#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "%s needs one argument: the structure name\n", argv[0]);
    exit(1);
  }
  printf("/* bin2header output - automatically generated */\n");
  printf("unsigned char %s[] = {\n", argv[1]);
  while (1) {
    int i, nread;
    unsigned char buf[10];
    nread = read(0, buf, sizeof(buf));
    if (nread <= 0)
      break;
    printf("\t");
    for (i = 0; i < nread - 1; i++)
      printf("0x%02x, ", buf[i]);
    printf("0x%02x,\n", buf[nread - 1]);
  }
  printf("};\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1186 <main+0x46>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x22(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     11cc <main+0x8c>
jmp    1237 <main+0xf7>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1217 <main+0xd7>
movslq -0x14(%rbp),%rax
movzbl -0x22(%rbp,%rax,1),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e1 <main+0xa1>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
movzbl -0x22(%rbp,%rax,1),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11aa <main+0x6a>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1198 <main+0x38>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe77(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rbx),%rsi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe(%rsp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11de <main+0x7e>
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    %eax,%ebp
lea    0xe5c(%rip),%r13
lea    0xe5e(%rip),%r14
lea    0xe(%rsp),%r15
jmp    1225 <main+0xc5>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0xe(%rsp,%r12,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11cb <main+0x6b>
mov    $0x9,%edi
call   1030 <putchar@plt>
movslq %ebp,%rax
lea    -0x1(%rax),%r12
cmp    $0x2,%eax
jb     1200 <main+0xa0>
mov    %r12d,%ebp
xor    %ebx,%ebx
movzbl 0xe(%rsp,%rbx,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1240 <main+0xe0>
jmp    1200 <main+0xa0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"%s needs one argument: the structure name\0A\00"
@.str.1 = [51 x i8] c"/* bin2header output - automatically generated */\0A\00"
@.str.2 = [24 x i8] c"unsigned char %s[] = {\0A\00"
@.str.3 = [2 x i8] c"\09\00"
@.str.4 = [9 x i8] c"0x%02x, \00"
@.str.5 = [9 x i8] c"0x%02x,\0A\00"
@.str.6 = [4 x i8] c"};\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 [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %18, %47
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%26 = call i32 @read(i32 0, i8* %25, i32 10)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %55
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %32
32: ; preds = %44, %30
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %47
37: ; preds = %32
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %37
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %32
47: ; preds = %32
%48 = load i32, i32* %7
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %53)
br label %24
55: ; preds = %29
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%57 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"%s needs one argument: the structure name\0A\00"
@.str.2 = [24 x i8] c"unsigned char %s[] = {\0A\00"
@.str.4 = [9 x i8] c"0x%02x, \00"
@.str.5 = [9 x i8] c"0x%02x,\0A\00"
@str = [50 x i8] c"/* bin2header output - automatically generated */\00"
@str.7 = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = call i32 @read(i32 0, i8* %15, i32 10)
%17 = icmp slt i32 %16, 1
br i1 %17, label %41, label %18
18: ; preds = %10, %33
%19 = phi i32 [ %39, %33 ], [ %16, %10 ]
%20 = tail call i32 @putchar(i32 9)
%21 = add nsw i32 %19, -1
%22 = icmp ugt i32 %19, 1
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = zext i32 %21 to i64
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %31, %25 ]
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %26, 1
%32 = icmp eq i64 %31, %24
br i1 %32, label %33, label %25
33: ; preds = %25, %18
%34 = sext i32 %21 to i64
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = call i32 @read(i32 0, i8* %15, i32 10)
%40 = icmp slt i32 %39, 1
br i1 %40, label %41, label %18
41: ; preds = %33, %10
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0))
%43 = tail call i32 @exit(i32 0)
unreachable
}