#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(char *);
char *load_binfile_to_memory(char const *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void genembbin_fromfile(const char *table_name, const char *file_name) {
  int file_size;
  char *file_buff;
  int i;
  if ((file_buff = load_binfile_to_memory(file_name, &file_size)) != NULL) {
    printf("#define %s_size %d\n\n", table_name, file_size);
    printf("const char %s [%d] = {\n", table_name, file_size);
    printf("\t");
    for (i = 0; i < file_size; i++) {
      printf("%d", file_buff[i]);
      if (i < (file_size - 1))
        printf(", ");
    }
    printf("\n");
    printf("};\n\n");
    free(file_buff);
  } else {
    fprintf(stderr, "ERROR: Unable to load input file: %s\n\n", file_name);
  }
}


x86 assembly (clang, -O0):
<genembbin_fromfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <load_binfile_to_memory@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     122c <genembbin_fromfile+0xec>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1202 <genembbin_fromfile+0xc2>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ef <genembbin_fromfile+0xaf>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f4 <genembbin_fromfile+0xb4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11aa <genembbin_fromfile+0x6a>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1245 <genembbin_fromfile+0x105>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdfa(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genembbin_fromfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x4(%rsp),%rsi
mov    %r15,%rdi
call   1080 <load_binfile_to_memory@plt>
test   %rax,%rax
je     123b <genembbin_fromfile+0xdb>
mov    %rax,%r12
mov    0x4(%rsp),%edx
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x4(%rsp),%edx
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x9,%edi
call   1040 <putchar@plt>
cmpl   $0x0,0x4(%rsp)
jle    121b <genembbin_fromfile+0xbb>
lea    0xe64(%rip),%r14
lea    0xe60(%rip),%r15
xor    %ebx,%ebx
jmp    11eb <genembbin_fromfile+0x8b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cltq
cmp    %rax,%rbx
jge    121b <genembbin_fromfile+0xbb>
movsbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movslq 0x4(%rsp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rbx
jge    11e0 <genembbin_fromfile+0x80>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x4(%rsp),%eax
jmp    11e0 <genembbin_fromfile+0x80>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe2e(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1253 <genembbin_fromfile+0xf3>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"#define %s_size %d\0A\0A\00"
@.str.1 = [24 x i8] c"const char %s [%d] = {\0A\00"
@.str.2 = [2 x i8] c"\09\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [5 x i8] c"};\0A\0A\00"
@stderr = global i32 0
@.str.7 = [39 x i8] c"ERROR: Unable to load input file: %s\0A\0A\00"
define void @genembbin_fromfile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i8* @load_binfile_to_memory(i8* %8, i32* %5)
store i8* %9, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %46
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13)
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %19
19: ; preds = %38, %11
%20 = load i32, i32* %7
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %41
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = load i32, i32* %5
%33 = sub nsw i32 %32, 1
%34 = icmp slt i32 %31, %33
br i1 %34, label %35, label %37
35: ; preds = %23
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %23
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %19
41: ; preds = %19
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%44 = load i8*, i8** %6
%45 = call i32 @free(i8* %44)
br label %50
46: ; preds = %2
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %4
%49 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %46, %41
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"#define %s_size %d\0A\0A\00"
@.str.1 = [24 x i8] c"const char %s [%d] = {\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c", \00"
@stderr = global i32 0
@.str.7 = [39 x i8] c"ERROR: Unable to load input file: %s\0A\0A\00"
@str = [4 x i8] c"};\0A\00"
define void @genembbin_fromfile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i8* @load_binfile_to_memory(i8* %1, i32* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %37, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %10)
%12 = call i32 @putchar(i32 9)
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %7, %28
%16 = phi i64 [ %30, %28 ], [ 0, %7 ]
%17 = getelementptr inbounds i8, i8* %5, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %16, %23
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* %3
br label %28
28: ; preds = %15, %25
%29 = phi i32 [ %21, %15 ], [ %27, %25 ]
%30 = add nuw nsw i64 %16, 1
%31 = sext i32 %29 to i64
%32 = icmp slt i64 %30, %31
br i1 %32, label %15, label %33
33: ; preds = %28, %7
%34 = call i32 @putchar(i32 10)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%36 = call i32 @free(i8* %5)
br label %40
37: ; preds = %2
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %1)
br label %40
40: ; preds = %37, %33
ret void
}