#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  FILE *fp;
  int value;
  if (argc < 2) {
    usage();
    exit(EXIT_SUCCESS);
  }
  if (!(fp = fopen(argv[1], "r"))) {
    printf("fopen problem\n");
    return -1;
  }
  while (fread(&value, 1, 4, fp)) {
    printf("%d\n", value);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1195 <main+0x35>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d1 <main+0x71>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <main+0xbd>
jmp    11d6 <main+0x76>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     120d <main+0xad>
mov    -0x1c(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d6 <main+0x76>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jle    121f <main+0xaf>
mov    0x8(%rsi),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1204 <main+0x94>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11f8 <main+0x88>
lea    0xe45(%rip),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0xc(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1215 <main+0xa5>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"fopen problem\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 (...) @usage()
%12 = load i32, i32* @EXIT_SUCCESS
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %33
22: ; preds = %14
br label %23
23: ; preds = %27, %22
%24 = load i32*, i32** %6
%25 = call i64 @fread(i32* %7, i32 1, i32 4, i32* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %23
30: ; preds = %23
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %20
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@str = [14 x i8] c"fopen problem\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 (...) @usage()
%8 = load i32, i32* @EXIT_SUCCESS
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = call i64 @fread(i32* %3, i32 1, i32 4, i32* %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %20
18: ; preds = %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %27
20: ; preds = %15, %20
%21 = load i32, i32* %3
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i64 @fread(i32* %3, i32 1, i32 4, i32* %13)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %20
25: ; preds = %20, %15
%26 = tail call i32 @fclose(i32* %13)
br label %27
27: ; preds = %25, %18
%28 = phi i32 [ 0, %25 ], [ -1, %18 ]
ret i32 %28
}