#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *in;
  FILE *out;
  int length;
  int c;
  if (argc < 3) {
    printf("Usage: dat2inc <datafile> <includefile>\n\n");
    return 1;
  }
  in = fopen(argv[1], "rb");
  if (!in) {
    printf("Datafile open error!\n");
    return 1;
  }
  out = fopen(argv[2], "wt");
  if (!out) {
    printf("Includefile open error!\n");
    return 1;
  }
  fseek(in, 0, SEEK_END);
  length = ftell(in);
  fseek(in, 0, SEEK_SET);
  fprintf(out, "unsigned char datafile[] = {\n");
  for (c = 0; c < length; c++) {
    if (c) {
      fprintf(out, ", ");
      if (!(c % 10))
        fprintf(out, "\n");
    }
    fprintf(out, "0x%02x", fgetc(in));
  }
  fprintf(out, "};\n");
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131c <main+0x1ac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe73(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e3 <main+0x73>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131c <main+0x1ac>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121e <main+0xae>
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131c <main+0x1ac>
mov    -0x18(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d8f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12f1 <main+0x181>
cmpl   $0x0,-0x28(%rbp)
je     12be <main+0x14e>
mov    -0x20(%rbp),%rdi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12b9 <main+0x149>
mov    -0x20(%rbp),%rdi
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12be <main+0x14e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    126b <main+0xfb>
mov    -0x20(%rbp),%rdi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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
jg     11ac <main+0x1c>
lea    0xeb8(%rip),%rdi
jmp    1291 <main+0x101>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe46(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1281 <main+0xf1>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe2d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128a <main+0xfa>
mov    %rax,%rbp
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %eax,%ebx
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0xde8(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
test   %ebx,%ebx
jle    1254 <main+0xc4>
mov    %r15,%rdi
call   1050 <fgetc@plt>
lea    0xde4(%rip),%rsi
mov    %rbp,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
cmp    $0x1,%ebx
jne    12aa <main+0x11a>
lea    0xdd3(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    129b <main+0x10b>
lea    0xdaa(%rip),%rdi
jmp    1291 <main+0x101>
lea    0xdb6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%ebx
mov    $0x1,%r12d
mov    $0xffffffff,%r14d
jmp    12ec <main+0x15c>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %rbp,%rdi
lea    0xd55(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%r12d
add    $0xffffffff,%r14d
add    $0xffffffff,%ebx
je     1254 <main+0xc4>
mov    %r12d,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%r13d
add    %r13d,%r13d
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xd10(%rip),%rdi
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
add    %r14d,%r13d
jne    12c0 <main+0x130>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
jmp    12c0 <main+0x130>

LLVM IR (-O0):
@.str = [42 x i8] c"Usage: dat2inc <datafile> <includefile>\0A\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"Datafile open error!\0A\00"
@.str.3 = [3 x i8] c"wt\00"
@.str.4 = [25 x i8] c"Includefile open error!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [30 x i8] c"unsigned char datafile[] = {\0A\00"
@.str.6 = [3 x i8] c", \00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [7 x i8] c"0x%02x\00"
@.str.9 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %75
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %75
23: ; preds = %14
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %7
%28 = load i32*, i32** %7
%29 = icmp ne i32* %28, null
br i1 %29, label %32, label %30
30: ; preds = %23
%31 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %75
32: ; preds = %23
%33 = load i32*, i32** %6
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %6
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %8
%38 = load i32*, i32** %6
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32*, i32** %7
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %9
br label %43
43: ; preds = %65, %32
%44 = load i32, i32* %9
%45 = load i32, i32* %8
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %68
47: ; preds = %43
%48 = load i32, i32* %9
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %60
50: ; preds = %47
%51 = load i32*, i32** %7
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%53 = load i32, i32* %9
%54 = srem i32 %53, 10
%55 = icmp ne i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %50
%57 = load i32*, i32** %7
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %59
59: ; preds = %56, %50
br label %60
60: ; preds = %59, %47
%61 = load i32*, i32** %7
%62 = load i32*, i32** %6
%63 = call i32 @fgetc(i32* %62)
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %60
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %43
68: ; preds = %43
%69 = load i32*, i32** %7
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%71 = load i32*, i32** %6
%72 = call i32 @fclose(i32* %71)
%73 = load i32*, i32** %7
%74 = call i32 @fclose(i32* %73)
store i32 0, i32* %3
br label %75
75: ; preds = %68, %30, %21, %12
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wt\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [30 x i8] c"unsigned char datafile[] = {\0A\00"
@.str.6 = [3 x i8] c", \00"
@.str.8 = [7 x i8] c"0x%02x\00"
@.str.9 = [4 x i8] c"};\0A\00"
@str = [21 x i8] c"Datafile open error!\00"
@str.10 = [24 x i8] c"Includefile open error!\00"
@str.11 = [41 x i8] c"Usage: dat2inc <datafile> <includefile>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.11, i64 0, i64 0))
br label %48
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %48
13: ; preds = %6
%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.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.10, i64 0, i64 0))
br label %48
20: ; preds = %13
%21 = load i32, i32* @SEEK_END
%22 = tail call i32 @fseek(i32* %9, i32 0, i32 %21)
%23 = tail call i32 @ftell(i32* %9)
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %9, i32 0, i32 %24)
%26 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 29, i64 1, i32* %16)
%27 = icmp sgt i32 %23, 0
br i1 %27, label %28, label %44
28: ; preds = %20
%29 = tail call i32 @fgetc(i32* %9)
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %29)
%31 = icmp eq i32 %23, 1
br i1 %31, label %44, label %32
32: ; preds = %28, %39
%33 = phi i32 [ %42, %39 ], [ 1, %28 ]
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %16)
%35 = urem i32 %33, 10
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = tail call i32 @fputc(i32 10, i32* %16)
br label %39
39: ; preds = %32, %37
%40 = tail call i32 @fgetc(i32* %9)
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %40)
%42 = add nuw nsw i32 %33, 1
%43 = icmp eq i32 %42, %23
br i1 %43, label %44, label %32
44: ; preds = %39, %28, %20
%45 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i64 3, i64 1, i32* %16)
%46 = tail call i32 @fclose(i32* %9)
%47 = tail call i32 @fclose(i32* %16)
br label %48
48: ; preds = %44, %18, %11, %4
%49 = phi i32 [ 1, %4 ], [ 0, %44 ], [ 1, %18 ], [ 1, %11 ]
ret i32 %49
}