#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 */

/* Variables and functions */
int /*<<< orphan*/ _dumpHexCBytes(int /*<<< orphan*/, unsigned char *, long);
long _getFileLength(char *);
int /*<<< orphan*/ _readEntireFile(char *, unsigned char *, long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
unsigned char *malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  long iLen;
  unsigned char *pBytes;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s datafile arrayname\n", argv[0]);
    return -1;
  }
  iLen = _getFileLength(argv[1]);
  pBytes = malloc(iLen);
  _readEntireFile(argv[1], pBytes, iLen);
  printf("unsigned char %s[] = {\n", argv[2]);
  _dumpHexCBytes(stdout, pBytes, iLen);
  printf("};\n");
  printf("unsigned long %s_sizeof = sizeof(%s);\n", argv[2], argv[2]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <_getFileLength@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <_readEntireFile@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <_dumpHexCBytes@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11f1 <main+0x81>
mov    0x8(%rbx),%rdi
call   1090 <_getFileLength@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
mov    %rax,%rsi
mov    %rbp,%rdx
call   1070 <_readEntireFile@plt>
mov    0x10(%rbx),%rsi
lea    0xe6e(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1080 <_dumpHexCBytes@plt>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbx),%rdx
lea    0xe51(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    120f <main+0x9f>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdfc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s datafile arrayname\0A\00"
@.str.1 = [24 x i8] c"unsigned char %s[] = {\0A\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"};\0A\00"
@.str.3 = [39 x i8] c"unsigned long %s_sizeof = sizeof(%s);\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %45
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @_getFileLength(i8* %19)
store i64 %20, i64* %6
%21 = load i64, i64* %6
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8*, i8** %7
%27 = load i64, i64* %6
%28 = call i32 @_readEntireFile(i8* %25, i8* %26, i64 %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @stdout
%34 = load i8*, i8** %7
%35 = load i64, i64* %6
%36 = call i32 @_dumpHexCBytes(i32 %33, i8* %34, i64 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %16, %10
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s datafile arrayname\0A\00"
@.str.1 = [24 x i8] c"unsigned char %s[] = {\0A\00"
@stdout = global i32 0
@.str.3 = [39 x i8] c"unsigned long %s_sizeof = sizeof(%s);\0A\00"
@str = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %23
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @_getFileLength(i8* %10)
%12 = tail call i8* @malloc(i64 %11)
%13 = load i8*, i8** %9
%14 = tail call i32 @_readEntireFile(i8* %13, i8* %12, i64 %11)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @stdout
%19 = tail call i32 @_dumpHexCBytes(i32 %18, i8* %12, i64 %11)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%21 = load i8*, i8** %15
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %21)
br label %23
23: ; preds = %8, %4
%24 = phi i32 [ -1, %4 ], [ 0, %8 ]
ret i32 %24
}