#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(void *, int, long, int /*<<< orphan*/ *);
scalar_t__ malloc(long);
int /*<<< orphan*/ memcpy(void *, void *, long);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
long strlen(char *);
scalar_t__ strstr(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 6) {
    printf("%s [source script] [target script] [string] [binary] [mode]\n",
           argv[0]);
    return 1;
  }
  int mode = 0;
  if (!strcmp(argv[5], "nowrap"))
    mode = 0;
  else if (!strcmp(argv[5], "wrap"))
    mode = 1;
  long script_in_len, script_out_len, binary_len, binary_p_len;
  FILE *script_in_f = NULL;
  FILE *script_out_f = NULL;
  FILE *binary_f = NULL;
  if ((script_in_f = fopen(argv[1], "r")) == NULL)
    return 1;
  if ((binary_f = fopen(argv[4], "r")) == NULL)
    return 1;
  fseek(script_in_f, 0L, SEEK_END);
  script_in_len = ftell(script_in_f);
  fseek(script_in_f, 0L, SEEK_SET);
  fseek(binary_f, 0L, SEEK_END);
  binary_len = ftell(binary_f);
  fseek(binary_f, 0L, SEEK_SET);
  if (mode == 1) {
    binary_p_len = (binary_len / 19) * 4 + binary_len * 4;
    if (binary_len % 19 != 0)
      binary_p_len += 4;
  } else
    binary_p_len = binary_len * 4;
  script_out_len = script_in_len - strlen(argv[3]) + binary_p_len;
  char *script_in = (char *)malloc(binary_len);
  char *binary = (char *)malloc(binary_len);
  char *script_out = (char *)malloc(script_out_len);
  fread((void *)script_in, 1, script_in_len, script_in_f);
  fread((void *)binary, 1, binary_len, binary_f);
  fclose(script_in_f);
  fclose(binary_f);
  unsigned long str_s = (unsigned long)strstr(script_in, argv[3]);
  unsigned long str_e = str_s + (unsigned long)strlen(argv[3]);
  if (str_s == 0)
    return 1;
  memcpy((void *)script_out, (void *)script_in,
         str_s - (unsigned long)script_in);
  memcpy((void *)((unsigned long)script_out + str_s - (unsigned long)script_in +
                  (unsigned long)binary_p_len),
         (void *)str_e, script_in_len - (str_e - (unsigned long)script_in));
  unsigned long addr =
      (unsigned long)script_out + str_s - (unsigned long)script_in;
  unsigned int i;
  for (i = 0; i < binary_len; i++) {
    if (mode == 1 && (i % 19) == 0) {
      sprintf((char *)addr, "'\\\n'");
      addr += 4;
    }
    sprintf((char *)addr, "\\x%02x", (unsigned char)binary[i]);
    addr += 4;
  }
  *((char *)addr) = *((char *)str_e);
  if ((script_out_f = fopen(argv[2], "w")) == NULL)
    return 1;
  fwrite((void *)script_out, 1, script_out_len, script_out_f);
  fclose(script_out_f);
  free(script_in);
  free(script_out);
  free(binary);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     1222 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdef(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1616 <main+0x436>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xe05(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1252 <main+0x72>
movl   $0x0,-0x14(%rbp)
jmp    127b <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xdde(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1276 <main+0x96>
movl   $0x1,-0x14(%rbp)
jmp    127b <main+0x9b>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda2(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    12c1 <main+0xe1>
movl   $0x1,-0x4(%rbp)
jmp    1616 <main+0x436>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xd74(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    12ef <main+0x10f>
movl   $0x1,-0x4(%rbp)
jmp    1616 <main+0x436>
mov    -0x40(%rbp),%rdi
mov    0x2cee(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2cbb(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x50(%rbp),%rdi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x50(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x50(%rbp),%rdi
mov    0x2c82(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
cmpl   $0x1,-0x14(%rbp)
jne    13b5 <main+0x1d5>
mov    -0x30(%rbp),%rax
mov    $0x13,%ecx
cqto
idiv   %rcx
shl    $0x2,%rax
mov    -0x30(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x13,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     13b0 <main+0x1d0>
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
jmp    13c1 <main+0x1e1>
mov    -0x30(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
sub    %rcx,%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x60(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    14a8 <main+0x2c8>
movl   $0x1,-0x4(%rbp)
jmp    1616 <main+0x436>
mov    -0x68(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x58(%rbp),%rax
sub    %rax,%rdx
call   10a0 <memcpy@plt>
mov    -0x68(%rbp),%rdi
add    -0x70(%rbp),%rdi
mov    -0x58(%rbp),%rax
sub    %rax,%rdi
add    -0x38(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x78(%rbp),%rax
mov    -0x58(%rbp),%rcx
sub    %rcx,%rax
sub    %rax,%rdx
call   10a0 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    -0x70(%rbp),%rax
mov    -0x58(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x30(%rbp),%rax
jge    159b <main+0x3bb>
cmpl   $0x1,-0x14(%rbp)
jne    155b <main+0x37b>
mov    -0x84(%rbp),%eax
mov    $0x13,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    155b <main+0x37b>
mov    -0x80(%rbp),%rdi
lea    0xafe(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0x80(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    -0x84(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xad7(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0x80(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x80(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    150b <main+0x32b>
mov    -0x78(%rbp),%rax
mov    (%rax),%cl
mov    -0x80(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xa9c(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    15d5 <main+0x3f5>
movl   $0x1,-0x4(%rbp)
jmp    1616 <main+0x436>
mov    -0x68(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r15
cmp    $0x6,%edi
jne    1227 <main+0x47>
mov    0x28(%r15),%rbx
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1240 <main+0x60>
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
sete   %al
mov    %eax,0x4(%rsp)
jmp    1248 <main+0x68>
mov    (%r15),%rsi
lea    0xdcf(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%ebp
jmp    151c <main+0x33c>
movl   $0x0,0x4(%rsp)
mov    0x8(%r15),%rdi
lea    0xdf1(%rip),%rsi
call   10d0 <fopen@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     151c <main+0x33c>
mov    %rax,%rbx
mov    0x20(%r15),%rdi
lea    0xdd0(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     151c <main+0x33c>
mov    %rax,%r14
mov    0x2d5c(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,0x18(%rsp)
mov    0x2d2a(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    (%r12),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r14,%rdi
call   1090 <ftell@plt>
mov    %rax,%r13
mov    0x0(%rbp),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
cmpb   $0x0,0x4(%rsp)
mov    %r14,0x40(%rsp)
mov    %rbx,0x38(%rsp)
je     134d <main+0x16d>
movabs $0xd79435e50d79436,%rcx
43 79 0d
mov    %r13,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
add    %rdx,%rax
add    %r13,%rax
lea    0x0(,%rax,4),%rcx
movabs $0x86bca1af286bca1b,%rdx
a1 bc 86
imul   %r13,%rdx
movabs $0x6bca1af286bca1a,%rsi
a1 bc 06
add    %rdx,%rsi
movabs $0xd79435e50d79435,%rdx
43 79 0d
cmp    %rdx,%rsi
lea    0x4(,%rax,4),%rbx
cmovb  %rcx,%rbx
jmp    1355 <main+0x175>
lea    0x0(,%r13,4),%rbx
mov    0x18(%r15),%rdi
call   1060 <strlen@plt>
mov    0x18(%rsp),%r14
mov    %r14,%rbp
sub    %rax,%rbp
mov    %rbx,0x30(%rsp)
add    %rbx,%rbp
mov    %r13,%rdi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x10(%rsp)
mov    %r13,%rdi
call   10b0 <malloc@plt>
mov    %r15,0x20(%rsp)
mov    %rax,%r15
mov    %rbp,0x28(%rsp)
mov    %rbp,%rdi
call   10b0 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    0x38(%rsp),%r12
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    0x40(%rsp),%r14
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
mov    0x10(%rsp),%r14
call   1050 <fclose@plt>
mov    0x20(%rsp),%rbx
mov    0x18(%rbx),%rsi
mov    %r14,%rdi
call   1100 <strstr@plt>
mov    %rax,%r12
mov    0x18(%rbx),%rdi
call   1060 <strlen@plt>
test   %r12,%r12
je     151c <main+0x33c>
mov    %rax,%rbx
add    %r12,%rbx
mov    %r12,%rdx
sub    %r14,%rdx
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <memcpy@plt>
sub    %r14,%rbp
add    %r12,%rbp
mov    0x30(%rsp),%rdi
add    %rbp,%rdi
mov    0x18(%rsp),%rdx
add    %r14,%rdx
sub    %rbx,%rdx
mov    %rbx,%rsi
call   10a0 <memcpy@plt>
test   %r13,%r13
jle    14b7 <main+0x2d7>
lea    0xbef(%rip),%r12
xor    %r14d,%r14d
jmp    148f <main+0x2af>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%r14,1),%edx
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10e0 <sprintf@plt>
add    $0x4,%rbp
add    $0x1,%r14d
cmp    %r14,%r13
jle    14b7 <main+0x2d7>
imul   $0x286bca1b,%r14d,%eax
cmp    $0xd79435f,%eax
setb   %al
and    0x4(%rsp),%al
cmp    $0x1,%al
jne    1470 <main+0x290>
movb   $0x0,0x4(%rbp)
movl   $0x270a5c27,0x0(%rbp)
add    $0x4,%rbp
jmp    1470 <main+0x290>
mov    (%rbx),%al
mov    %al,0x0(%rbp)
mov    0x20(%rsp),%rax
mov    0x10(%rax),%rdi
lea    0xb86(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
mov    $0x1,%ebp
je     151c <main+0x33c>
mov    %rax,%rbx
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    0x28(%rsp),%rdx
mov    %rax,%rcx
call   10f0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"%s [source script] [target script] [string] [binary] [mode]\0A\00"
@.str.1 = [7 x i8] c"nowrap\00"
@.str.2 = [5 x i8] c"wrap\00"
@.str.3 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [5 x i8] c"'\\\0A'\00"
@.str.5 = [7 x i8] c"\\x%02x\00"
@.str.6 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 6
br i1 %22, label %23, label %28
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 1, i32* %3
br label %229
28: ; preds = %2
store i32 0, i32* %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 5
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %28
store i32 0, i32* %6
br label %43
35: ; preds = %28
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 5
%38 = load i8*, i8** %37
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %35
store i32 1, i32* %6
br label %42
42: ; preds = %41, %35
br label %43
43: ; preds = %42, %34
store i32* null, i32** %11
store i32* null, i32** %12
store i32* null, i32** %13
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %47, i32** %11
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %50
49: ; preds = %43
store i32 1, i32* %3
br label %229
50: ; preds = %43
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 4
%53 = load i8*, i8** %52
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %54, i32** %13
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 1, i32* %3
br label %229
57: ; preds = %50
%58 = load i32*, i32** %11
%59 = load i32, i32* @SEEK_END
%60 = call i32 @fseek(i32* %58, i64 0, i32 %59)
%61 = load i32*, i32** %11
%62 = call i64 @ftell(i32* %61)
store i64 %62, i64* %7
%63 = load i32*, i32** %11
%64 = load i32, i32* @SEEK_SET
%65 = call i32 @fseek(i32* %63, i64 0, i32 %64)
%66 = load i32*, i32** %13
%67 = load i32, i32* @SEEK_END
%68 = call i32 @fseek(i32* %66, i64 0, i32 %67)
%69 = load i32*, i32** %13
%70 = call i64 @ftell(i32* %69)
store i64 %70, i64* %9
%71 = load i32*, i32** %13
%72 = load i32, i32* @SEEK_SET
%73 = call i32 @fseek(i32* %71, i64 0, i32 %72)
%74 = load i32, i32* %6
%75 = icmp eq i32 %74, 1
br i1 %75, label %76, label %90
76: ; preds = %57
%77 = load i64, i64* %9
%78 = sdiv i64 %77, 19
%79 = mul nsw i64 %78, 4
%80 = load i64, i64* %9
%81 = mul nsw i64 %80, 4
%82 = add nsw i64 %79, %81
store i64 %82, i64* %10
%83 = load i64, i64* %9
%84 = srem i64 %83, 19
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %76
%87 = load i64, i64* %10
%88 = add nsw i64 %87, 4
store i64 %88, i64* %10
br label %89
89: ; preds = %86, %76
br label %93
90: ; preds = %57
%91 = load i64, i64* %9
%92 = mul nsw i64 %91, 4
store i64 %92, i64* %10
br label %93
93: ; preds = %90, %89
%94 = load i64, i64* %7
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 3
%97 = load i8*, i8** %96
%98 = call i64 @strlen(i8* %97)
%99 = sub nsw i64 %94, %98
%100 = load i64, i64* %10
%101 = add nsw i64 %99, %100
store i64 %101, i64* %8
%102 = load i64, i64* %9
%103 = call i64 @malloc(i64 %102)
%104 = inttoptr i64 %103 to i8*
store i8* %104, i8** %14
%105 = load i64, i64* %9
%106 = call i64 @malloc(i64 %105)
%107 = inttoptr i64 %106 to i8*
store i8* %107, i8** %15
%108 = load i64, i64* %8
%109 = call i64 @malloc(i64 %108)
%110 = inttoptr i64 %109 to i8*
store i8* %110, i8** %16
%111 = load i8*, i8** %14
%112 = load i64, i64* %7
%113 = load i32*, i32** %11
%114 = call i32 @fread(i8* %111, i32 1, i64 %112, i32* %113)
%115 = load i8*, i8** %15
%116 = load i64, i64* %9
%117 = load i32*, i32** %13
%118 = call i32 @fread(i8* %115, i32 1, i64 %116, i32* %117)
%119 = load i32*, i32** %11
%120 = call i32 @fclose(i32* %119)
%121 = load i32*, i32** %13
%122 = call i32 @fclose(i32* %121)
%123 = load i8*, i8** %14
%124 = load i8**, i8*** %5
%125 = getelementptr inbounds i8*, i8** %124, i64 3
%126 = load i8*, i8** %125
%127 = call i64 @strstr(i8* %123, i8* %126)
store i64 %127, i64* %17
%128 = load i64, i64* %17
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 3
%131 = load i8*, i8** %130
%132 = call i64 @strlen(i8* %131)
%133 = add i64 %128, %132
store i64 %133, i64* %18
%134 = load i64, i64* %17
%135 = icmp eq i64 %134, 0
br i1 %135, label %136, label %137
136: ; preds = %93
store i32 1, i32* %3
br label %229
137: ; preds = %93
%138 = load i8*, i8** %16
%139 = load i8*, i8** %14
%140 = load i64, i64* %17
%141 = load i8*, i8** %14
%142 = ptrtoint i8* %141 to i64
%143 = sub i64 %140, %142
%144 = call i32 @memcpy(i8* %138, i8* %139, i64 %143)
%145 = load i8*, i8** %16
%146 = ptrtoint i8* %145 to i64
%147 = load i64, i64* %17
%148 = add i64 %146, %147
%149 = load i8*, i8** %14
%150 = ptrtoint i8* %149 to i64
%151 = sub i64 %148, %150
%152 = load i64, i64* %10
%153 = add i64 %151, %152
%154 = inttoptr i64 %153 to i8*
%155 = load i64, i64* %18
%156 = inttoptr i64 %155 to i8*
%157 = load i64, i64* %7
%158 = load i64, i64* %18
%159 = load i8*, i8** %14
%160 = ptrtoint i8* %159 to i64
%161 = sub i64 %158, %160
%162 = sub i64 %157, %161
%163 = call i32 @memcpy(i8* %154, i8* %156, i64 %162)
%164 = load i8*, i8** %16
%165 = ptrtoint i8* %164 to i64
%166 = load i64, i64* %17
%167 = add i64 %165, %166
%168 = load i8*, i8** %14
%169 = ptrtoint i8* %168 to i64
%170 = sub i64 %167, %169
store i64 %170, i64* %19
store i32 0, i32* %20
br label %171
171: ; preds = %201, %137
%172 = load i32, i32* %20
%173 = zext i32 %172 to i64
%174 = load i64, i64* %9
%175 = icmp slt i64 %173, %174
br i1 %175, label %176, label %204
176: ; preds = %171
%177 = load i32, i32* %6
%178 = icmp eq i32 %177, 1
br i1 %178, label %179, label %189
179: ; preds = %176
%180 = load i32, i32* %20
%181 = urem i32 %180, 19
%182 = icmp eq i32 %181, 0
br i1 %182, label %183, label %189
183: ; preds = %179
%184 = load i64, i64* %19
%185 = inttoptr i64 %184 to i8*
%186 = call i32 (i8*, i8*, ...) @sprintf(i8* %185, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%187 = load i64, i64* %19
%188 = add i64 %187, 4
store i64 %188, i64* %19
br label %189
189: ; preds = %183, %179, %176
%190 = load i64, i64* %19
%191 = inttoptr i64 %190 to i8*
%192 = load i8*, i8** %15
%193 = load i32, i32* %20
%194 = zext i32 %193 to i64
%195 = getelementptr inbounds i8, i8* %192, i64 %194
%196 = load i8, i8* %195
%197 = zext i8 %196 to i32
%198 = call i32 (i8*, i8*, ...) @sprintf(i8* %191, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %197)
%199 = load i64, i64* %19
%200 = add i64 %199, 4
store i64 %200, i64* %19
br label %201
201: ; preds = %189
%202 = load i32, i32* %20
%203 = add i32 %202, 1
store i32 %203, i32* %20
br label %171
204: ; preds = %171
%205 = load i64, i64* %18
%206 = inttoptr i64 %205 to i8*
%207 = load i8, i8* %206
%208 = load i64, i64* %19
%209 = inttoptr i64 %208 to i8*
store i8 %207, i8* %209
%210 = load i8**, i8*** %5
%211 = getelementptr inbounds i8*, i8** %210, i64 2
%212 = load i8*, i8** %211
%213 = call i32* @fopen(i8* %212, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %213, i32** %12
%214 = icmp eq i32* %213, null
br i1 %214, label %215, label %216
215: ; preds = %204
store i32 1, i32* %3
br label %229
216: ; preds = %204
%217 = load i8*, i8** %16
%218 = load i64, i64* %8
%219 = load i32*, i32** %12
%220 = call i32 @fwrite(i8* %217, i32 1, i64 %218, i32* %219)
%221 = load i32*, i32** %12
%222 = call i32 @fclose(i32* %221)
%223 = load i8*, i8** %14
%224 = call i32 @free(i8* %223)
%225 = load i8*, i8** %16
%226 = call i32 @free(i8* %225)
%227 = load i8*, i8** %15
%228 = call i32 @free(i8* %227)
store i32 0, i32* %3
br label %229
229: ; preds = %216, %215, %136, %56, %49, %23
%230 = load i32, i32* %3
ret i32 %230
}

LLVM IR (-O2):
@.str = [61 x i8] c"%s [source script] [target script] [string] [binary] [mode]\0A\00"
@.str.1 = [7 x i8] c"nowrap\00"
@.str.2 = [5 x i8] c"wrap\00"
@.str.3 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [5 x i8] c"'\\\0A'\00"
@.str.5 = [7 x i8] c"\\x%02x\00"
@.str.6 = [2 x i8] c"w\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 ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %117
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 5
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br label %15
15: ; preds = %12, %7
%16 = phi i1 [ false, %7 ], [ %14, %12 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%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 %117, label %21
21: ; preds = %15
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %117, label %26
26: ; preds = %21
%27 = load i32, i32* @SEEK_END
%28 = tail call i32 @fseek(i32* %19, i64 0, i32 %27)
%29 = tail call i64 @ftell(i32* %19)
%30 = load i32, i32* @SEEK_SET
%31 = tail call i32 @fseek(i32* %19, i64 0, i32 %30)
%32 = load i32, i32* @SEEK_END
%33 = tail call i32 @fseek(i32* %24, i64 0, i32 %32)
%34 = tail call i64 @ftell(i32* %24)
%35 = load i32, i32* @SEEK_SET
%36 = tail call i32 @fseek(i32* %24, i64 0, i32 %35)
br i1 %16, label %37, label %45
37: ; preds = %26
%38 = sdiv i64 %34, 19
%39 = add i64 %38, %34
%40 = shl i64 %39, 2
%41 = srem i64 %34, 19
%42 = icmp eq i64 %41, 0
%43 = add nsw i64 %40, 4
%44 = select i1 %42, i64 %40, i64 %43
br label %47
45: ; preds = %26
%46 = shl nsw i64 %34, 2
br label %47
47: ; preds = %37, %45
%48 = phi i64 [ %46, %45 ], [ %44, %37 ]
%49 = getelementptr inbounds i8*, i8** %1, i64 3
%50 = load i8*, i8** %49
%51 = tail call i64 @strlen(i8* dereferenceable(1) %50)
%52 = sub nsw i64 %29, %51
%53 = add nsw i64 %52, %48
%54 = tail call i64 @malloc(i64 %34)
%55 = inttoptr i64 %54 to i8*
%56 = tail call i64 @malloc(i64 %34)
%57 = inttoptr i64 %56 to i8*
%58 = tail call i64 @malloc(i64 %53)
%59 = inttoptr i64 %58 to i8*
%60 = tail call i32 @fread(i8* %55, i32 1, i64 %29, i32* %19)
%61 = tail call i32 @fread(i8* %57, i32 1, i64 %34, i32* %24)
%62 = tail call i32 @fclose(i32* %19)
%63 = tail call i32 @fclose(i32* %24)
%64 = load i8*, i8** %49
%65 = tail call i64 @strstr(i8* %55, i8* %64)
%66 = load i8*, i8** %49
%67 = tail call i64 @strlen(i8* dereferenceable(1) %66)
%68 = add i64 %67, %65
%69 = icmp eq i64 %65, 0
br i1 %69, label %117, label %70
70: ; preds = %47
%71 = sub i64 %65, %54
%72 = tail call i32 @memcpy(i8* %59, i8* %55, i64 %71)
%73 = sub i64 %58, %54
%74 = add i64 %73, %65
%75 = add i64 %74, %48
%76 = inttoptr i64 %75 to i8*
%77 = inttoptr i64 %68 to i8*
%78 = add i64 %54, %29
%79 = sub i64 %78, %68
%80 = tail call i32 @memcpy(i8* %76, i8* %77, i64 %79)
%81 = icmp sgt i64 %34, 0
br i1 %81, label %82, label %103
82: ; preds = %70, %92
%83 = phi i64 [ %101, %92 ], [ 0, %70 ]
%84 = phi i64 [ %99, %92 ], [ %74, %70 ]
%85 = trunc i64 %83 to i32
%86 = urem i32 %85, 19
%87 = icmp eq i32 %86, 0
%88 = select i1 %16, i1 %87, i1 false
br i1 %88, label %89, label %92
89: ; preds = %82
%90 = inttoptr i64 %84 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %90, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 5, i1 false)
%91 = add i64 %84, 4
br label %92
92: ; preds = %89, %82
%93 = phi i64 [ %91, %89 ], [ %84, %82 ]
%94 = inttoptr i64 %93 to i8*
%95 = getelementptr inbounds i8, i8* %57, i64 %83
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
%98 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %94, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %97)
%99 = add i64 %93, 4
%100 = add nuw nsw i64 %83, 1
%101 = and i64 %100, 4294967295
%102 = icmp sgt i64 %34, %101
br i1 %102, label %82, label %103
103: ; preds = %92, %70
%104 = phi i64 [ %74, %70 ], [ %99, %92 ]
%105 = load i8, i8* %77
%106 = inttoptr i64 %104 to i8*
store i8 %105, i8* %106
%107 = getelementptr inbounds i8*, i8** %1, i64 2
%108 = load i8*, i8** %107
%109 = tail call i32* @fopen(i8* %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%110 = icmp eq i32* %109, null
br i1 %110, label %117, label %111
111: ; preds = %103
%112 = tail call i32 @fwrite(i8* %59, i32 1, i64 %53, i32* %109)
%113 = tail call i32 @fclose(i32* %109)
%114 = tail call i32 @free(i8* %55)
%115 = tail call i32 @free(i8* %59)
%116 = tail call i32 @free(i8* %57)
br label %117
117: ; preds = %15, %21, %111, %103, %47, %4
%118 = phi i32 [ 1, %4 ], [ 1, %15 ], [ 1, %21 ], [ 1, %47 ], [ 0, %111 ], [ 1, %103 ]
ret i32 %118
}