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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_or_exit(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr,
            "USAGE: %s {sym} {rsrc}\n\n"
            "  Creates {sym}.c from the contents of {rsrc}\n",
            argv[0]);
    return EXIT_FAILURE;
  }
  const char *sym = argv[1];
  FILE *in = open_or_exit(argv[2], "r");
  char symfile[256];
  snprintf(symfile, sizeof(symfile), "%s.c", sym);
  FILE *out = open_or_exit(symfile, "w");
  fprintf(out, "#include <stdlib.h>\n");
  fprintf(out, "const char %s[] = {\n", sym);
  char buf[256];
  size_t nread = 0;
  size_t linecount = 0;
  do {
    nread = fread(buf, 1, sizeof(buf), in);
    size_t i;
    for (i = 0; i < nread; i++) {
      fprintf(out, "0x%02x, ", buf[i]);
      if (++linecount == 10) {
        fprintf(out, "\n");
        linecount = 0;
      }
    }
  } while (nread > 0);
  if (linecount > 0)
    fprintf(out, "\n");
  fprintf(out, "};\n");
  fprintf(out, "const size_t %s_len = sizeof(%s);\n\n", sym, sym);
  fclose(in);
  fclose(out);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a3 <main+0x53>
mov    0x2e66(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <main+0x236>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe89(%rip),%rsi
call   1060 <open_or_exit@plt>
mov    %rax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x100,%esi
lea    0xe6b(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <open_or_exit@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x128(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x238(%rbp)
movq   $0x0,-0x240(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
mov    %rax,-0x238(%rbp)
movq   $0x0,-0x248(%rbp)
mov    -0x248(%rbp),%rax
cmp    -0x238(%rbp),%rax
jae    12fd <main+0x1ad>
mov    -0x128(%rbp),%rdi
mov    -0x248(%rbp),%rax
movsbl -0x230(%rbp,%rax,1),%edx
ff
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x240(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x240(%rbp)
cmp    $0xa,%rax
jne    12e1 <main+0x191>
mov    -0x128(%rbp),%rdi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x240(%rbp)
jmp    12e6 <main+0x196>
mov    -0x248(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x248(%rbp)
jmp    126d <main+0x11d>
jmp    1302 <main+0x1b2>
cmpq   $0x0,-0x238(%rbp)
ja     1241 <main+0xf1>
cmpq   $0x0,-0x240(%rbp)
jbe    1333 <main+0x1e3>
mov    -0x128(%rbp),%rdi
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x128(%rbp),%rdi
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x128(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
cmp    $0x2,%edi
jg     11ad <main+0x3d>
mov    0x2e53(%rip),%rax
movslq (%rax),%rdi
mov    (%rsi),%rdx
lea    0xe66(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2e30(%rip),%rax
jmp    1303 <main+0x193>
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <open_or_exit@plt>
mov    %rax,%r15
lea    0xe7e(%rip),%rdx
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rbp,%rcx
call   1050 <snprintf@plt>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1060 <open_or_exit@plt>
mov    %rax,%rbx
lea    0xe54(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe4c(%rip),%r13
xor    %r14d,%r14d
jmp    1245 <main+0xd5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %rbp,%rbp
je     12a8 <main+0x138>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12a8 <main+0x138>
mov    %rax,%rbp
xor    %r12d,%r12d
jmp    1279 <main+0x109>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r12,%rbp
je     1240 <main+0xd0>
movsbl 0x10(%rsp,%r12,1),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r14
cmp    $0xa,%r14
jne    1270 <main+0x100>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
xor    %r14d,%r14d
jmp    1270 <main+0x100>
test   %r14,%r14
je     12ba <main+0x14a>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0xdc2(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xdad(%rip),%rsi
mov    %rbx,%rdi
mov    0x8(%rsp),%rcx
mov    %rcx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [71 x i8] c"USAGE: %s {sym} {rsrc}\0A\0A Creates {sym}.c from the contents of {rsrc}\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s.c\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"#include <stdlib.h>\0A\00"
@.str.5 = [21 x i8] c"const char %s[] = {\0A\00"
@.str.6 = [9 x i8] c"0x%02x, \00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [4 x i8] c"};\0A\00"
@.str.9 = [36 x i8] c"const size_t %s_len = sizeof(%s);\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca i32*
%10 = alloca [256 x i8]
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
store i32 %24, i32* %3
br label %90
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @open_or_exit(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %7
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = call i32 @snprintf(i8* %33, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%37 = call i32* @open_or_exit(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %37, i32** %9
%38 = load i32*, i32** %9
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32*, i32** %9
%41 = load i8*, i8** %6
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %41)
store i64 0, i64* %11
store i64 0, i64* %12
br label %43
43: ; preds = %69, %25
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%45 = load i32*, i32** %7
%46 = call i64 @fread(i8* %44, i32 1, i32 256, i32* %45)
store i64 %46, i64* %11
store i64 0, i64* %13
br label %47
47: ; preds = %65, %43
%48 = load i64, i64* %13
%49 = load i64, i64* %11
%50 = icmp ult i64 %48, %49
br i1 %50, label %51, label %68
51: ; preds = %47
%52 = load i32*, i32** %9
%53 = load i64, i64* %13
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = load i64, i64* %12
%59 = add i64 %58, 1
store i64 %59, i64* %12
%60 = icmp eq i64 %59, 10
br i1 %60, label %61, label %64
61: ; preds = %51
%62 = load i32*, i32** %9
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i64 0, i64* %12
br label %64
64: ; preds = %61, %51
br label %65
65: ; preds = %64
%66 = load i64, i64* %13
%67 = add i64 %66, 1
store i64 %67, i64* %13
br label %47
68: ; preds = %47
br label %69
69: ; preds = %68
%70 = load i64, i64* %11
%71 = icmp ugt i64 %70, 0
br i1 %71, label %43, label %72
72: ; preds = %69
%73 = load i64, i64* %12
%74 = icmp ugt i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i32*, i32** %9
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %78
78: ; preds = %75, %72
%79 = load i32*, i32** %9
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%81 = load i32*, i32** %9
%82 = load i8*, i8** %6
%83 = load i8*, i8** %6
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %81, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i8* %82, i8* %83)
%85 = load i32*, i32** %7
%86 = call i32 @fclose(i32* %85)
%87 = load i32*, i32** %9
%88 = call i32 @fclose(i32* %87)
%89 = load i32, i32* @EXIT_SUCCESS
store i32 %89, i32* %3
br label %90
90: ; preds = %78, %16
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [71 x i8] c"USAGE: %s {sym} {rsrc}\0A\0A Creates {sym}.c from the contents of {rsrc}\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s.c\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"#include <stdlib.h>\0A\00"
@.str.5 = [21 x i8] c"const char %s[] = {\0A\00"
@.str.6 = [9 x i8] c"0x%02x, \00"
@.str.8 = [4 x i8] c"};\0A\00"
@.str.9 = [36 x i8] c"const size_t %s_len = sizeof(%s);\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = load i8*, i8** %1
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
br label %56
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @open_or_exit(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = call i32 @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%21 = call i32* @open_or_exit(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 20, i64 1, i32* %21)
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
br label %25
25: ; preds = %44, %13
%26 = phi i64 [ 0, %13 ], [ %41, %44 ]
%27 = call i64 @fread(i8* %24, i32 1, i32 256, i32* %18)
%28 = icmp eq i64 %27, 0
br i1 %28, label %45, label %29
29: ; preds = %25, %40
%30 = phi i64 [ %42, %40 ], [ 0, %25 ]
%31 = phi i64 [ %41, %40 ], [ %26, %25 ]
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %30
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %34)
%36 = add i64 %31, 1
%37 = icmp eq i64 %36, 10
br i1 %37, label %38, label %40
38: ; preds = %29
%39 = call i32 @fputc(i32 10, i32* %21)
br label %40
40: ; preds = %29, %38
%41 = phi i64 [ 0, %38 ], [ %36, %29 ]
%42 = add nuw i64 %30, 1
%43 = icmp eq i64 %42, %27
br i1 %43, label %44, label %29
44: ; preds = %40
br i1 %28, label %45, label %25
45: ; preds = %25, %44
%46 = phi i64 [ %41, %44 ], [ %26, %25 ]
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @fputc(i32 10, i32* %21)
br label %50
50: ; preds = %48, %45
%51 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 3, i64 1, i32* %21)
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i8* %15, i8* %15)
%53 = call i32 @fclose(i32* %18)
%54 = call i32 @fclose(i32* %21)
%55 = load i32, i32* @EXIT_SUCCESS
br label %56
56: ; preds = %50, %6
%57 = phi i32 [ %12, %6 ], [ %55, %50 ]
ret i32 %57
}