#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 */
struct stat {
  size_t st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
void *mmap(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char **argv) {
  int fd;
  void *ptr;
  size_t len;
  struct stat stats;
  if (argc != 2) {
    return -1;
  }
  if (stat(argv[1], &stats) != 0) {
    perror("load_smtpfile");
    return -1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("load_smtpfile");
    return -1;
  }
  ptr = mmap(NULL, stats.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (ptr == NULL) {
    perror("load_smtpfile");
    return -1;
  }
  len = 0;
  printf("#include <sys/types.h>\n\n");
  printf("size_t rinoo_png_size = %u;\n", (unsigned int)stats.st_size);
  printf("char rinoo_png[] = {\n        ");
  while (len < stats.st_size) {
    printf("0x%02hx", *((unsigned char *)ptr + len));
    len++;
    if (len != stats.st_size) {
      if (len % 10 == 0) {
        printf(",\n        ");
      } else {
        printf(", ");
      }
    }
  }
  printf("\n};\n");
  munmap(ptr, stats.st_size);
  close(fd);
  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   $0x2,-0x8(%rbp)
je     119c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <main+0x1ce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
je     11cf <main+0x5f>
lea    0xe42(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <main+0x1ce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120a <main+0x9a>
lea    0xe07(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <main+0x1ce>
mov    -0x30(%rbp),%rsi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    0x2db2(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1257 <main+0xe7>
lea    0xdba(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <main+0x1ce>
movq   $0x0,-0x28(%rbp)
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1314 <main+0x1a4>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     130f <main+0x19f>
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    12fc <main+0x18c>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130a <main+0x19a>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130f <main+0x19f>
jmp    128f <main+0x11f>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@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
sub    $0x18,%rsp
mov    $0xffffffff,%ebp
cmp    $0x2,%edi
jne    12e4 <main+0x164>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    12f5 <main+0x175>
mov    0x8(%rbx),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     12f5 <main+0x175>
mov    %eax,%ebx
mov    0x8(%rsp),%rsi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    0x2de9(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
test   %rax,%rax
je     12f5 <main+0x175>
mov    %rax,%r13
mov    %ebx,0x14(%rsp)
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe00(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,0x8(%rsp)
je     12c0 <main+0x140>
mov    $0x1,%ebx
lea    0xdff(%rip),%r12
xor    %r15d,%r15d
jmp    125e <main+0xde>
nop
add    $0x1,%rbx
mov    %r14,%r15
cmp    0x8(%rsp),%r14
jae    12c0 <main+0x140>
mov    %rbx,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
mov    %rdx,%rbp
movzbl 0x0(%r13,%r15,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%r15),%r14
cmp    0x8(%rsp),%r14
je     1250 <main+0xd0>
shr    $0x3,%rbp
lea    0x0(,%rbp,4),%rax
add    %rbp,%rax
add    %rax,%rax
add    $0xffffffffffffffff,%rax
cmp    %r15,%rax
lea    0xdb0(%rip),%rdi
lea    0xd9e(%rip),%rax
cmove  %rax,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1250 <main+0xd0>
lea    0xdb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rsi
mov    %r13,%rdi
call   1080 <munmap@plt>
mov    0x14(%rsp),%edi
call   1060 <close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd04(%rip),%rdi
call   10a0 <perror@plt>
jmp    12e4 <main+0x164>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [14 x i8] c"load_smtpfile\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.1 = [25 x i8] c"#include <sys/types.h>\0A\0A\00"
@.str.2 = [29 x i8] c"size_t rinoo_png_size = %u;\0A\00"
@.str.3 = [30 x i8] c"char rinoo_png[] = {\0A \00"
@.str.4 = [8 x i8] c"0x%02hx\00"
@.str.5 = [11 x i8] c",\0A \00"
@.str.6 = [3 x i8] c", \00"
@.str.7 = [5 x i8] c"\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %85
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @stat(i8* %16, %struct.stat* %9)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %85
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %85
31: ; preds = %21
%32 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%33 = load i64, i64* %32
%34 = load i32, i32* @PROT_READ
%35 = load i32, i32* @MAP_PRIVATE
%36 = load i32, i32* %6
%37 = call i8* @mmap(i32* null, i64 %33, i32 %34, i32 %35, i32 %36, i32 0)
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %31
%41 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %85
42: ; preds = %31
store i64 0, i64* %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%44 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%45 = load i64, i64* %44
%46 = trunc i64 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %76, %42
%50 = load i64, i64* %8
%51 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%52 = load i64, i64* %51
%53 = icmp ult i64 %50, %52
br i1 %53, label %54, label %77
54: ; preds = %49
%55 = load i8*, i8** %7
%56 = load i64, i64* %8
%57 = getelementptr inbounds i8, i8* %55, i64 %56
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %59)
%61 = load i64, i64* %8
%62 = add i64 %61, 1
store i64 %62, i64* %8
%63 = load i64, i64* %8
%64 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%65 = load i64, i64* %64
%66 = icmp ne i64 %63, %65
br i1 %66, label %67, label %76
67: ; preds = %54
%68 = load i64, i64* %8
%69 = urem i64 %68, 10
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %75
73: ; preds = %67
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %75
75: ; preds = %73, %71
br label %76
76: ; preds = %75, %54
br label %49
77: ; preds = %49
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%79 = load i8*, i8** %7
%80 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%81 = load i64, i64* %80
%82 = call i32 @munmap(i8* %79, i64 %81)
%83 = load i32, i32* %6
%84 = call i32 @close(i32 %83)
store i32 0, i32* %3
br label %85
85: ; preds = %77, %40, %29, %19, %12
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [14 x i8] c"load_smtpfile\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [29 x i8] c"size_t rinoo_png_size = %u;\0A\00"
@.str.3 = [30 x i8] c"char rinoo_png[] = {\0A \00"
@.str.4 = [8 x i8] c"0x%02hx\00"
@.str.5 = [11 x i8] c",\0A \00"
@.str.6 = [3 x i8] c", \00"
@str = [24 x i8] c"#include <sys/types.h>\0A\00"
@str.8 = [4 x i8] c"\0A};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %59
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i64 @stat(i8* %8, %struct.stat* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %59
13: ; preds = %6
%14 = load i8*, i8** %7
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %59
20: ; preds = %13
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%22 = load i64, i64* %21
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @MAP_PRIVATE
%25 = call i8* @mmap(i32* null, i64 %22, i32 %23, i32 %24, i32 %16, i32 0)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %59
29: ; preds = %20
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%31 = load i64, i64* %21
%32 = trunc i64 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%35 = load i64, i64* %21
%36 = icmp eq i64 %35, 0
br i1 %36, label %54, label %37
37: ; preds = %29, %51
%38 = phi i64 [ %43, %51 ], [ 0, %29 ]
%39 = getelementptr inbounds i8, i8* %25, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = add nuw i64 %38, 1
%44 = load i64, i64* %21
%45 = icmp eq i64 %43, %44
br i1 %45, label %51, label %46
46: ; preds = %37
%47 = urem i64 %43, 10
%48 = icmp eq i64 %47, 0
%49 = select i1 %48, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %49)
br label %51
51: ; preds = %46, %37
%52 = load i64, i64* %21
%53 = icmp ult i64 %43, %52
br i1 %53, label %37, label %54
54: ; preds = %51, %29
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0))
%56 = load i64, i64* %21
%57 = call i32 @munmap(i8* %25, i64 %56)
%58 = call i32 @close(i32 %16)
br label %59
59: ; preds = %2, %54, %27, %18, %11
%60 = phi i32 [ -1, %11 ], [ -1, %18 ], [ -1, %27 ], [ 0, %54 ], [ -1, %2 ]
ret i32 %60
}