#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 EOF;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fputs(char *, int /*<<< orphan*/ *);
int main() {
  FILE *fp1;
  int ret;
  fp1 = fopen("foo.txt", "w+");
  ret = fputs("hello world 1", fp1);
  assert(ret == EOF);
  ret = fputs("hello world 2", fp1);
  assert(ret == EOF);
  fclose(fp1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe9a(%rip),%rdi
call   1040 <fputs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1040 <fputs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xeaa(%rip),%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    0x2e78(%rip),%r14
xor    %edi,%edi
cmp    (%r14),%eax
sete   %dil
call   1050 <assert@plt>
lea    0xe94(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
xor    %edi,%edi
cmp    (%r14),%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"foo.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [14 x i8] c"hello world 1\00"
@EOF = global i32 0
@.str.3 = [14 x i8] c"hello world 2\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32*, i32** %2
%13 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foo.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [14 x i8] c"hello world 1\00"
@EOF = global i32 0
@.str.3 = [14 x i8] c"hello world 2\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @fclose(i32* %1)
ret i32 0
}