#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  printf("%d\n", errno);
  FILE *fp;
  int ch;
  fp = fopen("file1.txt", "w+");
  for (ch = 33; ch <= 100; ch++) {
    fputc(ch, fp);
  }
  fclose(fp);
  printf("%d\n", errno);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x21,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jg     11a6 <main+0x66>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <main+0x42>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e95(%rip),%r14
mov    (%r14),%esi
lea    0xeab(%rip),%rdi
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    $0x21,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%ebp
cmp    $0x65,%ebp
jne    1180 <main+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%r14),%esi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@errno = global i32 0
@.str.1 = [10 x i8] c"file1.txt\00"
@.str.2 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @errno
%5 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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* %6, i32** %2
store i32 33, i32* %3
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 100
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %3
%12 = load i32*, i32** %2
%13 = call i32 @fputc(i32 %11, i32* %12)
br label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %7
17: ; preds = %7
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* @errno
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@errno = global i32 0
@.str.1 = [10 x i8] c"file1.txt\00"
@.str.2 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = load i32, i32* @errno
%2 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 33, %0 ], [ %7, %4 ]
%6 = tail call i32 @fputc(i32 %5, i32* %3)
%7 = add nuw nsw i32 %5, 1
%8 = icmp eq i32 %7, 101
br i1 %8, label %9, label %4
9: ; preds = %4
%10 = tail call i32 @fclose(i32* %3)
%11 = load i32, i32* @errno
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}