#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  const char *filename;
  FILE *in_fp;
  FILE *out_fp;
  int ch;
  int width;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <file>\n", argv[0]);
    return EXIT_FAILURE;
  }
  filename = argv[1];
  in_fp = fopen(filename, "r");
  out_fp = stdout;
  if (in_fp == NULL || out_fp == NULL) {
    fprintf(stderr, "failed to open %s\n", in_fp ? "app.c" : filename);
    return EXIT_FAILURE;
    ;
  }
  fprintf(out_fp,
          "/* Application bytecode compiled from the source file %s. */\n",
          filename);
  fprintf(out_fp, "static const uint8_t vm_program[] = {\n");
  width = 0;
  while ((ch = fgetc(in_fp)) != EOF) {
    if (ferror(in_fp) || ferror(out_fp)) {
      goto io_error;
    }
    if (width == 10) {
      fprintf(out_fp, ",\n");
      width = 0;
    } else if (width > 0) {
      fprintf(out_fp, ", ");
    }
    width++;
    fprintf(out_fp, "0x%02x", ch);
  }
  fprintf(out_fp, "};\n");
  if (ferror(out_fp)) {
    goto io_error;
  }
  fclose(in_fp);
  fclose(out_fp);
  return EXIT_SUCCESS;
io_error:
  fprintf(stderr, "Failed to create an array of a VM program: I/O error\n");
  return EXIT_FAILURE;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     11a0 <main+0x50>
