#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*/ a;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  char *filename = "num.bin";
  FILE *fp = fopen(filename, "rb");
  int a = 0;
  if (fp) {
    while (fread(&a, 1, sizeof(a), fp)) {
      printf("0x%x\n", a);
    }
    fclose(fp);
  } else {
    printf("Opening %s failed\n", filename);
  }
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11da <main+0x8a>
jmp    1195 <main+0x45>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
je     11cc <main+0x7c>
mov    -0x1c(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1195 <main+0x45>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    11ec <main+0x9c>
mov    -0x10(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea0(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1070 <fopen@plt>
movl   $0x0,0xc(%rsp)
test   %rax,%rax
je     11e2 <main+0x92>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11d8 <main+0x88>
lea    0xe6c(%rip),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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    11b0 <main+0x60>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11f7 <main+0xa7>
lea    0xe28(%rip),%rdi
lea    0xe10(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"num.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [6 x i8] c"0x%x\0A\00"
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = icmp eq i32* %2, null
br i1 %4, label %15, label %5
5: ; preds = %0
%6 = call i64 @fread(i32* %1, i32 1, i32 4, i32* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5, %8
%9 = load i32, i32* %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = call i64 @fread(i32* %1, i32 1, i32 4, i32* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %8
13: ; preds = %8, %5
%14 = tail call i32 @fclose(i32* %2)
br label %17
15: ; preds = %0
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
%18 = tail call i32 @putchar(i32 10)
ret i32 0
}