#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int putc(int, int /*<<< orphan*/ *);
int main() {
  FILE *fp;
  int err;
  fp = fopen("file1.txt", "w+");
  err = putc(65, fp);
  assert(err == EOF);
  err = putc(66, fp);
  assert(err == EOF);
  fclose(fp);
  return errno;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x41,%edi
call   1040 <putc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rsi
mov    $0x42,%edi
call   1040 <putc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e3d(%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>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [10 x i8] c"file1.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@EOF = global i32 0
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 @putc(i32 65, 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 @putc(i32 66, 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)
%21 = load i32, i32* @errno
ret i32 %21
}

LLVM IR (-O2):
@.str = [10 x i8] c"file1.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@EOF = global i32 0
@errno = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 @putc(i32 65, 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 @putc(i32 66, 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)
%13 = load i32, i32* @errno
ret i32 %13
}