#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");
    fclose(in);
    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    1325 <main+0x1b5>
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    1325 <main+0x1b5>
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    1227 <main+0xb7>
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1325 <main+0x1b5>
mov    -0x18(%rbp),%rdi
mov    0x2db6(%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    0x2d86(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12fa <main+0x18a>
cmpl   $0x0,-0x28(%rbp)
je     12c7 <main+0x157>
mov    -0x20(%rbp),%rdi
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12c2 <main+0x152>
mov    -0x20(%rbp),%rdi
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12c7 <main+0x157>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1274 <main+0x104>
mov    -0x20(%rbp),%rdi
lea    0xd82(%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    1288 <main+0xf8>
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     12a1 <main+0x111>
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    12b7 <main+0x127>
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    1292 <main+0x102>
lea    0xdaa(%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
lea    0xd9f(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    128d <main+0xfd>
add    $0xffffffff,%ebx
mov    $0x1,%r12d
mov    $0xffffffff,%r14d
jmp    12fc <main+0x16c>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %rbp,%rdi
lea    0xd45(%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    0xd00(%rip),%rdi
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
add    %r14d,%r13d
jne    12d0 <main+0x140>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
jmp    12d0 <main+0x140>

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 %77
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 %77
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 %34, label %30
30: ; preds = %23
%31 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
store i32 1, i32* %3
br label %77
34: ; preds = %23
%35 = load i32*, i32** %6
%36 = load i32, i32* @SEEK_END
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %6
%39 = call i32 @ftell(i32* %38)
store i32 %39, i32* %8
%40 = load i32*, i32** %6
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @fseek(i32* %40, i32 0, i32 %41)
%43 = load i32*, i32** %7
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %9
br label %45
45: ; preds = %67, %34
%46 = load i32, i32* %9
%47 = load i32, i32* %8
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %70
49: ; preds = %45
%50 = load i32, i32* %9
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %62
52: ; preds = %49
%53 = load i32*, i32** %7
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%55 = load i32, i32* %9
%56 = srem i32 %55, 10
%57 = icmp ne i32 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %52
%59 = load i32*, i32** %7
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %61
61: ; preds = %58, %52
br label %62
62: ; preds = %61, %49
%63 = load i32*, i32** %7
%64 = load i32*, i32** %6
%65 = call i32 @fgetc(i32* %64)
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %62
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %45
70: ; preds = %45
%71 = load i32*, i32** %7
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
store i32 0, i32* %3
br label %77
77: ; preds = %70, %30, %21, %12
%78 = load i32, i32* %3
ret i32 %78
}

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 %49
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 %49
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 %21
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))
%20 = tail call i32 @fclose(i32* %9)
br label %49
21: ; preds = %13
%22 = load i32, i32* @SEEK_END
%23 = tail call i32 @fseek(i32* %9, i32 0, i32 %22)
%24 = tail call i32 @ftell(i32* %9)
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %9, i32 0, i32 %25)
%27 = 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)
%28 = icmp sgt i32 %24, 0
br i1 %28, label %29, label %45
29: ; preds = %21
%30 = tail call i32 @fgetc(i32* %9)
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %30)
%32 = icmp eq i32 %24, 1
br i1 %32, label %45, label %33
33: ; preds = %29, %40
%34 = phi i32 [ %43, %40 ], [ 1, %29 ]
%35 = 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)
%36 = urem i32 %34, 10
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = tail call i32 @fputc(i32 10, i32* %16)
br label %40
40: ; preds = %33, %38
%41 = tail call i32 @fgetc(i32* %9)
%42 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i32 %34, 1
%44 = icmp eq i32 %43, %24
br i1 %44, label %45, label %33
45: ; preds = %40, %29, %21
%46 = 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)
%47 = tail call i32 @fclose(i32* %9)
%48 = tail call i32 @fclose(i32* %16)
br label %49
49: ; preds = %45, %18, %11, %4
%50 = phi i32 [ 1, %4 ], [ 0, %45 ], [ 1, %18 ], [ 1, %11 ]
ret i32 %50
}