Three Before One

This program is run from an interactive terminal with no shell redirection. out.txt does not exist beforehand.

int fd = open("out.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
dup2(fd, STDOUT_FILENO);
close(fd);

printf("one\n");
fprintf(stderr, "two\n");

dup2(STDOUT_FILENO, STDERR_FILENO);
fprintf(stderr, "three\n");
return 0;

What are the exact contents of out.txt when the program exits?

A
three
B
three
one
C
one
three
D
one
two
three