#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *basename(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strdup(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("not enough arguments\n");
    return 1;
  }
  FILE *fp_h = fopen(argv[1], "w");
  if (!fp_h) {
    printf("can't open %s\n", argv[1]);
    return 2;
  }
  FILE *fp_c = fopen(argv[2], "w");
  if (!fp_c) {
    fclose(fp_h);
    printf("can't open %s\n", argv[2]);
    return 2;
  }
  fprintf(fp_h, "// generated file, all changes will be lost\n"
                "#ifndef FPP_GENERATED_IMG_RESOURCES_H\n"
                "#define FPP_GENERATED_IMG_RESOURCES_H\n"
                "\n"
                "#include <stddef.h>\n"
                "\n"
                "struct resource_image_s {\n"
                "    const char *name;\n"
                "    size_t      len;\n"
                "    const char *data;\n"
                "};\n"
                "\n"
                "extern struct resource_image_s resource_image[];\n"
                "extern size_t resource_image_count;\n"
                "\n"
                "#endif\n");
  fclose(fp_h);
  fprintf(fp_c,
          "// generated file, all changes will be lost\n"
          "#include \"%s\"\n"
          "\n",
          argv[1]);
  fprintf(fp_c, "size_t resource_image_count = %d;\n", argc - 3);
  fprintf(fp_c, "struct resource_image_s resource_image[] = {\n");
  for (int k = 3; k < argc; k++) {
    unsigned char buf[4096];
    char *fname = strdup(argv[k]);
    char *bname = basename(fname);
    fprintf(fp_c, "{   .name = \"%s\",\n", bname);
    fprintf(fp_c, "    .data = \"");
    size_t fsize = 0;
    FILE *tmp = fopen(fname, "rb");
    if (!tmp) {
      printf("can't open %s\n", fname);
      free(fname);
      goto err_1;
    }
    while (!feof(tmp)) {
      size_t read_bytes = fread(buf, 1, sizeof(buf), tmp);
      for (size_t j = 0; j < read_bytes; j++)
        fprintf(fp_c, "\\x%02x", buf[j]);
      fsize += read_bytes;
    }
    fclose(tmp);
    fprintf(fp_c, "\",\n");
    fprintf(fp_c, "    .len = %u\n", (unsigned int)fsize);
    fprintf(fp_c, "},\n");
    free(fname);
  }
  fprintf(fp_c, "};\n");
  fclose(fp_c);
  return 0;
