#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 getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
void main(int argc, const char **argv) {
  int c;
  int j;
  int notfirst;
  if (argc != 2) {
    printf("usage: makecbin arrayname <binfile >textfile\n");
    exit(-1);
  }
  printf("char %s[]={", argv[1]);
  j = 0;
  notfirst = 0;
  for (;;) {
    c = getc(stdin);
    if (c == EOF)
      break;
    if (notfirst)
      printf(",");
    if (j++ % 16 == 0)
      printf("\n");
    printf("0x%02X", c);
    notfirst = 1;
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     1161 <main+0x31>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
jne    11ad <main+0x7d>
jmp    120c <main+0xdc>
cmpl   $0x0,-0x1c(%rbp)
je     11c5 <main+0x95>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ef <main+0xbf>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1185 <main+0x55>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jne    1219 <main+0xc9>
mov    0x8(%rsi),%rsi
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e6e(%rip),%r14
mov    (%r14),%edi
call   1070 <getc@plt>
mov    0x2e57(%rip),%r15
cmp    (%r15),%eax
je     11b7 <main+0x67>
mov    %eax,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe6b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%edi
call   1070 <getc@plt>
cmp    (%r15),%eax
jne    11cb <main+0x7b>
lea    0xe55(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    %eax,%ebp
mov    $0x1,%ebx
lea    0xe33(%rip),%r12
jmp    11fe <main+0xae>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebp
add    $0x1,%ebx
cmp    (%r15),%eax
je     11b7 <main+0x67>
mov    $0x2c,%edi
call   1030 <putchar@plt>
test   $0xf,%bl
jne    11e0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11e0 <main+0x90>
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"usage: makecbin arrayname <binfile >textfile\0A\00"
@.str.1 = [12 x i8] c"char %s[]={\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.2 = [2 x i8] c",\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [7 x i8] c"0x%02X\00"
@.str.5 = [4 x i8] c"};\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 0, i32* %6
store i32 0, i32* %7
br label %18
18: ; preds = %37, %13
%19 = load i32, i32* @stdin
%20 = call i32 @getc(i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %18
br label %40
25: ; preds = %18
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = srem i32 %31, 16
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = load i32, i32* %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %38)
store i32 1, i32* %7
br label %18
40: ; preds = %24
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"char %s[]={\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.4 = [7 x i8] c"0x%02X\00"
@str = [3 x i8] c"};\00"
@str.6 = [45 x i8] c"usage: makecbin arrayname <binfile >textfile\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @stdin
%12 = tail call i32 @getc(i32 %11)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %37, label %15
15: ; preds = %7
%16 = tail call i32 @putchar(i32 10)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %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 %37, label %22
22: ; preds = %15, %31
%23 = phi i32 [ %34, %31 ], [ %19, %15 ]
%24 = phi i32 [ %26, %31 ], [ 1, %15 ]
%25 = tail call i32 @putchar(i32 44)
%26 = add nuw nsw i32 %24, 1
%27 = and i32 %24, 15
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = tail call i32 @putchar(i32 10)
br label %31
31: ; preds = %29, %22
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%33 = load i32, i32* @stdin
%34 = tail call i32 @getc(i32 %33)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %22
37: ; preds = %31, %15, %7
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret void
}