#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 uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  uint32_t column_width = 20;
  if (argc != 4) {
    printf("Must supply three args.\n");
    return -1;
  }
  FILE *ifp = fopen(argv[1], "rb");
  FILE *ofp = fopen(argv[2], "w");
  if (!ifp) {
    fprintf(stderr, "Could not open file %s for reading\n", argv[1]);
    exit(-1);
  }
  if (!ofp) {
    fprintf(stderr, "Could not open file %s for writing\n", argv[2]);
    exit(-1);
  }
  uint8_t data;
  fprintf(ofp, "/*\n\tAutogenerated do not edit:\n\t%s\n*/\n", argv[1]);
  fprintf(ofp, "#include <stdint.h>\n");
  fprintf(ofp, "uint8_t %s_array[] = {\n", argv[3]);
  int count = 0;
  while (fread(&data, 1, 1, ifp)) {
    fprintf(ofp, "0x%02X,", data);
    if ((++count) % column_width == 0)
      fprintf(ofp, "\n");
  }
  fprintf(ofp, "};\n");
  fprintf(ofp, "uint32_t %s_size = 0x%x;\n", argv[3], count);
}


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)
movl   $0x14,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     118f <main+0x3f>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <main+0x1b5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f4 <main+0xa4>
mov    0x2e0f(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1229 <main+0xd9>
mov    0x2dda(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
je     12d6 <main+0x186>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    12d1 <main+0x181>
mov    -0x28(%rbp),%rdi
lea    0xd4d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1276 <main+0x126>
mov    -0x28(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x30(%rbp),%ecx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
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
cmp    $0x4,%edi
jne    12a5 <main+0x135>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <fopen@plt>
test   %r12,%r12
je     12fe <main+0x18e>
mov    %rax,%rbx
test   %rax,%rax
je     1315 <main+0x1a5>
mov    0x8(%rbp),%rdx
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe96(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbp,0x10(%rsp)
mov    0x18(%rbp),%rdx
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     12b8 <main+0x148>
lea    0xc(%rsp),%r15
xor    %ebp,%ebp
jmp    1261 <main+0xf1>
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
add    $0x1,%r14d
add    $0x1,%ebp
test   %rax,%rax
je     12b8 <main+0x148>
mov    %r14d,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x24,%rax
lea    (%rax,%rax,4),%eax
lea    -0x1(,%rax,4),%r13d
ff
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    %ebp,%r13d
jne    1240 <main+0xd0>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
jmp    1240 <main+0xd0>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    12ef <main+0x17f>
lea    0xdea(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    0x10(%rsp),%rax
mov    0x18(%rax),%rdx
lea    0xdcc(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cdb(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%rbp),%rdx
lea    0xcf2(%rip),%rsi
jmp    132a <main+0x1ba>
mov    0x2cc4(%rip),%rax
movslq (%rax),%rdi
mov    0x10(%rbp),%rdx
lea    0xcff(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Must supply three args.\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [36 x i8] c"Could not open file %s for reading\0A\00"
@.str.4 = [36 x i8] c"Could not open file %s for writing\0A\00"
@.str.5 = [39 x i8] c"/*\0A\09Autogenerated do not edit:\0A\09%s\0A*/\0A\00"
@.str.6 = [21 x i8] c"#include <stdint.h>\0A\00"
@.str.7 = [24 x i8] c"uint8_t %s_array[] = {\0A\00"
@.str.8 = [8 x i8] c"0x%02X,\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [4 x i8] c"};\0A\00"
@.str.11 = [26 x i8] c"uint32_t %s_size = 0x%x;\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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 20, i32* %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %86
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %8
%24 = load i32*, i32** %7
%25 = icmp ne i32* %24, null
br i1 %25, label %35, label %26
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %15
%36 = load i32*, i32** %8
%37 = icmp ne i32* %36, null
br i1 %37, label %47, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = sext i32 %39 to i64
%41 = inttoptr i64 %40 to i32*
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %35
%48 = load i32*, i32** %8
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %8
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%55 = load i32*, i32** %8
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %58)
store i32 0, i32* %10
br label %60
60: ; preds = %76, %47
%61 = load i32*, i32** %7
%62 = call i64 @fread(i32* %9, i32 1, i32 1, i32* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %77
64: ; preds = %60
%65 = load i32*, i32** %8
%66 = load i32, i32* %9
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
%70 = load i32, i32* %6
%71 = srem i32 %69, %70
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %64
%74 = load i32*, i32** %8
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %76
76: ; preds = %73, %64
br label %60
77: ; preds = %60
%78 = load i32*, i32** %8
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%80 = load i32*, i32** %8
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 3
%83 = load i8*, i8** %82
%84 = load i32, i32* %10
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %80, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %83, i32 %84)
br label %86
86: ; preds = %77, %13
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [36 x i8] c"Could not open file %s for reading\0A\00"
@.str.4 = [36 x i8] c"Could not open file %s for writing\0A\00"
@.str.5 = [39 x i8] c"/*\0A\09Autogenerated do not edit:\0A\09%s\0A*/\0A\00"
@.str.6 = [21 x i8] c"#include <stdint.h>\0A\00"
@.str.7 = [24 x i8] c"uint8_t %s_array[] = {\0A\00"
@.str.8 = [8 x i8] c"0x%02X,\00"
@.str.10 = [4 x i8] c"};\0A\00"
@.str.11 = [26 x i8] c"uint32_t %s_size = 0x%x;\0A\00"
@str = [24 x i8] c"Must supply three args.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 4
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %58
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 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %10, null
br i1 %14, label %15, label %22
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
%19 = load i8*, i8** %8
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %7
%23 = icmp eq i32* %13, null
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = load i32, i32* @stderr
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
%28 = load i8*, i8** %11
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %22
%32 = bitcast i32* %3 to i8*
%33 = load i8*, i8** %8
%34 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i64 20, i64 1, i32* %13)
%36 = getelementptr inbounds i8*, i8** %1, i64 3
%37 = load i8*, i8** %36
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %37)
%39 = call i64 @fread(i32* %3, i32 1, i32 1, i32* %10)
%40 = icmp eq i64 %39, 0
br i1 %40, label %53, label %41
41: ; preds = %31, %50
%42 = phi i32 [ %45, %50 ], [ 0, %31 ]
%43 = load i32, i32* %3
%44 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %43)
%45 = add nuw nsw i32 %42, 1
%46 = urem i32 %45, 20
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = tail call i32 @fputc(i32 10, i32* %13)
br label %50
50: ; preds = %48, %41
%51 = call i64 @fread(i32* %3, i32 1, i32 1, i32* %10)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %41
53: ; preds = %50, %31
%54 = phi i32 [ 0, %31 ], [ %45, %50 ]
%55 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i64 3, i64 1, i32* %13)
%56 = load i8*, i8** %36
%57 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %56, i32 %54)
br label %58
58: ; preds = %53, %5
%59 = phi i32 [ -1, %5 ], [ 0, %53 ]
ret i32 %59
}