#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 /*<<< orphan*/ DumpFile(int /*<<< orphan*/ *, char *, char const *, char *);
char *ReadFile(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char const *);
char *strstr(char *, char const *);
int main(int argc, char *argv[]) {
  if (6 != argc) {
    printf("Syntax: %s dest embedsource pattern symbol define\n", argv[0]);
    return 1;
  }
  const char *pDestArg = argv[1];
  const char *pEmbedSourceArg = argv[2];
  const char *pPatternArg = argv[3];
  const char *pSymbolArg = argv[4];
  const char *pDefineArg = argv[5];
  char *pEmbedSrc = ReadFile(pEmbedSourceArg);
  if (!pEmbedSrc) {
    return 1;
  }
  char *pEmbedStart = pEmbedSrc;
  char *pEmbedStartEnd = strstr(pEmbedStart, pPatternArg);
  char *pEmbedEnd = 0;
  if (pEmbedStartEnd) {
    pEmbedEnd = pEmbedStartEnd + strlen(pPatternArg);
    *pEmbedStartEnd = '\0';
  }
  FILE *pOut = fopen(pDestArg, "a");
  if (!pOut) {
    free(pEmbedSrc);
    return 1;
  }
  fprintf(pOut, "///start file generated from %s\n", pEmbedSourceArg);
  fprintf(pOut, "#ifdef %s\n", pDefineArg);
  DumpFile(pOut, pEmbedStart, pSymbolArg, "_begin");
  DumpFile(pOut, pEmbedEnd, pSymbolArg, "_end");
  fprintf(pOut, "#endif //%s\n", pDefineArg);
  fprintf(pOut, "\n///end file generated from  %s\n", pEmbedSourceArg);
  fclose(pOut);
  free(pEmbedSrc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x6,%eax
cmp    -0x8(%rbp),%eax
je     11d3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3e(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1354 <main+0x1c4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <ReadFile@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1233 <main+0xa3>
movl   $0x1,-0x4(%rbp)
jmp    1354 <main+0x1c4>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1287 <main+0xf7>
mov    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    0xda1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    12bb <main+0x12b>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1354 <main+0x1c4>
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd6b(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd78(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd6b(%rip),%rcx
call   10a0 <DumpFile@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd5a(%rip),%rcx
call   10a0 <DumpFile@plt>
mov    -0x60(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd4b(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd44(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x6,%edi
jne    1205 <main+0x75>
mov    0x8(%rsi),%r12
mov    0x10(%rsi),%rbx
mov    0x18(%rsi),%r15
mov    0x20(%rsi),%rax
mov    %rax,0x10(%rsp)
mov    0x28(%rsi),%r14
mov    %rbx,%rdi
call   1050 <ReadFile@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     12d8 <main+0x148>
mov    %rax,%r13
mov    %r14,0x8(%rsp)
mov    %rbx,(%rsp)
mov    %rax,%rdi
mov    %r15,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     121e <main+0x8e>
mov    %rax,%r14
mov    %r15,%rdi
call   1060 <strlen@plt>
movslq %eax,%r15
add    %r14,%r15
movb   $0x0,(%r14)
jmp    1221 <main+0x91>
mov    (%rsi),%rsi
lea    0xdf1(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%ebp
jmp    12d8 <main+0x148>
xor    %r15d,%r15d
lea    0xe0b(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
mov    0x8(%rsp),%r14
je     12d0 <main+0x140>
mov    %rax,%rbx
lea    0xded(%rip),%rsi
mov    %rax,%rdi
mov    (%rsp),%r12
mov    %r12,%rdx
call   1080 <fprintf@plt>
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <fprintf@plt>
lea    0xdf1(%rip),%rcx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
call   10a0 <DumpFile@plt>
lea    0xdde(%rip),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   10a0 <DumpFile@plt>
lea    0xdce(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <fprintf@plt>
lea    0xdc9(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    12d8 <main+0x148>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Syntax: %s dest embedsource pattern symbol define\0A\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [33 x i8] c"///start file generated from %s\0A\00"
@.str.3 = [11 x i8] c"#ifdef %s\0A\00"
@.str.4 = [7 x i8] c"_begin\00"
@.str.5 = [5 x i8] c"_end\00"
@.str.6 = [13 x i8] c"#endif //%s\0A\00"
@.str.7 = [33 x i8] c"\0A///end file generated from %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 6, %16
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %91
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
store i8* %32, i8** %8
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 4
%35 = load i8*, i8** %34
store i8* %35, i8** %9
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 5
%38 = load i8*, i8** %37
store i8* %38, i8** %10
%39 = load i8*, i8** %7
%40 = call i8* @ReadFile(i8* %39)
store i8* %40, i8** %11
%41 = load i8*, i8** %11
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %23
store i32 1, i32* %3
br label %91
44: ; preds = %23
%45 = load i8*, i8** %11
store i8* %45, i8** %12
%46 = load i8*, i8** %12
%47 = load i8*, i8** %8
%48 = call i8* @strstr(i8* %46, i8* %47)
store i8* %48, i8** %13
store i8* null, i8** %14
%49 = load i8*, i8** %13
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %58
51: ; preds = %44
%52 = load i8*, i8** %13
%53 = load i8*, i8** %8
%54 = call i32 @strlen(i8* %53)
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8* %56, i8** %14
%57 = load i8*, i8** %13
store i8 0, i8* %57
br label %58
58: ; preds = %51, %44
%59 = load i8*, i8** %6
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %60, i32** %15
%61 = load i32*, i32** %15
%62 = icmp ne i32* %61, null
br i1 %62, label %66, label %63
63: ; preds = %58
%64 = load i8*, i8** %11
%65 = call i32 @free(i8* %64)
store i32 1, i32* %3
br label %91
66: ; preds = %58
%67 = load i32*, i32** %15
%68 = load i8*, i8** %7
%69 = call i32 @fprintf(i32* %67, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %68)
%70 = load i32*, i32** %15
%71 = load i8*, i8** %10
%72 = call i32 @fprintf(i32* %70, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %71)
%73 = load i32*, i32** %15
%74 = load i8*, i8** %12
%75 = load i8*, i8** %9
%76 = call i32 @DumpFile(i32* %73, i8* %74, i8* %75, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32*, i32** %15
%78 = load i8*, i8** %14
%79 = load i8*, i8** %9
%80 = call i32 @DumpFile(i32* %77, i8* %78, i8* %79, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32*, i32** %15
%82 = load i8*, i8** %10
%83 = call i32 @fprintf(i32* %81, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %82)
%84 = load i32*, i32** %15
%85 = load i8*, i8** %7
%86 = call i32 @fprintf(i32* %84, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %85)
%87 = load i32*, i32** %15
%88 = call i32 @fclose(i32* %87)
%89 = load i8*, i8** %11
%90 = call i32 @free(i8* %89)
store i32 0, i32* %3
br label %91
91: ; preds = %66, %63, %43, %18
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@.str = [51 x i8] c"Syntax: %s dest embedsource pattern symbol define\0A\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [33 x i8] c"///start file generated from %s\0A\00"
@.str.3 = [11 x i8] c"#ifdef %s\0A\00"
@.str.4 = [7 x i8] c"_begin\00"
@.str.5 = [5 x i8] c"_end\00"
@.str.6 = [13 x i8] c"#endif //%s\0A\00"
@.str.7 = [33 x i8] c"\0A///end file generated from %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 6
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %42
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 4
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 5
%17 = load i8*, i8** %16
%18 = tail call i8* @ReadFile(i8* %11)
%19 = icmp eq i8* %18, null
br i1 %19, label %42, label %20
20: ; preds = %7
%21 = tail call i8* @strstr(i8* %18, i8* dereferenceable(1) %13)
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = tail call i32 @strlen(i8* %13)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %21, i64 %25
store i8 0, i8* %21
br label %27
27: ; preds = %23, %20
%28 = phi i8* [ %26, %23 ], [ null, %20 ]
%29 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 @free(i8* %18)
br label %42
33: ; preds = %27
%34 = tail call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%35 = tail call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%36 = tail call i32 @DumpFile(i32* %29, i8* %18, i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call i32 @DumpFile(i32* %29, i8* %28, i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%38 = tail call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %17)
%39 = tail call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %11)
%40 = tail call i32 @fclose(i32* %29)
%41 = tail call i32 @free(i8* %18)
br label %42
42: ; preds = %7, %33, %31, %4
%43 = phi i32 [ 1, %4 ], [ 1, %7 ], [ 0, %33 ], [ 1, %31 ]
ret i32 %43
}