#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc == 3) {
    FILE *in = fopen(argv[1], "rb");
    unsigned long maxSize = strtoul(argv[2], NULL, 0);
    if (in) {
      int x, y;
      int count = 0;
      while (1) {
        if ((x = fgetc(in)) == EOF)
          break;
        if ((y = fgetc(in)) == EOF)
          y = 0;
        if (count % 8 == 0)
          printf("@%08x ", count * 2);
        printf(" %02x %02x", y, x);
        if (++count % 8 == 0)
          printf("\n");
      }
      if (count % 8 != 0)
        printf("\n");
      if (count * 2 >= maxSize) {
        fprintf(stderr, "image is too big: %u vs. %lu\n", count * 2, maxSize);
        return 1;
      }
    } else {
      fprintf(stderr, "failed to open file: %s\n", argv[1]);
      return 1;
    }
  } else {
    fprintf(stderr, "usage: %s input_file max_size_in_bytes\n", argv[0]);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    12f2 <main+0x1a2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12c2 <main+0x172>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11d1 <main+0x81>
jmp    125c <main+0x10c>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%eax
jne    11f3 <main+0xa3>
movl   $0x0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    121b <main+0xcb>
mov    -0x2c(%rbp),%esi
shl    $0x1,%esi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1257 <main+0x107>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <main+0x61>
mov    -0x2c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     127e <main+0x12e>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
cltq
cmp    -0x20(%rbp),%rax
jb     12bd <main+0x16d>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
shl    $0x1,%edx
mov    -0x20(%rbp),%rcx
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1323 <main+0x1d3>
jmp    12ed <main+0x19d>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1323 <main+0x1d3>
jmp    131c <main+0x1cc>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1323 <main+0x1d3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    123c <main+0xdc>
mov    0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
test   %r15,%r15
je     1252 <main+0xf2>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    0x2e34(%rip),%r13
cmp    0x0(%r13),%eax
je     1294 <main+0x134>
mov    %eax,%r14d
mov    %r12,(%rsp)
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    11e8 <main+0x88>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
add    $0x2,%ebp
cmp    0x0(%r13),%eax
je     1281 <main+0x121>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    $0x0,%r12d
cmp    0x0(%r13),%eax
je     11ff <main+0x9f>
mov    %eax,%r12d
test   $0x7,%bl
jne    1214 <main+0xb4>
lea    0xdf8(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdef(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
test   $0x7,%bl
jne    11d0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x70>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdfc(%rip),%rsi
jmp    1266 <main+0x106>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   $0x7,%bl
je     1290 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rsp),%r12
add    %ebx,%ebx
xor    %eax,%eax
cmp    %rbx,%r12
ja     1272 <main+0x112>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
mov    %ebx,%edx
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    126d <main+0x10d>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [7 x i8] c"@%08x \00"
@.str.2 = [11 x i8] c" %02x %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"image is too big: %u vs. %lu\0A\00"
@.str.5 = [25 x i8] c"failed to open file: %s\0A\00"
@.str.6 = [40 x i8] c"usage: %s input_file max_size_in_bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 3
br i1 %12, label %13, label %82
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, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i64 @strtoul(i8* %20, i32* null, i32 0)
store i64 %21, i64* %7
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %75
24: ; preds = %13
store i32 0, i32* %10
br label %25
25: ; preds = %24, %55
%26 = load i32*, i32** %6
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %8
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %25
br label %56
31: ; preds = %25
%32 = load i32*, i32** %6
%33 = call i32 @fgetc(i32* %32)
store i32 %33, i32* %9
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 0, i32* %9
br label %37
37: ; preds = %36, %31
%38 = load i32, i32* %10
%39 = srem i32 %38, 8
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %10
%43 = mul nsw i32 %42, 2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %37
%46 = load i32, i32* %9
%47 = load i32, i32* %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %46, i32 %47)
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
%51 = srem i32 %50, 8
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %45
br label %25
56: ; preds = %30
%57 = load i32, i32* %10
%58 = srem i32 %57, 8
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60, %56
%63 = load i32, i32* %10
%64 = mul nsw i32 %63, 2
%65 = sext i32 %64 to i64
%66 = load i64, i64* %7
%67 = icmp uge i64 %65, %66
br i1 %67, label %68, label %74
68: ; preds = %62
%69 = load i32, i32* @stderr
%70 = load i32, i32* %10
%71 = mul nsw i32 %70, 2
%72 = load i64, i64* %7
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %71, i64 %72)
store i32 1, i32* %3
br label %89
74: ; preds = %62
br label %81
75: ; preds = %13
%76 = load i32, i32* @stderr
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %79)
store i32 1, i32* %3
br label %89
81: ; preds = %74
br label %88
82: ; preds = %2
%83 = load i32, i32* @stderr
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 0
%86 = load i8*, i8** %85
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %86)
store i32 1, i32* %3
br label %89
88: ; preds = %81
store i32 0, i32* %3
br label %89
89: ; preds = %88, %82, %75, %68
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [7 x i8] c"@%08x \00"
@.str.2 = [11 x i8] c" %02x %02x\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"image is too big: %u vs. %lu\0A\00"
@.str.5 = [25 x i8] c"failed to open file: %s\0A\00"
@.str.6 = [40 x i8] c"usage: %s input_file max_size_in_bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %56
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i64 @strtoul(i8* nocapture %9, i32* null, i32 0)
%11 = icmp eq i32* %7, null
br i1 %11, label %52, label %12
12: ; preds = %4
%13 = tail call i32 @fgetc(i32* %7)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %44, label %16
16: ; preds = %12, %35
%17 = phi i32 [ %36, %35 ], [ %13, %12 ]
%18 = phi i32 [ %30, %35 ], [ 0, %12 ]
%19 = tail call i32 @fgetc(i32* %7)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
%22 = select i1 %21, i32 0, i32 %19
%23 = and i32 %18, 7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = shl nuw nsw i32 %18, 1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %16
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %17)
%30 = add nuw nsw i32 %18, 1
%31 = and i32 %30, 7
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = tail call i32 @putchar(i32 10)
br label %35
35: ; preds = %33, %28
%36 = tail call i32 @fgetc(i32* %7)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %16
39: ; preds = %35
%40 = and i32 %30, 7
%41 = icmp eq i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = tail call i32 @putchar(i32 10)
br label %44
44: ; preds = %12, %42, %39
%45 = phi i32 [ %30, %42 ], [ %30, %39 ], [ 0, %12 ]
%46 = shl nuw nsw i32 %45, 1
%47 = zext i32 %46 to i64
%48 = icmp ugt i64 %10, %47
br i1 %48, label %60, label %49
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %46, i64 %10)
br label %60
52: ; preds = %4
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %5
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %54)
br label %60
56: ; preds = %2
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %1
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %49, %52, %44, %56
%61 = phi i32 [ 1, %56 ], [ 0, %44 ], [ 1, %52 ], [ 1, %49 ]
ret i32 %61
}