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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  uint32_t val;
  int counter = 0;
  if (argc <= 1) {
    printf("\nShould pass a filename as input via command line\n");
    return 0;
  }
  FILE *fp = fopen(argv[1], "rb");
  if (!fp) {
    printf("\nFailed to open file named \"%s\" for reading\n", argv[1]);
    return 0;
  }
  while (!feof(fp)) {
    if (!fread(&val, sizeof(val), 1, fp)) {
      break;
    }
    printf(" 0x%08x,", val);
    if (++counter == 4) {
      counter = 0;
      printf("\n");
    }
  }
  fclose(fp);
  printf("\n");
  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)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1191 <main+0x41>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1279 <main+0x129>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1279 <main+0x129>
jmp    11db <main+0x8b>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f9 <main+0xa9>
jmp    125b <main+0x10b>
mov    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    121e <main+0xce>
jmp    125b <main+0x10b>
mov    -0x14(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x4,%eax
jne    1256 <main+0x106>
movl   $0x0,-0x18(%rbp)
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11db <main+0x8b>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     118a <main+0x1a>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
jmp    11d7 <main+0x67>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe68(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11c5 <main+0x55>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11e4 <main+0x74>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d7 <main+0x67>
mov    0x8(%r14),%rsi
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x4(%rsp),%r14
lea    0xe40(%rip),%r15
xor    %ebp,%ebp
jmp    120c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    11b1 <main+0x41>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     11b1 <main+0x41>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebp
cmp    $0x4,%ebp
jne    1200 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    1200 <main+0x90>

LLVM IR (-O0):
@.str = [51 x i8] c"\0AShould pass a filename as input via command line\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [45 x i8] c"\0AFailed to open file named \22%s\22 for reading\0A\00"
@.str.3 = [9 x i8] c" 0x%08x,\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %49
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %8
%18 = load i32*, i32** %8
%19 = icmp ne i32* %18, null
br i1 %19, label %25, label %20
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %23)
store i32 0, i32* %3
br label %49
25: ; preds = %13
br label %26
26: ; preds = %44, %25
%27 = load i32*, i32** %8
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %45
31: ; preds = %26
%32 = load i32*, i32** %8
%33 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %31
br label %45
36: ; preds = %31
%37 = load i32, i32* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
%41 = icmp eq i32 %40, 4
br i1 %41, label %42, label %44
42: ; preds = %36
store i32 0, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
br label %26
45: ; preds = %35, %26
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %49
49: ; preds = %45, %20, %11
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [45 x i8] c"\0AFailed to open file named \22%s\22 for reading\0A\00"
@.str.3 = [9 x i8] c" 0x%08x,\00"
@str = [50 x i8] c"\0AShould pass a filename as input via command line\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 %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %37
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 @feof(i32* %11)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %34
16: ; preds = %8
%17 = load i8*, i8** %9
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %37
19: ; preds = %13, %30
%20 = phi i32 [ %31, %30 ], [ 0, %13 ]
%21 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %11)
%22 = icmp eq i32 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %19
%24 = load i32, i32* %3
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = add nsw i32 %20, 1
%27 = icmp eq i32 %26, 4
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = tail call i32 @putchar(i32 10)
br label %30
30: ; preds = %28, %23
%31 = phi i32 [ 0, %28 ], [ %26, %23 ]
%32 = tail call i32 @feof(i32* %11)
%33 = icmp eq i32 %32, 0
br i1 %33, label %19, label %34
34: ; preds = %30, %19, %13
%35 = tail call i32 @fclose(i32* %11)
%36 = tail call i32 @putchar(i32 10)
br label %37
37: ; preds = %16, %34, %6
ret i32 0
}