#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  FILE *f_ip, *f_op;
  unsigned char byte;
  int ret, i = 1, count = 0;
  char op_filename[50];
  if (argc < 2)
    usage();
  f_ip = fopen(argv[1], "r");
  if (!f_ip) {
    printf("failed to open %s\n", argv[1]);
    exit(0);
  };
  sprintf(op_filename, "%s.i", argv[1]);
  printf("%s\n", op_filename);
  f_op = fopen(op_filename, "w");
  if (!f_op) {
    printf("failed to open output file\n");
    exit(0);
  };
  do {
    ret = fread(&byte, 1, 1, f_ip);
    if (ret < 0)
      exit(0);
    fprintf(f_op, "0x%02x,", byte);
    i++;
    if (i % 10 == 0) {
      i = 1;
      fprintf(f_op, "\n");
    }
    count++;
  } while (ret == 1);
  fclose(f_ip);
  fclose(f_op);
  printf("count = %d\n", count);
  printf("file created at %s\n", op_filename);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b5 <main+0x35>
mov    $0x0,%al
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <main+0x75>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe0d(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x70(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1253 <main+0xd3>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    1258 <main+0xd8>
mov    -0x18(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1280 <main+0x100>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
movzbl -0x21(%rbp),%edx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12cc <main+0x14c>
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x28(%rbp)
je     1258 <main+0xd8>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%esi
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11bd <main+0x1d>
xor    %eax,%eax
call   1090 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xe38(%rip),%rsi
call   10a0 <fopen@plt>
mov    0x8(%rbx),%rdx
test   %rax,%rax
je     12dd <main+0x13d>
mov    %rax,%r14
lea    0xe31(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe1a(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x155>
mov    %rax,%r13
mov    $0x1,%r15d
lea    0xdfb(%rip),%r12
xor    %ebp,%ebp
jmp    1238 <main+0x98>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    $0x1,%ebx
jne    1299 <main+0xf9>
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
js     1301 <main+0x161>
mov    %eax,%ebx
movzbl 0xf(%rsp),%edx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r15d
imul   $0xcccccccd,%r15d,%eax
add    $0x19999998,%eax
ror    %eax
cmp    $0x19999998,%eax
ja     1230 <main+0x90>
mov    $0xa,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    $0x1,%r15d
jmp    1230 <main+0x90>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
lea    0xd74(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd70(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1e(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xd48(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [19 x i8] c"failed to open %s\0A\00"
@.str.2 = [5 x i8] c"%s.i\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [28 x i8] c"failed to open output file\0A\00"
@.str.6 = [8 x i8] c"0x%02x,\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [12 x i8] c"count = %d\0A\00"
@.str.9 = [20 x i8] c"file created at %s\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 i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %10
store i32 0, i32* %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @usage()
br label %17
17: ; preds = %15, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %30, label %24
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %17
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %39, i32** %7
%40 = load i32*, i32** %7
%41 = icmp ne i32* %40, null
br i1 %41, label %45, label %42
42: ; preds = %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %30
br label %46
46: ; preds = %69, %45
%47 = load i32*, i32** %6
%48 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %47)
store i32 %48, i32* %9
%49 = load i32, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %46
%54 = load i32*, i32** %7
%55 = load i8, i8* %8
%56 = zext i8 %55 to i32
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
%60 = load i32, i32* %10
%61 = srem i32 %60, 10
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %53
store i32 1, i32* %10
%64 = load i32*, i32** %7
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %66
66: ; preds = %63, %53
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %69
69: ; preds = %66
%70 = load i32, i32* %9
%71 = icmp eq i32 %70, 1
br i1 %71, label %46, label %72
72: ; preds = %69
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
%77 = load i32, i32* %11
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %77)
%79 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %79)
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [19 x i8] c"failed to open %s\0A\00"
@.str.2 = [5 x i8] c"%s.i\00"
@.str.4 = [2 x i8] c"w\00"
@.str.6 = [8 x i8] c"0x%02x,\00"
@.str.8 = [12 x i8] c"count = %d\0A\00"
@.str.9 = [20 x i8] c"file created at %s\0A\00"
@str = [27 x i8] c"failed to open output file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (...) @usage()
br label %9
9: ; preds = %7, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
%14 = load i8*, i8** %10
br i1 %13, label %15, label %18
15: ; preds = %9
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %9
%19 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%20 = call i32 @puts(i8* %5)
%21 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 0)
unreachable
26: ; preds = %18, %42
%27 = phi i32 [ %43, %42 ], [ 1, %18 ]
%28 = phi i32 [ %44, %42 ], [ 0, %18 ]
%29 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %12)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = tail call i32 @exit(i32 0)
unreachable
33: ; preds = %26
%34 = load i8, i8* %3
%35 = zext i8 %34 to i32
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = add nsw i32 %27, 1
%38 = srem i32 %37, 10
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = tail call i32 @fputc(i32 10, i32* %21)
br label %42
42: ; preds = %40, %33
%43 = phi i32 [ 1, %40 ], [ %37, %33 ]
%44 = add nuw nsw i32 %28, 1
%45 = icmp eq i32 %29, 1
br i1 %45, label %26, label %46
46: ; preds = %42
%47 = tail call i32 @fclose(i32* %12)
%48 = tail call i32 @fclose(i32* %21)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %44)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %5)
ret i32 0
}