#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *ptr_file = fopen("aoc1.txt", "r");
  char buf[1000];
  if (!ptr_file) {
    return 1;
  }
  while (fgets(buf, 1000, ptr_file) != NULL) {
    printf("%s", buf);
  }
  fclose(ptr_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <main+0x47>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <main+0x93>
jmp    118c <main+0x4c>
lea    -0x400(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11c3 <main+0x83>
lea    -0x400(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
jmp    118c <main+0x4c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
lea    0xead(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bc <main+0x7c>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b0 <main+0x70>
lea    0xe88(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <main+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11c1 <main+0x81>
mov    $0x1,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"aoc1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 1, i32* %3
br label %24
12: ; preds = %2
br label %13
13: ; preds = %18, %12
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%15 = load i32*, i32** %6
%16 = call i32* @fgets(i8* %14, i32 1000, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %13
21: ; preds = %13
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %3
br label %24
24: ; preds = %21, %11
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [9 x i8] c"aoc1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32* %4, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %5, i32 1000, i32* %4)
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %7, %10
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%12 = call i32* @fgets(i8* %5, i32 1000, i32* %4)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %10
14: ; preds = %10, %7
%15 = call i32 @fclose(i32* %4)
br label %16
16: ; preds = %2, %14
%17 = phi i32 [ 0, %14 ], [ 1, %2 ]
ret i32 %17
}