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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  FILE *f;
  int cnt;
  int res, x;
  char buf[10];
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("open");
    exit(1);
  }
  f = fopen(argv[2], "w+");
  if (!f) {
    perror("fopen");
    exit(1);
  }
  fprintf(f, "static unsigned char %s[] = {\n", argv[3]);
  read(fd, buf, 8);
  read(fd, buf, 8);
  read(fd, buf, 8);
  while ((res = read(fd, buf, 10)) > 0) {
    for (x = 0; x < res; x++)
      fprintf(f, "%#x, ", buf[x] & 0xff);
    fprintf(f, "\n");
  }
  fprintf(f, "};\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11af <main+0x4f>
lea    0xe64(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e8 <main+0x88>
lea    0xe2a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x36(%rbp),%rsi
mov    $0x8,%edx
call   1030 <read@plt>
mov    -0x14(%rbp),%edi
lea    -0x36(%rbp),%rsi
mov    $0x8,%edx
call   1030 <read@plt>
mov    -0x14(%rbp),%edi
lea    -0x36(%rbp),%rsi
mov    $0x8,%edx
call   1030 <read@plt>
mov    -0x14(%rbp),%edi
lea    -0x36(%rbp),%rsi
mov    $0xa,%edx
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jle    12ab <main+0x14b>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1294 <main+0x134>
mov    -0x20(%rbp),%rdi
movslq -0x2c(%rbp),%rax
movsbl -0x36(%rbp,%rax,1),%edx
and    $0xff,%edx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1259 <main+0xf9>
mov    -0x20(%rbp),%rdi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1235 <main+0xd5>
mov    -0x20(%rbp),%rdi
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     12b6 <main+0x136>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12bf <main+0x13f>
mov    %rax,%r13
mov    0x18(%rbp),%rdx
lea    0xe34(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe(%rsp),%rbp
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    128c <main+0x10c>
lea    0xdf9(%rip),%r12
lea    0xe(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0xe(%rsp,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1250 <main+0xd0>
mov    $0xa,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1240 <main+0xc0>
lea    0xd9b(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10a0 <fwrite@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd47(%rip),%rdi
jmp    12c6 <main+0x146>
lea    0xd3d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [31 x i8] c"static unsigned char %s[] = {\0A\00"
@.str.4 = [6 x i8] c"%#x, \00"
@.str.5 = [2 x i8] c"\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %7
%27 = load i32*, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %22
%33 = load i32*, i32** %7
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %6
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 8)
%41 = load i32, i32* %6
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%43 = call i32 @read(i32 %41, i8* %42, i32 8)
%44 = load i32, i32* %6
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 8)
br label %47
47: ; preds = %69, %32
%48 = load i32, i32* %6
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%50 = call i32 @read(i32 %48, i8* %49, i32 10)
store i32 %50, i32* %9
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %72
52: ; preds = %47
store i32 0, i32* %10
br label %53
53: ; preds = %66, %52
%54 = load i32, i32* %10
%55 = load i32, i32* %9
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %69
57: ; preds = %53
%58 = load i32*, i32** %7
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = and i32 %63, 255
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %57
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %53
69: ; preds = %53
%70 = load i32*, i32** %7
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %47
72: ; preds = %47
%73 = load i32*, i32** %7
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [31 x i8] c"static unsigned char %s[] = {\0A\00"
@.str.4 = [6 x i8] c"%#x, \00"
@.str.6 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = call i32 @read(i32 %8, i8* %4, i32 8)
%26 = call i32 @read(i32 %8, i8* %4, i32 8)
%27 = call i32 @read(i32 %8, i8* %4, i32 8)
%28 = call i32 @read(i32 %8, i8* %4, i32 10)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %45
30: ; preds = %21, %41
%31 = phi i32 [ %43, %41 ], [ %28, %21 ]
%32 = zext i32 %31 to i64
br label %33
33: ; preds = %30, %33
%34 = phi i64 [ 0, %30 ], [ %39, %33 ]
%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 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = add nuw nsw i64 %34, 1
%40 = icmp eq i64 %39, %32
br i1 %40, label %41, label %33
41: ; preds = %33
%42 = tail call i32 @fputc(i32 10, i32* %16)
%43 = call i32 @read(i32 %8, i8* %4, i32 10)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %30, label %45
45: ; preds = %41, %21
%46 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64 3, i64 1, i32* %16)
ret i32 0
}