#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getc(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int c;
  unsigned int n;
  char *name;
  if (argc == 1) {
    fprintf(stderr, "bin2char <varname>\n");
    fprintf(stderr, "read from standard input and write a char"
                    " array out to standard output\n");
    exit(1);
  }
  n = 0;
  name = argv[1];
  fprintf(stdout, "/* autogenerated from %s */\n", argv[0]);
  fprintf(stdout, "unsigned const char %s[] = {\n", name);
  while ((c = getc(stdin)) != EOF) {
    fprintf(stdout, "0x%02x,", c & 0xff);
    if ((++n % 16) == 0)
      fprintf(stdout, "\n");
  }
  fprintf(stdout, "0 /* terminate with a null */};\n");
  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   $0x1,-0x8(%rbp)
jne    1188 <main+0x58>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xeac(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
je     1245 <main+0x115>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
and    $0xff,%edx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
and    $0xf,%eax
cmp    $0x0,%eax
jne    1240 <main+0x110>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11d4 <main+0xa4>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
je     1205 <main+0xd5>
mov    (%rsi),%rdx
mov    0x8(%rsi),%r14
mov    0x2e76(%rip),%rbx
mov    (%rbx),%edi
lea    0xf01(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf0e(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e6c(%rip),%r12
mov    (%r12),%edi
call   1050 <getc@plt>
mov    0x2e54(%rip),%r13
cmp    0x0(%r13),%eax
jne    11b3 <main+0x83>
mov    (%rbx),%edi
lea    0xf04(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
lea    0xed8(%rip),%r15
lea    0xeb1(%rip),%r14
jmp    11e2 <main+0xb2>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
call   1050 <getc@plt>
add    $0x1,%ebp
cmp    0x0(%r13),%eax
je     1192 <main+0x62>
mov    (%rbx),%edi
movzbl %al,%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
test   $0xf,%bpl
jne    11d0 <main+0xa0>
mov    (%rbx),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11d0 <main+0xa0>
mov    0x2dc4(%rip),%rbx
mov    (%rbx),%edi
lea    0xdeb(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdef(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"bin2char <varname>\0A\00"
@.str.1 = [72 x i8] c"read from standard input and write a char array out to standard output\0A\00"
@stdout = global i32 0
@.str.2 = [29 x i8] c"/* autogenerated from %s */\0A\00"
@.str.3 = [30 x i8] c"unsigned const char %s[] = {\0A\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.4 = [8 x i8] c"0x%02x,\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [33 x i8] c"0 /* terminate with a null */};\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 0, i32* %7
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %8
%21 = load i32, i32* @stdout
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @stdout
%27 = load i8*, i8** %8
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %46, %17
%30 = load i32, i32* @stdin
%31 = call i32 @getc(i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = load i32, i32* @stdout
%36 = load i32, i32* %6
%37 = and i32 %36, 255
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %7
%40 = add i32 %39, 1
store i32 %40, i32* %7
%41 = urem i32 %40, 16
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %34
%44 = load i32, i32* @stdout
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %43, %34
br label %29
47: ; preds = %29
%48 = load i32, i32* @stdout
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"bin2char <varname>\0A\00"
@.str.1 = [72 x i8] c"read from standard input and write a char array out to standard output\0A\00"
@stdout = global i32 0
@.str.2 = [29 x i8] c"/* autogenerated from %s */\0A\00"
@.str.3 = [30 x i8] c"unsigned const char %s[] = {\0A\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.4 = [8 x i8] c"0x%02x,\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [33 x i8] c"0 /* terminate with a null */};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @stdout
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stdout
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%18 = load i32, i32* @stdin
%19 = tail call i32 @getc(i32 %18)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %39, label %22
22: ; preds = %10, %34
%23 = phi i32 [ %36, %34 ], [ %19, %10 ]
%24 = phi i32 [ %28, %34 ], [ 0, %10 ]
%25 = load i32, i32* @stdout
%26 = and i32 %23, 255
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = add i32 %24, 1
%29 = and i32 %28, 15
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i32, i32* @stdout
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %31, %22
%35 = load i32, i32* @stdin
%36 = tail call i32 @getc(i32 %35)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %22
39: ; preds = %34, %10
%40 = load i32, i32* @stdout
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}