#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 EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int c, colno;
  if (argc != 2) {
    fprintf(stderr, "Usage: bin2c varname < infile > outfile\n");
    return 0;
  }
  (void)puts("/* This file is automatically generated; to modify it,");
  (void)puts("   modify the source file, not this file. */");
  (void)puts("#include \"config.h\"");
  printf("const char* %s=\"\\\n", argv[1]);
  colno = 0;
  while ((c = getchar()) != EOF) {
    printf("\\x%02x", (unsigned)c);
    colno += 4;
    if (colno > 70) {
      (void)puts("\\");
      colno = 0;
    }
  }
  (void)puts("\";");
  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   $0x2,-0x8(%rbp)
je     1181 <main+0x41>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    122a <main+0xea>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
je     1217 <main+0xd7>
mov    -0x14(%rbp),%esi
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x46,-0x18(%rbp)
jle    1212 <main+0xd2>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x18(%rbp)
jmp    11c2 <main+0x82>
lea    0xe9f(%rip),%rdi
call   1030 <puts@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
cmp    $0x2,%edi
jne    11a6 <main+0x66>
mov    %rsi,%rbx
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xefe(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rsi
lea    0xf23(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e55(%rip),%r15
cmp    (%r15),%eax
jne    11c8 <main+0x88>
lea    0xf1e(%rip),%rdi
call   1030 <puts@plt>
jmp    11bb <main+0x7b>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xee5(%rip),%rbx
lea    0xee5(%rip),%r14
xor    %ebp,%ebp
jmp    11f6 <main+0xb6>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%eax
je     1198 <main+0x58>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x43,%ebp
jge    11e0 <main+0xa0>
add    $0x4,%ebp
jmp    11ea <main+0xaa>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: bin2c varname < infile > outfile\0A\00"
@.str.1 = [55 x i8] c"/* This file is automatically generated; to modify it,\00"
@.str.2 = [45 x i8] c" modify the source file, not this file. */\00"
@.str.3 = [20 x i8] c"#include \22config.h\22\00"
@.str.4 = [19 x i8] c"const char* %s=\22\\\0A\00"
@EOF = global i32 0
@.str.5 = [7 x i8] c"\\x%02x\00"
@.str.6 = [2 x i8] c"\\\00"
@.str.7 = [3 x i8] c"\22;\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
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, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %37
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %19)
store i32 0, i32* %7
br label %21
21: ; preds = %34, %13
%22 = call i32 (...) @getchar()
store i32 %22, i32* %6
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 4
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp sgt i32 %30, 70
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %7
br label %34
34: ; preds = %32, %25
br label %21
35: ; preds = %21
%36 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %37
37: ; preds = %35, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: bin2c varname < infile > outfile\0A\00"
@.str.1 = [55 x i8] c"/* This file is automatically generated; to modify it,\00"
@.str.2 = [45 x i8] c" modify the source file, not this file. */\00"
@.str.3 = [20 x i8] c"#include \22config.h\22\00"
@.str.4 = [19 x i8] c"const char* %s=\22\\\0A\00"
@EOF = global i32 0
@.str.5 = [7 x i8] c"\\x%02x\00"
@.str.6 = [2 x i8] c"\\\00"
@.str.7 = [3 x i8] c"\22;\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %32
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %30, label %17
17: ; preds = %7, %25
%18 = phi i32 [ %27, %25 ], [ %14, %7 ]
%19 = phi i32 [ %26, %25 ], [ 0, %7 ]
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%21 = add nsw i32 %19, 4
%22 = icmp sgt i32 %19, 66
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %25
25: ; preds = %23, %17
%26 = phi i32 [ 0, %23 ], [ %21, %17 ]
%27 = tail call i32 (...) @getchar()
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %17
30: ; preds = %25, %7
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %30, %4
ret i32 0
}