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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    return 1;
  }
  if (strlen(argv[1]) == 0) {
    return 1;
  }
  FILE *fp = fopen(argv[2], "rb");
  if (!fp) {
    return 1;
  }
  unsigned char buffer[1024];
  size_t totalBytes = 0;
  size_t bytes;
  printf("unsigned char %s[] = {", argv[1]);
  const size_t lineLength = 16;
  while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
    for (size_t i = 0; i < bytes; i++) {
      if (i % lineLength == 0) {
        printf("\n");
      }
      printf(" 0x%02x,", buffer[i]);
    }
    totalBytes += bytes;
  }
  printf("\n 0x00};\n"
         "unsigned int %s_len = %lu;\n",
         argv[1], totalBytes);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    117f <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    12e5 <main+0x195>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    11a2 <main+0x52>
movl   $0x1,-0x4(%rbp)
jmp    12e5 <main+0x195>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <main+0x81>
movl   $0x1,-0x4(%rbp)
jmp    12e5 <main+0x195>
movq   $0x0,-0x428(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x10,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
jbe    12b8 <main+0x168>
movq   $0x0,-0x440(%rbp)
mov    -0x440(%rbp),%rax
cmp    -0x430(%rbp),%rax
jae    129e <main+0x14e>
mov    -0x440(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    126a <main+0x11a>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x440(%rbp),%rax
movzbl -0x420(%rbp,%rax,1),%esi
ff
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x440(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x440(%rbp)
jmp    1233 <main+0xe3>
mov    -0x430(%rbp),%rax
add    -0x428(%rbp),%rax
mov    %rax,-0x428(%rbp)
jmp    11fd <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x428(%rbp),%rdx
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    $0x1,%ebx
cmp    $0x3,%edi
jl     1272 <main+0x122>
mov    %rsi,%rbp
mov    0x8(%rsi),%rax
cmpb   $0x0,(%rax)
je     1272 <main+0x122>
mov    0x10(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1272 <main+0x122>
mov    %rax,%r12
mov    %rbp,0x8(%rsp)
mov    0x8(%rbp),%rsi
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     124b <main+0xfb>
mov    %rax,%rbp
lea    0xe42(%rip),%rbx
lea    0x10(%rsp),%r14
xor    %r13d,%r13d
jmp    1210 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %rbp,%r13
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rax,%rbp
test   %rax,%rax
je     124e <main+0xfe>
xor    %r15d,%r15d
jmp    1239 <main+0xe9>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x10(%rsp,%r15,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
je     11f0 <main+0xa0>
test   $0xf,%r15b
jne    1220 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0xd0>
xor    %r13d,%r13d
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
lea    0xdc5(%rip),%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [23 x i8] c"unsigned char %s[] = {\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [9 x i8] c" 0x%02x,\00"
@.str.4 = [37 x i8] c"\0A 0x00};\0Aunsigned int %s_len = %lu;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %72
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strlen(i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 1, i32* %3
br label %72
22: ; preds = %15
%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, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i32*, i32** %6
%28 = icmp ne i32* %27, null
br i1 %28, label %30, label %29
29: ; preds = %22
store i32 1, i32* %3
br label %72
30: ; preds = %22
store i64 0, i64* %8
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i64 16, i64* %10
br label %35
35: ; preds = %60, %30
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = load i32*, i32** %6
%38 = call i64 @fread(i8* %36, i32 1, i32 1024, i32* %37)
store i64 %38, i64* %9
%39 = icmp ugt i64 %38, 0
br i1 %39, label %40, label %64
40: ; preds = %35
store i64 0, i64* %11
br label %41
41: ; preds = %57, %40
%42 = load i64, i64* %11
%43 = load i64, i64* %9
%44 = icmp ult i64 %42, %43
br i1 %44, label %45, label %60
45: ; preds = %41
%46 = load i64, i64* %11
%47 = urem i64 %46, 16
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
%52 = load i64, i64* %11
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %51
%58 = load i64, i64* %11
%59 = add i64 %58, 1
store i64 %59, i64* %11
br label %41
60: ; preds = %41
%61 = load i64, i64* %9
%62 = load i64, i64* %8
%63 = add i64 %62, %61
store i64 %63, i64* %8
br label %35
64: ; preds = %35
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = load i64, i64* %8
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %67, i64 %68)
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
store i32 0, i32* %3
br label %72
72: ; preds = %64, %29, %21, %14
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [23 x i8] c"unsigned char %s[] = {\00"
@.str.3 = [9 x i8] c" 0x%02x,\00"
@.str.4 = [37 x i8] c"\0A 0x00};\0Aunsigned int %s_len = %lu;\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %46, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %46, label %10
10: ; preds = %5
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %46, label %15
15: ; preds = %10
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i64 @fread(i8* %16, i32 1, i32 1024, i32* %13)
%20 = icmp eq i64 %19, 0
br i1 %20, label %41, label %21
21: ; preds = %15, %24
%22 = phi i64 [ %26, %24 ], [ %19, %15 ]
%23 = phi i64 [ %25, %24 ], [ 0, %15 ]
br label %28
24: ; preds = %34
%25 = add i64 %22, %23
%26 = call i64 @fread(i8* %16, i32 1, i32 1024, i32* %13)
%27 = icmp eq i64 %26, 0
br i1 %27, label %41, label %21
28: ; preds = %21, %34
%29 = phi i64 [ 0, %21 ], [ %39, %34 ]
%30 = and i64 %29, 15
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @putchar(i32 10)
br label %34
34: ; preds = %32, %28
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %29
%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.3, i64 0, i64 0), i32 %37)
%39 = add nuw i64 %29, 1
%40 = icmp eq i64 %39, %22
br i1 %40, label %24, label %28
41: ; preds = %24, %15
%42 = phi i64 [ 0, %15 ], [ %25, %24 ]
%43 = load i8*, i8** %6
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %43, i64 %42)
%45 = tail call i32 @fclose(i32* %13)
br label %46
46: ; preds = %41, %10, %5, %2
%47 = phi i32 [ 1, %2 ], [ 1, %5 ], [ 0, %41 ], [ 1, %10 ]
ret i32 %47
}