#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ 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 *, 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);
  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    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    120d <main+0x3d>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x16e>
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    0xde8(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125e <main+0x8e>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x16e>
mov    -0x28(%rbp),%rdi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10b0 <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   1040 <fread@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1f4,%esi
lea    0xd4e(%rip),%rdx
call   1090 <snprintf@plt>
lea    -0x230(%rbp),%rdi
lea    0xd4b(%rip),%rsi
call   10d0 <popen@plt>
mov    %rax,-0x238(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x238(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    -0x38(%rbp),%rsi
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x238(%rbp),%rdi
call   1080 <pclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
cmp    $0x3,%edi
jg     1205 <main+0x25>
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
jmp    12e5 <main+0x105>
mov    0x8(%rsi),%rdi
mov    0x18(%rsi),%r14
lea    0xdec(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12d7 <main+0xf7>
mov    %rax,%rbp
mov    0x2dbc(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %rbp,%rdi
call   10b0 <ftell@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1080 <rewind@plt>
lea    0x1(%r12),%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
movslq %r12d,%r12
movb   $0x0,(%rax,%r12,1)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
lea    0xd91(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1f4,%esi
mov    %r14,%rcx
call   10a0 <snprintf@plt>
lea    0xd87(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <popen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1090 <pclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    12eb <main+0x10b>
lea    0xd24(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
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 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [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 [500 x i8]
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = 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 %70
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
store i8* %25, i8** %7
%26 = load i8*, i8** %6
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %8
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = 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 %70
32: ; preds = %19
%33 = load i32*, i32** %8
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %8
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %9
%38 = load i32*, i32** %8
%39 = call i32 @rewind(i32* %38)
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i8*
store i8* %44, i8** %11
%45 = load i8*, i8** %11
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %11
%50 = load i32, i32* %9
%51 = load i32*, i32** %8
%52 = call i32 @fread(i8* %49, i32 1, i32 %50, i32* %51)
store i32 %52, i32* %12
%53 = load i32*, i32** %8
%54 = call i32 @fclose(i32* %53)
%55 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%56 = load i8*, i8** %7
%57 = call i32 @snprintf(i8* %55, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%59 = call i32* @popen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %59, i32** %14
%60 = load i8*, i8** %11
%61 = load i32, i32* %9
%62 = load i32*, i32** %14
%63 = call i32 @fwrite(i8* %60, i32 1, i32 %61, i32* %62)
%64 = load i8*, i8** %11
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %64)
%66 = load i32*, i32** %14
%67 = call i32 @pclose(i32* %66)
%68 = load i8*, i8** %11
%69 = call i32 @free(i8* %68)
br label %70
70: ; preds = %32, %30, %17
%71 = load i32, i32* %3
ret i32 %71
}

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 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.4 = [2 x i8] c"w\00"
@str = [23 x i8] c"Insufficient arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [500 x i8]
%4 = icmp slt i32 %0, 4
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %35
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 3
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %35
16: ; preds = %7
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %12, i32 0, i32 %17)
%19 = tail call i32 @ftell(i32* %12)
%20 = tail call i32 @rewind(i32* %12)
%21 = add nsw i32 %19, 1
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = sext i32 %19 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @fread(i8* %23, i32 1, i32 %19, i32* %12)
%27 = tail call i32 @fclose(i32* %12)
%28 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%29 = call i32 @snprintf(i8* %28, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%30 = call i32* @popen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @fwrite(i8* %23, i32 1, i32 %19, i32* %30)
%32 = call i32 @puts(i8* dereferenceable(1) %23)
%33 = call i32 @pclose(i32* %30)
%34 = call i32 @free(i8* %23)
br label %35
35: ; preds = %14, %16, %5
%36 = phi i32 [ 1, %5 ], [ 1, %14 ], [ 0, %16 ]
ret i32 %36
}