#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 EOF;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main(int argc, char **argv) {
  FILE *file = 0;
  int k = 0, nc = 16, i = 0, ch = 0;
  char *name = 0;
  if (argc != 2) {
    printf("usage: embed <file>\n");
    return 1;
  }
  name = argv[1];
  while (name[k] && (name[k] != '.'))
    ++k;
  name = malloc(k + 1);
  memcpy(name, argv[1], k);
  name[k] = 0;
  file = fopen(argv[1], "r");
  if (!file) {
    int ret = errno;
    perror("embed");
    return ret;
  }
  printf("static unsigned char %s[] = {\n", name);
  while ((ch = fgetc(file)) != EOF) {
    if (i != 0) {
      putchar(',');
      if (i % nc == 0)
        putchar('\n');
    }
    printf("0x%02X", ch);
    ++i;
  }
  printf("\n"
         "};\n"
         "static int %sSize = %d;\n",
         name, i);
  fclose(file);
  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)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x10,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e6 <main+0x66>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1358 <main+0x1d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x35(%rbp)
je     1221 <main+0xa1>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1231 <main+0xb1>
jmp    123f <main+0xbf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f2 <main+0x72>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd98(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12b4 <main+0x134>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
lea    0xd73(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1358 <main+0x1d8>
mov    -0x30(%rbp),%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d0f(%rip),%rcx
cmp    (%rcx),%eax
je     1333 <main+0x1b3>
cmpl   $0x0,-0x24(%rbp)
je     1314 <main+0x194>
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x20(%rbp)
cmp    $0x0,%edx
jne    130f <main+0x18f>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1314 <main+0x194>
mov    -0x28(%rbp),%esi
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12c6 <main+0x146>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11c3 <main+0x33>
mov    %rsi,%r14
mov    0x8(%rsi),%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl 0x0(%rbp,%rbx,1),%eax
test   %al,%al
je     11d9 <main+0x49>
cmp    $0x2e,%al
je     11d9 <main+0x49>
add    $0x1,%rbx
jmp    11b0 <main+0x20>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    127e <main+0xee>
mov    %ebx,%r12d
lea    0x1(%rbx),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1080 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    0x8(%r14),%rdi
lea    0xdfc(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d9 <main+0x149>
mov    %rax,%r12
lea    0xdec(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1070 <fgetc@plt>
mov    0x2db3(%rip),%r14
mov    $0x0,%ebx
cmp    (%r14),%eax
je     1261 <main+0xd1>
lea    0xde1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1070 <fgetc@plt>
mov    $0x1,%ebx
cmp    (%r14),%eax
jne    128f <main+0xff>
lea    0xdc6(%rip),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    $0x1,%ebx
lea    0xd8a(%rip),%r13
jmp    12be <main+0x12e>
nop
mov    %r13,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebx
mov    %r12,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
je     1261 <main+0xd1>
mov    $0x2c,%edi
call   1030 <putchar@plt>
test   $0xf,%bl
jne    12a0 <main+0x110>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12a0 <main+0x110>
mov    0x2cf8(%rip),%rax
mov    (%rax),%ebx
lea    0xd19(%rip),%rdi
call   10b0 <perror@plt>
jmp    127e <main+0xee>

LLVM IR (-O0):
@.str = [21 x i8] c"usage: embed <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"embed\00"
@.str.3 = [31 x i8] c"static unsigned char %s[] = {\0A\00"
@EOF = global i32 0
@.str.4 = [7 x i8] c"0x%02X\00"
@.str.5 = [29 x i8] c"\0A};\0Astatic int %sSize = %d;\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 i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %7
store i32 16, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i8* null, i8** %11
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %97
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %11
br label %21
21: ; preds = %39, %17
%22 = load i8*, i8** %11
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %21
%30 = load i8*, i8** %11
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 46
br label %37
37: ; preds = %29, %21
%38 = phi i1 [ false, %21 ], [ %36, %29 ]
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %21
42: ; preds = %37
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
%45 = call i8* @malloc(i32 %44)
store i8* %45, i8** %11
%46 = load i8*, i8** %11
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i32, i32* %7
%51 = call i32 @memcpy(i8* %46, i8* %49, i32 %50)
%52 = load i8*, i8** %11
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 0, i8* %55
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %59, i32** %6
%60 = load i32*, i32** %6
%61 = icmp ne i32* %60, null
br i1 %61, label %66, label %62
62: ; preds = %42
%63 = load i32, i32* @errno
store i32 %63, i32* %12
%64 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%65 = load i32, i32* %12
store i32 %65, i32* %3
br label %97
66: ; preds = %42
%67 = load i8*, i8** %11
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %86, %66
%70 = load i32*, i32** %6
%71 = call i32 @fgetc(i32* %70)
store i32 %71, i32* %10
%72 = load i32, i32* @EOF
%73 = icmp ne i32 %71, %72
br i1 %73, label %74, label %91
74: ; preds = %69
%75 = load i32, i32* %9
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %86
77: ; preds = %74
%78 = call i32 @putchar(i8 signext 44)
%79 = load i32, i32* %9
%80 = load i32, i32* %8
%81 = srem i32 %79, %80
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %77
%84 = call i32 @putchar(i8 signext 10)
br label %85
85: ; preds = %83, %77
br label %86
86: ; preds = %85, %74
%87 = load i32, i32* %10
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 1
store i32 %90, i32* %9
br label %69
91: ; preds = %69
%92 = load i8*, i8** %11
%93 = load i32, i32* %9
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %92, i32 %93)
%95 = load i32*, i32** %6
%96 = call i32 @fclose(i32* %95)
store i32 0, i32* %3
br label %97
97: ; preds = %91, %62, %15
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"embed\00"
@.str.3 = [31 x i8] c"static unsigned char %s[] = {\0A\00"
@EOF = global i32 0
@.str.4 = [7 x i8] c"0x%02X\00"
@.str.5 = [29 x i8] c"\0A};\0Astatic int %sSize = %d;\0A\00"
@str = [20 x i8] c"usage: embed <file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %56
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %13, %6
%10 = phi i64 [ %14, %13 ], [ 0, %6 ]
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %13 [
i8 0, label %15
i8 46, label %15
]
13: ; preds = %9
%14 = add nuw i64 %10, 1
br label %9
15: ; preds = %9, %9
%16 = trunc i64 %10 to i32
%17 = and i64 %10, 4294967295
%18 = add nuw nsw i32 %16, 1
%19 = tail call i8* @malloc(i32 %18)
%20 = tail call i32 @memcpy(i8* %19, i8* %8, i32 %16)
%21 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 0, i8* %21
%22 = load i8*, i8** %7
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load i32, i32* @errno
%27 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %56
28: ; preds = %15
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%30 = tail call i32 @fgetc(i32* %23)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %52, label %33
33: ; preds = %28
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%35 = tail call i32 @fgetc(i32* %23)
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %52, label %38
38: ; preds = %33, %46
%39 = phi i32 [ %49, %46 ], [ %35, %33 ]
%40 = phi i32 [ %48, %46 ], [ 1, %33 ]
%41 = tail call i32 @putchar(i8 signext 44)
%42 = and i32 %40, 15
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = tail call i32 @putchar(i8 signext 10)
br label %46
46: ; preds = %38, %44
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%48 = add nuw nsw i32 %40, 1
%49 = tail call i32 @fgetc(i32* %23)
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %38
52: ; preds = %46, %33, %28
%53 = phi i32 [ 0, %28 ], [ 1, %33 ], [ %48, %46 ]
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %19, i32 %53)
%55 = tail call i32 @fclose(i32* %23)
br label %56
56: ; preds = %52, %25, %4
%57 = phi i32 [ 1, %4 ], [ 0, %52 ], [ %26, %25 ]
ret i32 %57
}