mov    0x2e61(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138e <main+0x23e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e4 <main+0x94>
cmpq   $0x0,-0x28(%rbp)
jne    123c <main+0xec>
mov    0x2ded(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120d <main+0xbd>
lea    0xe23(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    1215 <main+0xc5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138e <main+0x23e>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d6a(%rip),%rcx
cmp    (%rcx),%eax
je     131d <main+0x1cd>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    12ac <main+0x15c>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12b1 <main+0x161>
jmp    136a <main+0x21a>
cmpl   $0xa,-0x30(%rbp)
jne    12d9 <main+0x189>
mov    -0x28(%rbp),%rdi
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
jmp    12fa <main+0x1aa>
cmpl   $0x0,-0x30(%rbp)
jle    12f5 <main+0x1a5>
mov    -0x28(%rbp),%rdi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12fa <main+0x1aa>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    126b <main+0x11b>
mov    -0x28(%rbp),%rdi
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1347 <main+0x1f7>
jmp    136a <main+0x21a>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138e <main+0x23e>
mov    0x2c67(%rip),%rax
mov    (%rax),%rdi
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-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    1238 <main+0xd8>
mov    0x8(%rsi),%rbp
lea    0xe93(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     124e <main+0xee>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
je     124e <main+0xee>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x26,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e06(%rip),%r12
cmp    (%r12),%eax
jne    128c <main+0x12c>
lea    0xeac(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1327 <main+0x1c7>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rcx
lea    0xe7c(%rip),%rdi
mov    $0x35,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
jmp    1274 <main+0x114>
mov    0x2d99(%rip),%rax
mov    (%rax),%rdi
mov    (%rsi),%rdx
lea    0xdb4(%rip),%rsi
jmp    126d <main+0x10d>
test   %r14,%r14
mov    0x2d80(%rip),%rax
mov    (%rax),%rdi
lea    0xdc5(%rip),%rdx
cmove  %rbp,%rdx
lea    0xda7(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
xor    %r13d,%r13d
jmp    12e0 <main+0x180>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r15d,%r13d
add    $0x1,%r13d
mov    %rbx,%rdi
lea    0xdd5(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
je     11ec <main+0x8c>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1216 <main+0xb6>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1216 <main+0xb6>
xor    %r15d,%r15d
lea    0xd86(%rip),%rdi
cmp    $0xa,%r13d
je     12a0 <main+0x140>
lea    0xd7c(%rip),%rdi
mov    %r13d,%r15d
test   %r13d,%r13d
jg     12a0 <main+0x140>
jmp    12b5 <main+0x155>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2c82(%rip),%rax
jmp    127b <main+0x11b>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.2 = [19 x i8] c"failed to open %s\0A\00"
@.str.3 = [6 x i8] c"app.c\00"
@.str.4 = [62 x i8] c"/* Application bytecode compiled from the source file %s. */\0A\00"
@.str.5 = [39 x i8] c"static const uint8_t vm_program[] = {\0A\00"
@EOF = global i32 0
@.str.6 = [3 x i8] c",\0A\00"
@.str.7 = [3 x i8] c", \00"
@.str.8 = [7 x i8] c"0x%02x\00"
@.str.9 = [4 x i8] c"};\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.10 = [54 x i8] c"Failed to create an array of a VM program: I/O error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32*, i32** @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %99
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i32*, i32** @stdout
store i32* %26, i32** %8
%27 = load i32*, i32** %7
%28 = icmp eq i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %20
%30 = load i32*, i32** %8
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %43
32: ; preds = %29, %20
%33 = load i32*, i32** @stderr
%34 = load i32*, i32** %7
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %37
36: ; preds = %32
br label %39
37: ; preds = %32
%38 = load i8*, i8** %6
br label %39
39: ; preds = %37, %36
%40 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %36 ], [ %38, %37 ]
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %3
br label %99
43: ; preds = %29
%44 = load i32*, i32** %8
%45 = load i8*, i8** %6
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %8
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %10
br label %49
49: ; preds = %76, %43
%50 = load i32*, i32** %7
%51 = call i32 @fgetc(i32* %50)
store i32 %51, i32* %9
%52 = load i32, i32* @EOF
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %82
54: ; preds = %49
%55 = load i32*, i32** %7
%56 = call i64 @ferror(i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %54
%59 = load i32*, i32** %8
%60 = call i64 @ferror(i32* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %58, %54
br label %95
63: ; preds = %58
%64 = load i32, i32* %10
%65 = icmp eq i32 %64, 10
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i32*, i32** %8
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %10
br label %76
69: ; preds = %63
%70 = load i32, i32* %10
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = load i32*, i32** %8
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %75
75: ; preds = %72, %69
br label %76
76: ; preds = %75, %66
%77 = load i32, i32* %10
%78 = add nsw i32 %77, 1
store i32 %78, i32* %10
%79 = load i32*, i32** %8
%80 = load i32, i32* %9
%81 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %80)
br label %49
82: ; preds = %49
%83 = load i32*, i32** %8
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%85 = load i32*, i32** %8
%86 = call i64 @ferror(i32* %85)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %89
88: ; preds = %82
br label %95
89: ; preds = %82
%90 = load i32*, i32** %7
%91 = call i32 @fclose(i32* %90)
%92 = load i32*, i32** %8
%93 = call i32 @fclose(i32* %92)
%94 = load i32, i32* @EXIT_SUCCESS
store i32 %94, i32* %3
br label %99
95: ; preds = %88, %62
%96 = load i32*, i32** @stderr
%97 = call i32 (i32*, i8*, ...) @fprintf(i32* %96, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.10, i64 0, i64 0))
%98 = load i32, i32* @EXIT_FAILURE
store i32 %98, i32* %3
br label %99
99: ; preds = %95, %89, %39, %13
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.2 = [19 x i8] c"failed to open %s\0A\00"
@.str.3 = [6 x i8] c"app.c\00"
@.str.4 = [62 x i8] c"/* Application bytecode compiled from the source file %s. */\0A\00"
@.str.5 = [39 x i8] c"static const uint8_t vm_program[] = {\0A\00"
@EOF = global i32 0
@.str.6 = [3 x i8] c",\0A\00"
@.str.7 = [3 x i8] c", \00"
@.str.8 = [7 x i8] c"0x%02x\00"
@.str.9 = [4 x i8] c"};\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.10 = [54 x i8] c"Failed to create an array of a VM program: I/O error\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %59
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32*, i32** @stdout
%13 = icmp eq i32* %11, null
%14 = icmp eq i32* %12, null
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = load i32*, i32** @stderr
%18 = select i1 %13, i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %59
20: ; preds = %8
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i64 38, i64 1, i32* %12)
%23 = tail call i32 @fgetc(i32* %11)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %49, label %26
26: ; preds = %20, %42
%27 = phi i32 [ %46, %42 ], [ %23, %20 ]
%28 = phi i32 [ %44, %42 ], [ 0, %20 ]
%29 = tail call i64 @ferror(i32* %11)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %56
31: ; preds = %26
%32 = tail call i64 @ferror(i32* %12)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %56
34: ; preds = %31
%35 = icmp eq i32 %28, 10
br i1 %35, label %38, label %36
36: ; preds = %34
%37 = icmp sgt i32 %28, 0
br i1 %37, label %38, label %42
38: ; preds = %36, %34
%39 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %34 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), %36 ]
%40 = phi i32 [ 0, %34 ], [ %28, %36 ]
%41 = tail call i64 @fwrite(i8* %39, i64 2, i64 1, i32* %12)
br label %42
42: ; preds = %38, %36
%43 = phi i32 [ %28, %36 ], [ %40, %38 ]
%44 = add nsw i32 %43, 1
%45 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %27)
%46 = tail call i32 @fgetc(i32* %11)
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %26
49: ; preds = %42, %20
%50 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i64 3, i64 1, i32* %12)
%51 = tail call i64 @ferror(i32* %12)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = tail call i32 @fclose(i32* %11)
%55 = tail call i32 @fclose(i32* %12)
br label %59
56: ; preds = %26, %31, %49
%57 = load i32*, i32** @stderr
%58 = tail call i64 @fwrite(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.10, i64 0, i64 0), i64 53, i64 1, i32* %57)
br label %59
59: ; preds = %56, %53, %16, %4
%60 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %16 ], [ @EXIT_FAILURE, %56 ], [ @EXIT_SUCCESS, %53 ]
%61 = load i32, i32* %60
ret i32 %61
}