err_1:
  fclose(fp_c);
  return 3;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11cd <main+0x3d>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14d8 <main+0x348>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1212 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14d8 <main+0x348>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf5(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1260 <main+0xd0>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14d8 <main+0x348>
mov    -0x18(%rbp),%rdi
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xee4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x3,%edx
lea    0xf08(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xf19(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x3,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14a1 <main+0x311>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x1038(%rbp)
mov    -0x1038(%rbp),%rdi
call   1080 <basename@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x1040(%rbp),%rdx
lea    0xef0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xef1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x1048(%rbp)
mov    -0x1038(%rbp),%rdi
lea    0xedf(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1050(%rbp)
cmpq   $0x0,-0x1050(%rbp)
jne    1381 <main+0x1f1>
mov    -0x1038(%rbp),%rsi
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1038(%rbp),%rdi
call   1030 <free@plt>
jmp    14c8 <main+0x338>
jmp    1386 <main+0x1f6>
mov    -0x1050(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13a7 <main+0x217>
jmp    143c <main+0x2ac>
lea    -0x1030(%rbp),%rdi
mov    -0x1050(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
mov    %rax,-0x1058(%rbp)
movq   $0x0,-0x1060(%rbp)
mov    -0x1060(%rbp),%rax
cmp    -0x1058(%rbp),%rax
jae    1422 <main+0x292>
mov    -0x20(%rbp),%rdi
mov    -0x1060(%rbp),%rax
movzbl -0x1030(%rbp,%rax,1),%edx
ff
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x1060(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1060(%rbp)
jmp    13d6 <main+0x246>
mov    -0x1058(%rbp),%rax
add    -0x1048(%rbp),%rax
mov    %rax,-0x1048(%rbp)
jmp    1386 <main+0x1f6>
mov    -0x1050(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x1048(%rbp),%rax
mov    %eax,%edx
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x1038(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12c6 <main+0x136>
mov    -0x20(%rbp),%rdi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    14d8 <main+0x348>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
cmp    $0x2,%edi
jg     11dc <main+0x2c>
lea    0x105e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1448 <main+0x298>
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x8(%rsi),%rdi
lea    0xe13(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13fe <main+0x24e>
mov    %rax,%rbp
mov    0x10(%r15),%rdi
lea    0xdf7(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1429 <main+0x279>
mov    %rax,%rbx
lea    0xdf0(%rip),%rdi
mov    $0x14a,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10c0 <fwrite@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x8(%r15),%rdx
lea    0xf16(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    -0x3(%r14),%edx
lea    0xf3d(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xf4f(%rip),%rdi
mov    $0x2d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
cmp    $0x4,%r14d
jb     1404 <main+0x254>
mov    %r14d,%eax
mov    %rax,(%rsp)
mov    $0x3,%r14d
lea    0xf71(%rip),%r12
mov    %r15,0x8(%rsp)
jmp    1320 <main+0x170>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xf2f(%rip),%rdi
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
lea    0xf39(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xf2d(%rip),%rdi
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%r14
add    $0x1,%r14
cmp    (%rsp),%r14
mov    0x8(%rsp),%r15
je     1404 <main+0x254>
mov    (%r15,%r14,8),%rdi
call   10d0 <strdup@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1090 <basename@plt>
mov    %rbx,%rdi
lea    0xeab(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xd,%esi
mov    $0x1,%edx
lea    0xea3(%rip),%rdi
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    %r13,%rdi
lea    0xe9f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     145a <main+0x2aa>
mov    %rax,%rbp
mov    %r13,0x10(%rsp)
mov    %r14,0x18(%rsp)
mov    %rax,%rdi
call   10a0 <feof@plt>
xor    %r14d,%r14d
jmp    13ab <main+0x1fb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %r15,%r14
mov    %rbp,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    12b0 <main+0x100>
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rax,%r15
test   %rax,%rax
je     13a0 <main+0x1f0>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x20(%rsp,%r13,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    13e0 <main+0x230>
jmp    13a0 <main+0x1f0>
mov    0x8(%r15),%rsi
jmp    1435 <main+0x285>
lea    0xe1c(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    1448 <main+0x298>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x10(%r15),%rsi
lea    0xbc6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xba1(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0x3,%eax
jmp    1448 <main+0x298>

LLVM IR (-O0):
@.str = [22 x i8] c"not enough arguments\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"can't open %s\0A\00"
@.str.3 = [331 x i8] c"// generated file, all changes will be lost\0A#ifndef FPP_GENERATED_IMG_RESOURCES_H\0A#define FPP_GENERATED_IMG_RESOURCES_H\0A\0A#include <stddef.h>\0A\0Astruct resource_image_s {\0A const char *name;\0A size_t len;\0A const char *data;\0A};\0A\0Aextern struct resource_image_s resource_image[];\0Aextern size_t resource_image_count;\0A\0A#endif\0A\00"
@.str.4 = [60 x i8] c"// generated file, all changes will be lost\0A#include \22%s\22\0A\0A\00"
@.str.5 = [35 x i8] c"size_t resource_image_count = %d;\0A\00"
@.str.6 = [46 x i8] c"struct resource_image_s resource_image[] = {\0A\00"
@.str.7 = [19 x i8] c"{ .name = \22%s\22,\0A\00"
@.str.8 = [14 x i8] c" .data = \22\00"
@.str.9 = [3 x i8] c"rb\00"
@.str.10 = [7 x i8] c"\\x%02x\00"
@.str.11 = [4 x i8] c"\22,\0A\00"
@.str.12 = [15 x i8] c" .len = %u\0A\00"
@.str.13 = [4 x i8] c"},\0A\00"
@.str.14 = [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 [4096 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i64
%15 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %141
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %32, label %27
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 2, i32* %3
br label %141
32: ; preds = %20
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp ne i32* %37, null
br i1 %38, label %46, label %39
39: ; preds = %32
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %44)
store i32 2, i32* %3
br label %141
46: ; preds = %32
%47 = load i32*, i32** %6
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([331 x i8], [331 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %7
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = load i32*, i32** %7
%57 = load i32, i32* %4
%58 = sub nsw i32 %57, 3
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = load i32*, i32** %7
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
store i32 3, i32* %8
br label %62
62: ; preds = %130, %46
%63 = load i32, i32* %8
%64 = load i32, i32* %4
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %133
66: ; preds = %62
%67 = load i8**, i8*** %5
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i8* @strdup(i8* %71)
store i8* %72, i8** %10
%73 = load i8*, i8** %10
%74 = call i8* @basename(i8* %73)
store i8* %74, i8** %11
%75 = load i32*, i32** %7
%76 = load i8*, i8** %11
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %76)
%78 = load i32*, i32** %7
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i64 0, i64* %12
%80 = load i8*, i8** %10
%81 = call i32* @fopen(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %81, i32** %13
%82 = load i32*, i32** %13
%83 = icmp ne i32* %82, null
br i1 %83, label %89, label %84
84: ; preds = %66
%85 = load i8*, i8** %10
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %85)
%87 = load i8*, i8** %10
%88 = call i32 @free(i8* %87)
br label %138
89: ; preds = %66
br label %90
90: ; preds = %113, %89
%91 = load i32*, i32** %13
%92 = call i32 @feof(i32* %91)
%93 = icmp ne i32 %92, 0
%94 = xor i1 %93, true
br i1 %94, label %95, label %117
95: ; preds = %90
%96 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%97 = load i32*, i32** %13
%98 = call i64 @fread(i8* %96, i32 1, i32 4096, i32* %97)
store i64 %98, i64* %14
store i64 0, i64* %15
br label %99
99: ; preds = %110, %95
%100 = load i64, i64* %15
%101 = load i64, i64* %14
%102 = icmp ult i64 %100, %101
br i1 %102, label %103, label %113
103: ; preds = %99
%104 = load i32*, i32** %7
%105 = load i64, i64* %15
%106 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %105
%107 = load i8, i8* %106
%108 = zext i8 %107 to i32
%109 = call i32 (i32*, i8*, ...) @fprintf(i32* %104, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %108)
br label %110
110: ; preds = %103
%111 = load i64, i64* %15
%112 = add i64 %111, 1
store i64 %112, i64* %15
br label %99
113: ; preds = %99
%114 = load i64, i64* %14
%115 = load i64, i64* %12
%116 = add i64 %115, %114
store i64 %116, i64* %12
br label %90
117: ; preds = %90
%118 = load i32*, i32** %13
%119 = call i32 @fclose(i32* %118)
%120 = load i32*, i32** %7
%121 = call i32 (i32*, i8*, ...) @fprintf(i32* %120, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%122 = load i32*, i32** %7
%123 = load i64, i64* %12
%124 = trunc i64 %123 to i32
%125 = call i32 (i32*, i8*, ...) @fprintf(i32* %122, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %124)
%126 = load i32*, i32** %7
%127 = call i32 (i32*, i8*, ...) @fprintf(i32* %126, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0))
%128 = load i8*, i8** %10
%129 = call i32 @free(i8* %128)
br label %130
130: ; preds = %117
%131 = load i32, i32* %8
%132 = add nsw i32 %131, 1
store i32 %132, i32* %8
br label %62
133: ; preds = %62
%134 = load i32*, i32** %7
%135 = call i32 (i32*, i8*, ...) @fprintf(i32* %134, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0))
%136 = load i32*, i32** %7
%137 = call i32 @fclose(i32* %136)
store i32 0, i32* %3
br label %141
138: ; preds = %84
%139 = load i32*, i32** %7
%140 = call i32 @fclose(i32* %139)
store i32 3, i32* %3
br label %141
141: ; preds = %138, %133, %39, %27, %18
%142 = load i32, i32* %3
ret i32 %142
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"can't open %s\0A\00"
@.str.3 = [331 x i8] c"// generated file, all changes will be lost\0A#ifndef FPP_GENERATED_IMG_RESOURCES_H\0A#define FPP_GENERATED_IMG_RESOURCES_H\0A\0A#include <stddef.h>\0A\0Astruct resource_image_s {\0A const char *name;\0A size_t len;\0A const char *data;\0A};\0A\0Aextern struct resource_image_s resource_image[];\0Aextern size_t resource_image_count;\0A\0A#endif\0A\00"
@.str.4 = [60 x i8] c"// generated file, all changes will be lost\0A#include \22%s\22\0A\0A\00"
@.str.5 = [35 x i8] c"size_t resource_image_count = %d;\0A\00"
@.str.6 = [46 x i8] c"struct resource_image_s resource_image[] = {\0A\00"
@.str.7 = [19 x i8] c"{ .name = \22%s\22,\0A\00"
@.str.8 = [14 x i8] c" .data = \22\00"
@.str.9 = [3 x i8] c"rb\00"
@.str.10 = [7 x i8] c"\\x%02x\00"
@.str.11 = [4 x i8] c"\22,\0A\00"
@.str.12 = [15 x i8] c" .len = %u\0A\00"
@.str.13 = [4 x i8] c"},\0A\00"
@.str.14 = [4 x i8] c"};\0A\00"
@str = [21 x i8] c"not enough arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %82
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %82
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = tail call i32 @fclose(i32* %10)
%22 = load i8*, i8** %16
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %82
24: ; preds = %15
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([331 x i8], [331 x i8]* @.str.3, i64 0, i64 0), i64 330, i64 1, i32* %10)
%26 = tail call i32 @fclose(i32* %10)
%27 = load i8*, i8** %8
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = add nsw i32 %0, -3
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i64 45, i64 1, i32* %18)
%32 = icmp ugt i32 %0, 3
br i1 %32, label %33, label %75
33: ; preds = %24
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%35 = zext i32 %0 to i64
br label %46
36: ; preds = %63, %56
%37 = phi i64 [ 0, %56 ], [ %64, %63 ]
%38 = tail call i32 @fclose(i32* %54)
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i64 3, i64 1, i32* %18)
%40 = trunc i64 %37 to i32
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %40)
%42 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i64 3, i64 1, i32* %18)
%43 = tail call i32 @free(i8* %50)
%44 = add nuw nsw i64 %47, 1
%45 = icmp eq i64 %44, %35
br i1 %45, label %75, label %46
46: ; preds = %33, %36
%47 = phi i64 [ 3, %33 ], [ %44, %36 ]
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = tail call i8* @strdup(i8* %49)
%51 = tail call i8* @basename(i8* %50)
%52 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %51)
%53 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 13, i64 1, i32* %18)
%54 = tail call i32* @fopen(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%55 = icmp eq i32* %54, null
br i1 %55, label %78, label %56
56: ; preds = %46
%57 = tail call i32 @feof(i32* %54)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %36
59: ; preds = %56, %63
%60 = phi i64 [ %64, %63 ], [ 0, %56 ]
%61 = call i64 @fread(i8* %34, i32 1, i32 4096, i32* %54)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %67, %59
%64 = add i64 %61, %60
%65 = tail call i32 @feof(i32* %54)
%66 = icmp eq i32 %65, 0
br i1 %66, label %59, label %36
67: ; preds = %59, %67
%68 = phi i64 [ %73, %67 ], [ 0, %59 ]
%69 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %71)
%73 = add nuw i64 %68, 1
%74 = icmp eq i64 %73, %61
br i1 %74, label %63, label %67
75: ; preds = %36, %24
%76 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i64 3, i64 1, i32* %18)
%77 = tail call i32 @fclose(i32* %18)
br label %82
78: ; preds = %46
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%80 = tail call i32 @free(i8* %50)
%81 = tail call i32 @fclose(i32* %18)
br label %82
82: ; preds = %12, %78, %75, %20, %5
%83 = phi i32 [ 1, %5 ], [ 2, %12 ], [ 3, %78 ], [ 0, %75 ], [ 2, %20 ]
ret i32 %83
}