#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *stdout;
int main() {
  fprintf(stdout, "Hello World, from C!\n");
  fflush(stdout);
  FILE *fd = fopen("/tmp/dpriv-c-test", "w+");
  if (fd == NULL)
    return 0;
  fprintf(fd, "Hello World, from C!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%rdi
call   1040 <fflush@plt>
lea    0xeab(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <main+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <main+0x79>
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea8(%rip),%rbx
mov    (%rbx),%rcx
lea    0xebe(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    (%rbx),%rdi
call   1030 <fflush@plt>
lea    0xeb6(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     118a <main+0x5a>
lea    0xe88(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32* null
@.str = [22 x i8] c"Hello World, from C!\0A\00"
@.str.1 = [18 x i8] c"/tmp/dpriv-c-test\00"
@.str.2 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = load i32*, i32** @stdout
%4 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = load i32*, i32** @stdout
%6 = call i32 @fflush(i32* %5)
%7 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 0, i32* %1
br label %14
11: ; preds = %0
%12 = load i32*, i32** %2
%13 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %14
14: ; preds = %11, %10
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [22 x i8] c"Hello World, from C!\0A\00"
@.str.1 = [18 x i8] c"/tmp/dpriv-c-test\00"
@.str.2 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = load i32*, i32** @stdout
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 21, i64 1, i32* %1)
%3 = load i32*, i32** @stdout
%4 = tail call i32 @fflush(i32* %3)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 21, i64 1, i32* %5)
br label %9
9: ; preds = %0, %7
ret i32 0
}