#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ *stderr;
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  unsigned char inchar;
  unsigned int counter;
  struct stat file_info;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s infile outfile identifier\n", argv[0]);
    return 1;
  }
  stat(argv[1], &file_info);
  infile = fopen(argv[1], "r");
  if (!infile) {
    fprintf(stderr, "Input file doesn't exist.\n");
    return 2;
  }
  outfile = fopen(argv[2], "w+");
  fprintf(outfile, "int %s_size = %d;\n\n", argv[3], (int)file_info.st_size);
  fprintf(outfile, "unsigned char %s [] = \n{\n  ", argv[3]);
  counter = 0;
  while (fread(&inchar, 1, 1, infile)) {
    if (counter >= 32) {
      counter = 0;
      fprintf(outfile, "\n  ");
    }
    fprintf(outfile, "%d,", inchar);
    counter++;
  }
  fseek(outfile, -1, SEEK_CUR);
  fprintf(outfile, "\n};\n");
  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   $0x4,-0x8(%rbp)
je     119b <main+0x4b>
mov    0x2e61(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e1 <main+0x191>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f3 <main+0xa3>
mov    0x2e02(%rip),%rax
mov    (%rax),%rdi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12e1 <main+0x191>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe40(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
je     12b1 <main+0x161>
cmpl   $0x20,-0x28(%rbp)
jb     128d <main+0x13d>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
movzbl -0x21(%rbp),%edx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    124c <main+0xfc>
mov    -0x20(%rbp),%rdi
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
mov    -0x20(%rbp),%rdi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@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
sub    $0x18,%rsp
mov    %rsi,%r15
cmp    $0x4,%edi
jne    126d <main+0x10d>
mov    0x8(%r15),%rdi
lea    0x10(%rsp),%rsi
call   1050 <stat@plt>
mov    0x8(%r15),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12c2 <main+0x162>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x18(%r15),%rdx
mov    0x10(%rsp),%ecx
lea    0xe7f(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x18(%r15),%rdx
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     128f <main+0x12f>
lea    0xe65(%rip),%r15
lea    0xe62(%rip),%r12
lea    0xf(%rsp),%r13
xor    %ebp,%ebp
jmp    124f <main+0xef>
nopl   0x0(%rax)
movzbl 0xf(%rsp),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebp
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     128f <main+0x12f>
cmp    $0x20,%ebp
jb     1220 <main+0xc0>
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   1080 <fwrite@plt>
xor    %ebp,%ebp
jmp    1220 <main+0xc0>
mov    0x2d64(%rip),%rax
mov    (%rax),%rdi
mov    (%r15),%rdx
lea    0xd7f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    12e7 <main+0x187>
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
lea    0xdcd(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
xor    %eax,%eax
jmp    12e7 <main+0x187>
mov    0x2d0f(%rip),%rax
mov    (%rax),%rcx
lea    0xd54(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0x2,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@stderr = global i32* null
@.str = [37 x i8] c"Usage: %s infile outfile identifier\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Input file doesn't exist.\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [20 x i8] c"int %s_size = %d;\0A\0A\00"
@.str.5 = [28 x i8] c"unsigned char %s [] = \0A{\0A \00"
@.str.6 = [4 x i8] c"\0A \00"
@.str.7 = [4 x i8] c"%d,\00"
@SEEK_CUR = global i32 0
@.str.8 = [5 x i8] c"\0A};\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 %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32*, i32** @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %74
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @stat(i8* %22, %struct.stat* %10)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %33, label %30
30: ; preds = %19
%31 = load i32*, i32** @stderr
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %74
33: ; preds = %19
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %37, i32** %7
%38 = load i32*, i32** %7
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
%42 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%43 = load i64, i64* %42
%44 = trunc i64 %43 to i32
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %41, i32 %44)
%46 = load i32*, i32** %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %49)
store i32 0, i32* %9
br label %51
51: ; preds = %61, %33
%52 = load i32*, i32** %6
%53 = call i64 @fread(i8* %8, i32 1, i32 1, i32* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %68
55: ; preds = %51
%56 = load i32, i32* %9
%57 = icmp uge i32 %56, 32
br i1 %57, label %58, label %61
58: ; preds = %55
store i32 0, i32* %9
%59 = load i32*, i32** %7
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %58, %55
%62 = load i32*, i32** %7
%63 = load i8, i8* %8
%64 = zext i8 %63 to i32
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %9
%67 = add i32 %66, 1
store i32 %67, i32* %9
br label %51
68: ; preds = %51
%69 = load i32*, i32** %7
%70 = load i32, i32* @SEEK_CUR
%71 = call i32 @fseek(i32* %69, i32 -1, i32 %70)
%72 = load i32*, i32** %7
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %74
74: ; preds = %68, %30, %13
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32* null
@.str = [37 x i8] c"Usage: %s infile outfile identifier\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Input file doesn't exist.\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [20 x i8] c"int %s_size = %d;\0A\0A\00"
@.str.5 = [28 x i8] c"unsigned char %s [] = \0A{\0A \00"
@.str.6 = [4 x i8] c"\0A \00"
@.str.7 = [4 x i8] c"%d,\00"
@SEEK_CUR = global i32 0
@.str.8 = [5 x i8] c"\0A};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = icmp eq i32 %0, 4
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32*, i32** @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %52
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @stat(i8* %13, %struct.stat* %4)
%15 = load i8*, i8** %12
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32*, i32** @stderr
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 26, i64 1, i32* %19)
br label %52
21: ; preds = %11
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %26, i32 %29)
%31 = load i8*, i8** %25
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %31)
%33 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %16)
%34 = icmp eq i64 %33, 0
br i1 %34, label %48, label %35
35: ; preds = %21, %40
%36 = phi i32 [ %45, %40 ], [ 0, %21 ]
%37 = icmp ugt i32 %36, 31
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64 3, i64 1, i32* %24)
br label %40
40: ; preds = %38, %35
%41 = phi i32 [ 0, %38 ], [ %36, %35 ]
%42 = load i8, i8* %3
%43 = zext i8 %42 to i32
%44 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %43)
%45 = add nuw nsw i32 %41, 1
%46 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %16)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %35
48: ; preds = %40, %21
%49 = load i32, i32* @SEEK_CUR
%50 = tail call i32 @fseek(i32* %24, i32 -1, i32 %49)
%51 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64 4, i64 1, i32* %24)
br label %52
52: ; preds = %48, %18, %7
%53 = phi i32 [ 1, %7 ], [ 0, %48 ], [ 2, %18 ]
ret i32 %53
}