#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int print_ints(const char *file_name) {
  int status = 0;
  FILE *fd;
  struct stat filestat;
  size_t len;
  int num;
  fd = fopen(file_name, "r");
  if (fd < 0) {
    char cwd[1000 + 1];
    if (getcwd(cwd, 1000) == NULL) {
      return -1;
    }
    fprintf(stderr, "Could not open file [%s] \n", file_name);
    fprintf(stderr, "Currently in dir    [%s] \n", cwd);
    return -1;
  }
  fseek(fd, 0L, SEEK_END);
  size_t pos = ftell(fd);
  fseek(fd, 0, SEEK_END);
  len = ftell(fd) / sizeof(int);
  rewind(fd);
  for (int iter = 0; iter < len; iter++) {
    int val = fread(&num, sizeof(int), 1, fd);
    if (val == 1)
      printf("%d\t%d\n", iter, num);
  }
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<print_ints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jae    122d <print_ints+0x9d>
lea    -0x420(%rbp),%rdi
mov    $0x3e8,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    11ec <print_ints+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    130a <print_ints+0x17a>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe02(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130a <print_ints+0x17a>
mov    -0x20(%rbp),%rdi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
cltq
mov    %rax,-0x428(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
cltq
shr    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x0,-0x42c(%rbp)
movslq -0x42c(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    12fa <print_ints+0x16a>
mov    -0x20(%rbp),%rcx
lea    -0x34(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x430(%rbp)
cmpl   $0x1,-0x430(%rbp)
jne    12e1 <print_ints+0x151>
mov    -0x42c(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xd5c(%rip),%rdi
call   1050 <printf@plt>
jmp    12e6 <print_ints+0x156>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1291 <print_ints+0x101>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ints>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    0x2e55(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1070 <ftell@plt>
mov    (%rbx),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <rewind@plt>
cmp    $0x4,%ebx
jae    11e2 <print_ints+0x72>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
movslq %ebx,%rax
shr    $0x2,%rax
cmp    $0x2,%rax
mov    $0x1,%r13d
cmovae %rax,%r13
xor    %ebx,%ebx
lea    0xc(%rsp),%r15
lea    0xdfd(%rip),%r12
jmp    1219 <print_ints+0xa9>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     11ca <print_ints+0x5a>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1210 <print_ints+0xa0>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
jmp    1210 <print_ints+0xa0>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not open file [%s] \0A\00"
@.str.2 = [27 x i8] c"Currently in dir [%s] \0A\00"
@SEEK_END = global i32 0
@.str.3 = [7 x i8] c"%d\09%d\0A\00"
define i32 @print_ints(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.stat
%7 = alloca i64
%8 = alloca i32
%9 = alloca [1001 x i8]
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ult i32* %15, null
br i1 %16, label %17, label %29
17: ; preds = %1
%18 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%19 = call i32* @getcwd(i8* %18, i32 1000)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %2
br label %66
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 -1, i32* %2
br label %66
29: ; preds = %1
%30 = load i32*, i32** %5
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i64 0, i32 %31)
%33 = load i32*, i32** %5
%34 = call i32 @ftell(i32* %33)
%35 = sext i32 %34 to i64
store i64 %35, i64* %10
%36 = load i32*, i32** %5
%37 = load i32, i32* @SEEK_END
%38 = call i32 @fseek(i32* %36, i64 0, i32 %37)
%39 = load i32*, i32** %5
%40 = call i32 @ftell(i32* %39)
%41 = sext i32 %40 to i64
%42 = udiv i64 %41, 4
store i64 %42, i64* %7
%43 = load i32*, i32** %5
%44 = call i32 @rewind(i32* %43)
store i32 0, i32* %11
br label %45
45: ; preds = %60, %29
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = load i64, i64* %7
%49 = icmp ult i64 %47, %48
br i1 %49, label %50, label %63
50: ; preds = %45
%51 = load i32*, i32** %5
%52 = call i32 @fread(i32* %8, i32 4, i32 1, i32* %51)
store i32 %52, i32* %12
%53 = load i32, i32* %12
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load i32, i32* %11
%57 = load i32, i32* %8
%58 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %56, i32 %57)
br label %59
59: ; preds = %55, %50
br label %60
60: ; preds = %59
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %45
63: ; preds = %45
%64 = load i32*, i32** %5
%65 = call i32 @fclose(i32* %64)
store i32 0, i32* %2
br label %66
66: ; preds = %63, %22, %21
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@SEEK_END = global i32 0
@.str.3 = [7 x i8] c"%d\09%d\0A\00"
define i32 @print_ints(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %4, i64 0, i32 %5)
%7 = tail call i32 @ftell(i32* %4)
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %4, i64 0, i32 %8)
%10 = tail call i32 @ftell(i32* %4)
%11 = tail call i32 @rewind(i32* %4)
%12 = icmp ult i32 %10, 4
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = sext i32 %10 to i64
%15 = lshr i64 %14, 2
%16 = call i64 @llvm.umax.i64(i64 %15, i64 1)
br label %19
17: ; preds = %27, %1
%18 = tail call i32 @fclose(i32* %4)
ret i32 0
19: ; preds = %13, %27
%20 = phi i64 [ 0, %13 ], [ %28, %27 ]
%21 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %4)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %2
%25 = trunc i64 %20 to i32
%26 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %24)
br label %27
27: ; preds = %23, %19
%28 = add nuw nsw i64 %20, 1
%29 = icmp eq i64 %28, %16
br i1 %29, label %17, label %19
}