#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 */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
int main(int argc, char **argv) {
  FILE *infp, *outfp;
  if (argc < 3) {
    fprintf(stderr, "Syntax: %s <in-file> <out-file>\n", argv[0]);
    return EXIT_FAILURE;
  }
  infp = fopen(argv[1], "r");
  if (!infp) {
    perror("fopen");
    return EXIT_FAILURE;
  }
  outfp = fopen(argv[2], "w");
  if (!outfp) {
    fclose(infp);
    perror("fopen");
    return EXIT_FAILURE;
  }
  fprintf(outfp,
          "/* This file has been automatically generated\n"
          "   from the input file \"%s\". */\n\n",
          argv[1]);
  fputs("#include \"config/configfragment.hpp\"\n\nnamespace {\n\nconst char "
        "*fragment = R\"CONFIG_FRAGMENT(",
        outfp);
  while (!feof(infp)) {
    char buf[1024];
    size_t rc = fread(buf, 1, sizeof(buf), infp);
    if (rc == 0)
      break;
    fwrite(buf, rc, 1, outfp);
  }
  fprintf(
      outfp,
      ")CONFIG_FRAGMENT\";\n\nREGISTER_CONFIG_FRAGMENT(\"%s\", fragment);\n\n}",
      argv[1]);
  fclose(outfp);
  fclose(infp);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11d1 <main+0x51>
mov    0x2e36(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe45(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132b <main+0x1ab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1211 <main+0x91>
lea    0xe28(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132b <main+0x1ab>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe09(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    125a <main+0xda>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xddf(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132b <main+0x1ab>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdbe(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdfe(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12a0 <main+0x120>
jmp    12f5 <main+0x175>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    12d4 <main+0x154>
jmp    12f5 <main+0x175>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
jmp    1282 <main+0x102>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd0(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jg     11ab <main+0x3b>
mov    0x2e53(%rip),%rax
mov    (%rax),%rdi
mov    (%r14),%rdx
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e32(%rip),%rax
jmp    1283 <main+0x113>
mov    0x8(%r14),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     129c <main+0x12c>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1294 <main+0x124>
mov    %rax,%r15
mov    0x8(%r14),%rdx
lea    0xe3d(%rip),%rsi
mov    %rax,%rdi
call   1050 <fprintf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x5c,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1259 <main+0xe9>
mov    %rsp,%r12
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1259 <main+0xe9>
mov    %r12,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1220 <main+0xb0>
mov    0x8(%r14),%rdx
lea    0xe74(%rip),%rsi
mov    %r15,%rdi
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd80(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d29(%rip),%rax
jmp    1283 <main+0x113>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [33 x i8] c"Syntax: %s <in-file> <out-file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [80 x i8] c"/* This file has been automatically generated\0A from the input file \22%s\22. */\0A\0A\00"
@.str.5 = [93 x i8] c"#include \22config/configfragment.hpp\22\0A\0Anamespace {\0A\0Aconst char *fragment = R\22CONFIG_FRAGMENT(\00"
@.str.6 = [65 x i8] c")CONFIG_FRAGMENT\22;\0A\0AREGISTER_CONFIG_FRAGMENT(\22%s\22, fragment);\0A\0A}\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca i64
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 %19
12: ; preds = %2
%13 = load i32*, i32** @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %77
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %77
29: ; preds = %19
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %7
%34 = load i32*, i32** %7
%35 = icmp ne i32* %34, null
br i1 %35, label %41, label %36
36: ; preds = %29
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %3
br label %77
41: ; preds = %29
%42 = load i32*, i32** %7
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fputs(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.5, i64 0, i64 0), i32* %47)
br label %49
49: ; preds = %61, %41
%50 = load i32*, i32** %6
%51 = call i32 @feof(i32* %50)
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
br i1 %53, label %54, label %66
54: ; preds = %49
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%56 = load i32*, i32** %6
%57 = call i64 @fread(i8* %55, i32 1, i32 1024, i32* %56)
store i64 %57, i64* %9
%58 = load i64, i64* %9
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %54
br label %66
61: ; preds = %54
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%63 = load i64, i64* %9
%64 = load i32*, i32** %7
%65 = call i32 @fwrite(i8* %62, i64 %63, i32 1, i32* %64)
br label %49
66: ; preds = %60, %49
%67 = load i32*, i32** %7
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i32 @fprintf(i32* %67, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0), i8* %70)
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %6
%75 = call i32 @fclose(i32* %74)
%76 = load i32, i32* @EXIT_SUCCESS
store i32 %76, i32* %3
br label %77
77: ; preds = %66, %36, %26, %12
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [33 x i8] c"Syntax: %s <in-file> <out-file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [80 x i8] c"/* This file has been automatically generated\0A from the input file \22%s\22. */\0A\0A\00"
@.str.5 = [93 x i8] c"#include \22config/configfragment.hpp\22\0A\0Anamespace {\0A\0Aconst char *fragment = R\22CONFIG_FRAGMENT(\00"
@.str.6 = [65 x i8] c")CONFIG_FRAGMENT\22;\0A\0AREGISTER_CONFIG_FRAGMENT(\22%s\22, fragment);\0A\0A}\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32*, i32** @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %45
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %45
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = tail call i32 @fclose(i32* %12)
%23 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %45
24: ; preds = %16
%25 = load i8*, i8** %10
%26 = tail call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = tail call i64 bitcast (i32 (i8*, i64, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.5, i64 0, i64 0), i64 92, i64 1, i32* %19)
%28 = tail call i32 @feof(i32* %12)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %24
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %32
32: ; preds = %30, %36
%33 = call i64 @fread(i8* %31, i32 1, i32 1024, i32* %12)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
br label %40
36: ; preds = %32
%37 = call i32 @fwrite(i8* %31, i64 %33, i32 1, i32* %19)
%38 = tail call i32 @feof(i32* %12)
%39 = icmp eq i32 %38, 0
br i1 %39, label %32, label %40
40: ; preds = %36, %24, %35
%41 = load i8*, i8** %10
%42 = tail call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0), i8* %41)
%43 = tail call i32 @fclose(i32* %19)
%44 = tail call i32 @fclose(i32* %12)
br label %45
45: ; preds = %40, %21, %14, %5
%46 = phi i32* [ @EXIT_FAILURE, %5 ], [ @EXIT_SUCCESS, %40 ], [ @EXIT_FAILURE, %21 ], [ @EXIT_FAILURE, %14 ]
%47 = load i32, i32* %46
ret i32 %47
}