#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*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned char buffer[1024];
  int i, l, n = 0;
  if (argc != 2) {
    fprintf(stderr, "Bad usage\n");
    exit(-1);
  }
  printf("static unsigned char %s[] =\n", argv[1]);
  printf("{\n");
  while ((l = read(0, buffer, sizeof(buffer))) > 0) {
    for (i = 0; i < l; i++) {
      if (n > 0)
        printf(", ");
      if (n && (n % 16) == 0)
        printf("\n");
      printf("0x%02x", buffer[i]);
      n++;
    }
  }
  printf("\n};\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x41c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118c <main+0x4c>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x418(%rbp)
cmp    $0x0,%eax
jle    1280 <main+0x140>
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x418(%rbp),%eax
jge    127b <main+0x13b>
cmpl   $0x0,-0x41c(%rbp)
jle    1209 <main+0xc9>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x41c(%rbp)
je     123b <main+0xfb>
mov    -0x41c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    123b <main+0xfb>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x414(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%esi
ff
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11dc <main+0x9c>
jmp    11b0 <main+0x70>
lea    0xdae(%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    $0x408,%rsp
cmp    $0x2,%edi
jne    1241 <main+0xe1>
mov    0x8(%rsi),%rsi
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1260 <main+0x100>
lea    0xe72(%rip),%r14
lea    0xe6e(%rip),%r12
xor    %r13d,%r13d
jmp    11e6 <main+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %ebx,%r13d
xor    %edi,%edi
mov    %rsp,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1260 <main+0x100>
mov    %r13d,%ecx
mov    %r13d,%ebx
mov    %eax,%r13d
xor    %ebp,%ebp
jmp    1217 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rsp,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11d0 <main+0x70>
lea    (%rbx,%rbp,1),%r15
test   %r15d,%r15d
jle    122a <main+0xca>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
je     1200 <main+0xa0>
and    $0xf,%r15d
jne    1200 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1200 <main+0xa0>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xdcd(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"Bad usage\0A\00"
@.str.1 = [29 x i8] c"static unsigned char %s[] =\0A\00"
@.str.2 = [3 x i8] c"{\0A\00"
@.str.3 = [3 x i8] c", \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [7 x i8] c"0x%02x\00"
@.str.6 = [5 x i8] c"\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%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 ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %57, %16
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i32 @read(i32 0, i8* %23, i32 1024)
store i32 %24, i32* %8
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %58
26: ; preds = %22
store i32 0, i32* %7
br label %27
27: ; preds = %54, %26
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %57
31: ; preds = %27
%32 = load i32, i32* %9
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* %9
%41 = srem i32 %40, 16
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %39, %36
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %54
54: ; preds = %45
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %27
57: ; preds = %27
br label %22
58: ; preds = %22
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%60 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"Bad usage\0A\00"
@.str.1 = [29 x i8] c"static unsigned char %s[] =\0A\00"
@.str.3 = [3 x i8] c", \00"
@.str.5 = [7 x i8] c"0x%02x\00"
@str = [2 x i8] c"{\00"
@str.7 = [4 x i8] c"\0A};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, 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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%15 = call i32 @read(i32 0, i8* %4, i32 1024)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %21, label %46
17: ; preds = %38
%18 = add i32 %22, %23
%19 = call i32 @read(i32 0, i8* %4, i32 1024)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %46
21: ; preds = %10, %17
%22 = phi i32 [ %19, %17 ], [ %15, %10 ]
%23 = phi i32 [ %18, %17 ], [ 0, %10 ]
%24 = zext i32 %22 to i64
br label %25
25: ; preds = %21, %38
%26 = phi i64 [ 0, %21 ], [ %44, %38 ]
%27 = phi i32 [ %23, %21 ], [ %43, %38 ]
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = icmp ne i32 %27, 0
%33 = and i32 %27, 15
%34 = icmp eq i32 %33, 0
%35 = and i1 %32, %34
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = tail call i32 @putchar(i32 10)
br label %38
38: ; preds = %36, %31
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %26
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = add nsw i32 %27, 1
%44 = add nuw nsw i64 %26, 1
%45 = icmp eq i64 %44, %24
br i1 %45, label %17, label %25
46: ; preds = %17, %10
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.7, i64 0, i64 0))
%48 = tail call i32 @exit(i32 0)
unreachable
}