#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  FILE *fp = NULL;
  FILE *header_fp = NULL;
  int c;
  int ret = 1;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s SOURCE_IMAGE noimage.h\n", argv[0]);
    ret = 1;
    goto end;
  }
  const char *noimage_file = argv[1];
  const char *noimage_header = argv[2];
  if ((fp = fopen(noimage_file, "r")) == NULL) {
    fprintf(stderr, "Failed to open %s - %s\n", noimage_file, strerror(errno));
    ret = 1;
    goto end;
  }
  if ((header_fp = fopen(noimage_header, "w")) == NULL) {
    fprintf(stderr, "Failed to open %s - %s\n", noimage_header,
            strerror(errno));
    ret = 1;
    goto end;
  }
  fprintf(header_fp, "#ifndef __NOIMAGE_H__\n");
  fprintf(header_fp, "#define __NOIMAGE_H__\n");
  fprintf(header_fp, "\n");
  fprintf(header_fp, "const unsigned char noimage_data[] = {");
  c = fgetc(fp);
  if (c != EOF) {
    fprintf(header_fp, "%d", c);
    while ((c = fgetc(fp)) != EOF) {
      fprintf(header_fp, ",%d", c);
    }
  }
  fprintf(header_fp, "};\n\n");
  fprintf(header_fp, "#endif\n");
  ret = 0;
end:
  if (fp) {
    fclose(fp);
  }
  if (header_fp) {
    fclose(header_fp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b2 <main+0x62>
mov    0x2e4a(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    1378 <main+0x228>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1231 <main+0xe1>
mov    0x2de9(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    1378 <main+0x228>
mov    -0x38(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1298 <main+0x148>
mov    0x2d82(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    1378 <main+0x228>
mov    -0x20(%rbp),%rdi
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2cf2(%rip),%rcx
cmp    (%rcx),%eax
je     134d <main+0x1fd>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2cc2(%rip),%rcx
cmp    (%rcx),%eax
je     1348 <main+0x1f8>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1313 <main+0x1c3>
jmp    134d <main+0x1fd>
mov    -0x20(%rbp),%rdi
lea    0xd3f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xd32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     138c <main+0x23c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     13a0 <main+0x250>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    12ce <main+0x15e>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r15
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     12eb <main+0x17b>
mov    %rax,%r14
lea    0xe92(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     131c <main+0x1ac>
mov    %rax,%rbx
lea    0xe79(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe77(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
lea    0xe68(%rip),%rdi
mov    $0x26,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2dc3(%rip),%rbp
cmp    0x0(%rbp),%eax
je     127c <main+0x10c>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%rbp),%eax
je     127c <main+0x10c>
lea    0xe42(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%rbp),%eax
jne    1260 <main+0xf0>
lea    0xe14(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe00(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
je     1358 <main+0x1e8>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1358 <main+0x1e8>
mov    0x2d03(%rip),%rax
movslq (%rax),%rdi
mov    (%rsi),%rdx
lea    0xd1e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1353 <main+0x1e3>
mov    0x2ce6(%rip),%rax
movslq (%rax),%rbp
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd1a(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1353 <main+0x1e3>
mov    0x2cb5(%rip),%rax
movslq (%rax),%rbx
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xce9(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: %s SOURCE_IMAGE noimage.h\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Failed to open %s - %s\0A\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [23 x i8] c"#ifndef __NOIMAGE_H__\0A\00"
@.str.5 = [23 x i8] c"#define __NOIMAGE_H__\0A\00"
@.str.7 = [39 x i8] c"const unsigned char noimage_data[] = {\00"
@EOF = global i32 0
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [4 x i8] c",%d\00"
@.str.10 = [5 x i8] c"};\0A\0A\00"
@.str.11 = [8 x i8] c"#endif\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = load i8*, i8** %1
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %60
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %12, i8* %22)
br label %60
24: ; preds = %10
%25 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %14, i8* %32)
%34 = tail call i32 @fclose(i32* %15)
br label %60
35: ; preds = %24
%36 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i64 22, i64 1, i32* %25)
%37 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 22, i64 1, i32* %25)
%38 = tail call i32 @fputc(i32 10, i32* %25)
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i64 38, i64 1, i32* %25)
%40 = tail call i32 @fgetc(i32* %15)
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %54, label %43
43: ; preds = %35
%44 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %40)
%45 = tail call i32 @fgetc(i32* %15)
%46 = load i32, i32* @EOF
%47 = icmp eq i32 %45, %46
br i1 %47, label %54, label %48
48: ; preds = %43, %48
%49 = phi i32 [ %51, %48 ], [ %45, %43 ]
%50 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %49)
%51 = tail call i32 @fgetc(i32* %15)
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %48
54: ; preds = %48, %35, %43
%55 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i64 4, i64 1, i32* %25)
%56 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i64 7, i64 1, i32* %25)
%57 = tail call i32 @fclose(i32* %15)
br i1 %26, label %60, label %58
58: ; preds = %54
%59 = tail call i32 @fclose(i32* %25)
br label %60
60: ; preds = %27, %4, %17, %58, %54
%61 = phi i32 [ 0, %58 ], [ 0, %54 ], [ 1, %17 ], [ 1, %4 ], [ 1, %27 ]
ret i32 %61
}