#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  int c, n;
  if (argc != 3) {
    printf("Usage: %s <infile> <outfile>\n", argv[0]);
    return 1;
  }
  infile = fopen(argv[1], "rb");
  if (infile == NULL) {
    printf("Error: cannot open file '%s' for input\n", argv[1]);
    return 1;
  }
  outfile = fopen(argv[2], "wt");
  if (outfile == NULL) {
    printf("Error: cannot open file '%s' for output\n", argv[2]);
    return 1;
  }
  n = 0;
  while (1) {
    c = getc(infile);
    if (c == EOF) {
      break;
    }
    fprintf(outfile, "0x%02X, ", c);
    n++;
    if (n == 8) {
      n = 0;
      fprintf(outfile, "\n");
    }
  }
  if (n != 0) {
    fprintf(outfile, "\n");
  }
  fclose(infile);
  fclose(outfile);
  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)
je     118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ba <main+0x16a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ba <main+0x16a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1215 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ba <main+0x16a>
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%eax
jne    123f <main+0xef>
jmp    1285 <main+0x135>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x8,-0x28(%rbp)
jne    1280 <main+0x130>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    121c <main+0xcc>
cmpl   $0x0,-0x28(%rbp)
je     12a1 <main+0x151>
mov    -0x20(%rbp),%rdi
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <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   %r12
push   %rbx
mov    %rsi,%r15
cmp    $0x3,%edi
jne    1206 <main+0xa6>
mov    0x8(%r15),%rdi
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1212 <main+0xb2>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xeae(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121f <main+0xbf>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <getc@plt>
mov    0x2e31(%rip),%r12
cmp    (%r12),%eax
je     124e <main+0xee>
lea    0xead(%rip),%r15
xor    %ebp,%ebp
jmp    11de <main+0x7e>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1080 <getc@plt>
cmp    (%r12),%eax
je     123d <main+0xdd>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x8,%ebp
jne    11d0 <main+0x70>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %ebp,%ebp
jmp    11d0 <main+0x70>
mov    (%r15),%rsi
lea    0xdf0(%rip),%rdi
jmp    122a <main+0xca>
mov    0x8(%r15),%rsi
lea    0xe04(%rip),%rdi
jmp    122a <main+0xca>
mov    0x10(%r15),%rsi
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
je     124e <main+0xee>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1234 <main+0xd4>

LLVM IR (-O0):
@.str = [30 x i8] c"Usage: %s <infile> <outfile>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [40 x i8] c"Error: cannot open file '%s' for input\0A\00"
@.str.3 = [3 x i8] c"wt\00"
@.str.4 = [41 x i8] c"Error: cannot open file '%s' for output\0A\00"
@EOF = global i32 0
@.str.5 = [9 x i8] c"0x%02X, \00"
@.str.6 = [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
%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 ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %72
17: ; preds = %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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %72
29: ; preds = %17
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %7
%34 = load i32*, i32** %7
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %39)
store i32 1, i32* %3
br label %72
41: ; preds = %29
store i32 0, i32* %9
br label %42
42: ; preds = %41, %60
%43 = load i32*, i32** %6
%44 = call i32 @getc(i32* %43)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = load i32, i32* @EOF
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %61
49: ; preds = %42
%50 = load i32*, i32** %7
%51 = load i32, i32* %8
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, 8
br i1 %56, label %57, label %60
57: ; preds = %49
store i32 0, i32* %9
%58 = load i32*, i32** %7
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %60
60: ; preds = %57, %49
br label %42
61: ; preds = %48
%62 = load i32, i32* %9
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32*, i32** %7
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %64, %61
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
store i32 0, i32* %3
br label %72
72: ; preds = %67, %36, %24, %12
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [30 x i8] c"Usage: %s <infile> <outfile>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [40 x i8] c"Error: cannot open file '%s' for input\0A\00"
@.str.3 = [3 x i8] c"wt\00"
@.str.4 = [41 x i8] c"Error: cannot open file '%s' for output\0A\00"
@EOF = global i32 0
@.str.5 = [9 x i8] c"0x%02X, \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %47
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %47
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = tail call i32 @getc(i32* %10)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %44, label %27
24: ; preds = %15
%25 = load i8*, i8** %16
%26 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %47
27: ; preds = %20, %35
%28 = phi i32 [ %37, %35 ], [ %21, %20 ]
%29 = phi i32 [ %36, %35 ], [ 0, %20 ]
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%31 = add nsw i32 %29, 1
%32 = icmp eq i32 %31, 8
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = tail call i32 @fputc(i32 10, i32* %18)
br label %35
35: ; preds = %33, %27
%36 = phi i32 [ 0, %33 ], [ %31, %27 ]
%37 = tail call i32 @getc(i32* %10)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %27
40: ; preds = %35
%41 = icmp eq i32 %36, 0
br i1 %41, label %44, label %42
42: ; preds = %40
%43 = tail call i32 @fputc(i32 10, i32* %18)
br label %44
44: ; preds = %20, %42, %40
%45 = tail call i32 @fclose(i32* %10)
%46 = tail call i32 @fclose(i32* %18)
br label %47
47: ; preds = %44, %24, %12, %4
%48 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %24 ], [ 0, %44 ]
ret i32 %48
}