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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  char *filename = "num.bin";
  FILE *fp = fopen(filename, "rb");
  char c[4];
  memset(c, 0, sizeof(c));
  if (fp) {
    while (fread(c, 1, 3, fp)) {
      printf("%x%x%x\n", c[0], c[1], c[2]);
      memset(c, 0, sizeof(c));
    }
    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    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     120c <main+0xac>
jmp    11ae <main+0x4e>
lea    -0x1c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
je     11fe <main+0x9e>
movsbl -0x1c(%rbp),%esi
movsbl -0x1b(%rbp),%edx
movsbl -0x1a(%rbp),%ecx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
jmp    11ae <main+0x4e>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    121e <main+0xbe>
mov    -0x10(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe00(%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    0xe90(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
test   %r15,%r15
je     120c <main+0xac>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     1202 <main+0xa2>
lea    0xe53(%rip),%r14
lea    0xc(%rsp),%rbx
nopl   (%rax)
movsbl 0xc(%rsp),%esi
movsbl 0xd(%rsp),%edx
movsbl 0xe(%rsp),%ecx
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    1221 <main+0xc1>
lea    0xe00(%rip),%rdi
lea    0xde6(%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 = [8 x i8] c"%x%x%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 [4 x i8]
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
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 4)
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %33
11: ; preds = %0
br label %12
12: ; preds = %17, %11
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i64 @fread(i8* %13, i32 1, i32 3, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %12
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %23, i32 %26)
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 4)
br label %12
30: ; preds = %12
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
br label %36
33: ; preds = %0
%34 = load i8*, i8** %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %33, %30
%37 = 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 = [8 x i8] c"%x%x%x\0A\00"
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%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 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 4)
%5 = icmp eq i32* %2, null
br i1 %5, label %25, label %6
6: ; preds = %0
%7 = call i64 @fread(i8* %3, i32 1, i32 3, i32* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 1
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 2
br label %12
12: ; preds = %9, %12
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = load i8, i8* %10
%16 = sext i8 %15 to i32
%17 = load i8, i8* %11
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %16, i32 %18)
%20 = call i32 @memset(i8* %3, i32 0, i32 4)
%21 = call i64 @fread(i8* %3, i32 1, i32 3, i32* %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %12
23: ; preds = %12, %6
%24 = call i32 @fclose(i32* %2)
br label %27
25: ; preds = %0
%26 = 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 %27
27: ; preds = %25, %23
%28 = call i32 @putchar(i32 10)
ret i32 0
}