#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, unsigned char,
                          unsigned char, unsigned char, unsigned char);
int main(int argc, char *argv[]) {
  if (argc < 3)
    return -1;
  FILE *f = fopen(argv[1], "rb");
  if (!f)
    return -1;
  unsigned char x[4];
  int i = 0;
  int n = atoi(argv[2]);
  while (!feof(f)) {
    fread(x, 1, 4, f);
    printf("write %x %02X%02X%02X%02X\n", i++, x[0], x[1], x[2], x[3]);
  }
  for (; i < n;) {
    printf("write %x %02X%02X%02X%02X\n", i++, 0, 0, 0, 0);
  }
  fclose(f);
  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)
jge    118c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <main+0x124>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bb <main+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <main+0x124>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f0 <main+0x90>
jmp    123b <main+0xdb>
lea    -0x1c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%dl
mov    -0x1b(%rbp),%cl
mov    -0x1a(%rbp),%al
lea    0xde1(%rip),%rdi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %al,%r8d
movzbl -0x19(%rbp),%r9d
call   1050 <printf@plt>
jmp    11d2 <main+0x72>
jmp    1240 <main+0xe0>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1274 <main+0x114>
mov    -0x20(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
lea    0xda5(%rip),%rdi
xor    %r9d,%r9d
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1050 <printf@plt>
jmp    1240 <main+0xe0>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
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    $0xffffffff,%ebx
cmp    $0x3,%edi
jl     1248 <main+0xe8>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1248 <main+0xe8>
mov    %rax,%r13
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    1206 <main+0xa6>
xor    %ebx,%ebx
lea    0x4(%rsp),%r15
lea    0xe43(%rip),%r12
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
lea    0x1(%rbx),%ebp
movzbl 0x4(%rsp),%edx
movzbl 0x5(%rsp),%ecx
movzbl 0x6(%rsp),%r8d
movzbl 0x7(%rsp),%r9d
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %r13,%rdi
call   1060 <feof@plt>
mov    %ebp,%ebx
test   %eax,%eax
je     11c0 <main+0x60>
cmp    %r14d,%ebp
jge    123e <main+0xde>
lea    0xdf1(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbp),%ebx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <printf@plt>
mov    %ebx,%ebp
cmp    %ebx,%r14d
jne    1220 <main+0xc0>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [27 x i8] c"write %x %02X%02X%02X%02X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [4 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %58
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 i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %13
store i32 -1, i32* %3
br label %58
21: ; preds = %13
store i32 0, i32* %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %9
br label %26
26: ; preds = %31, %21
%27 = load i32*, i32** %6
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %46
31: ; preds = %26
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%33 = load i32*, i32** %6
%34 = call i32 @fread(i8* %32, i32 1, i32 4, i32* %33)
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%38 = load i8, i8* %37
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 1
%40 = load i8, i8* %39
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 2
%42 = load i8, i8* %41
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 3
%44 = load i8, i8* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %35, i8 zeroext %38, i8 zeroext %40, i8 zeroext %42, i8 zeroext %44)
br label %26
46: ; preds = %26
br label %47
47: ; preds = %51, %46
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
%54 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %52, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0)
br label %47
55: ; preds = %47
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %3
br label %58
58: ; preds = %55, %20, %12
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [27 x i8] c"write %x %02X%02X%02X%02X\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %42, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %42, label %10
10: ; preds = %5
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @feof(i32* %8)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
br label %24
21: ; preds = %24, %10
%22 = phi i32 [ 0, %10 ], [ %27, %24 ]
%23 = icmp slt i32 %22, %14
br i1 %23, label %35, label %40
24: ; preds = %17, %24
%25 = phi i32 [ 0, %17 ], [ %27, %24 ]
%26 = call i32 @fread(i8* %11, i32 1, i32 4, i32* %8)
%27 = add nuw nsw i32 %25, 1
%28 = load i8, i8* %11
%29 = load i8, i8* %18
%30 = load i8, i8* %19
%31 = load i8, i8* %20
%32 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8 zeroext %28, i8 zeroext %29, i8 zeroext %30, i8 zeroext %31)
%33 = tail call i32 @feof(i32* %8)
%34 = icmp eq i32 %33, 0
br i1 %34, label %24, label %21
35: ; preds = %21, %35
%36 = phi i32 [ %37, %35 ], [ %22, %21 ]
%37 = add i32 %36, 1
%38 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %36, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0)
%39 = icmp eq i32 %37, %14
br i1 %39, label %40, label %35
40: ; preds = %35, %21
%41 = tail call i32 @fclose(i32* %8)
br label %42
42: ; preds = %40, %5, %2
%43 = phi i32 [ -1, %2 ], [ 0, %40 ], [ -1, %5 ]
ret i32 %43
}