#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 /*<<< 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);
  char newDataType[6] = {'u', 'i', 'n', 't', '1', '\0'};
  char *whereUint;
  while ((whereUint = strstr(buffer, newDataType)) != NULL) {
    strncpy(whereUint, "char ", 5);
  }
  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    $0x260,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    122d <main+0x3d>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a7 <main+0x1b7>
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    0xdc8(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    127e <main+0x8e>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a7 <main+0x1b7>
mov    -0x28(%rbp),%rdi
mov    0x2d5f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <rewind@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10c0 <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>
mov    0xd3f(%rip),%eax
mov    %eax,-0x42(%rbp)
mov    0xd39(%rip),%ax
mov    %ax,-0x3e(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x42(%rbp),%rsi
call   1110 <strstr@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     1332 <main+0x142>
mov    -0x50(%rbp),%rdi
lea    0xd11(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncpy@plt>
jmp    12fd <main+0x10d>
lea    -0x250(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1f4,%esi
lea    0xcf1(%rip),%rdx
call   10a0 <snprintf@plt>
lea    -0x250(%rbp),%rdi
lea    0xcee(%rip),%rsi
call   10e0 <popen@plt>
mov    %rax,-0x258(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x258(%rbp),%rcx
mov    $0x1,%esi
call   1100 <fwrite@plt>
mov    -0x38(%rbp),%rsi
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x258(%rbp),%rdi
call   1090 <pclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f8,%rsp
cmp    $0x3,%edi
jg     1227 <main+0x27>
lea    0xe17(%rip),%rdi
call   1050 <puts@plt>
jmp    1347 <main+0x147>
mov    0x8(%rsi),%rdi
mov    0x18(%rsi),%r14
lea    0xdca(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     1339 <main+0x139>
mov    %rax,%rbp
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
xor    %r12d,%r12d
mov    %rbp,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %rbp,%rdi
call   10c0 <ftell@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1090 <rewind@plt>
lea    0x1(%r15),%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
movslq %r15d,%rdx
movb   $0x0,(%rax,%rdx,1)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rcx
call   1060 <fread@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
lea    0xd74(%rip),%rsi
mov    %rbx,%rdi
call   1120 <strstr@plt>
test   %rax,%rax
je     12e0 <main+0xe0>
lea    0xd66(%rip),%r13
lea    0xd59(%rip),%rbp
nopl   (%rax)
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1120 <strstr@plt>
test   %rax,%rax
jne    12c0 <main+0xc0>
lea    0xd3b(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1f4,%esi
mov    %r14,%rcx
call   10b0 <snprintf@plt>
lea    0xd31(%rip),%rsi
mov    %rbp,%rdi
call   10f0 <popen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1110 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   10a0 <pclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    134d <main+0x14d>
lea    0xcc2(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x1f8,%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
@__const.main.newDataType = [6 x i8] c"uint1\00"
@.str.3 = [6 x i8] c"char \00"
@.str.4 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [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 [6 x i8]
%14 = alloca i8*
%15 = alloca [500 x i8]
%16 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = 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 %82
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %6
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = 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 %82
34: ; preds = %21
%35 = load i32*, i32** %8
%36 = load i32, i32* @SEEK_END
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %8
%39 = call i32 @ftell(i32* %38)
store i32 %39, i32* %9
%40 = load i32*, i32** %8
%41 = call i32 @rewind(i32* %40)
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %11
%47 = load i8*, i8** %11
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %11
%52 = load i32, i32* %9
%53 = load i32*, i32** %8
%54 = call i32 @fread(i8* %51, i32 1, i32 %52, i32* %53)
store i32 %54, i32* %12
%55 = load i32*, i32** %8
%56 = call i32 @fclose(i32* %55)
%57 = bitcast [6 x i8]* %13 to i8*
br label %58
58: ; preds = %63, %34
%59 = load i8*, i8** %11
%60 = getelementptr inbounds [6 x i8], [6 x i8]* %13, i64 0, i64 0
%61 = call i8* @strstr(i8* %59, i8* %60)
store i8* %61, i8** %14
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i8*, i8** %14
%65 = call i32 @strncpy(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
br label %58
66: ; preds = %58
%67 = getelementptr inbounds [500 x i8], [500 x i8]* %15, i64 0, i64 0
%68 = load i8*, i8** %7
%69 = call i32 @snprintf(i8* %67, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %68)
%70 = getelementptr inbounds [500 x i8], [500 x i8]* %15, i64 0, i64 0
%71 = call i32* @popen(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %71, i32** %16
%72 = load i8*, i8** %11
%73 = load i32, i32* %9
%74 = load i32*, i32** %16
%75 = call i32 @fwrite(i8* %72, i32 1, i32 %73, i32* %74)
%76 = load i8*, i8** %11
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %76)
%78 = load i32*, i32** %16
%79 = call i32 @pclose(i32* %78)
%80 = load i8*, i8** %11
%81 = call i32 @free(i8* %80)
br label %82
82: ; preds = %66, %32, %19
%83 = load i32, i32* %3
ret i32 %83
}

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
@__const.main.newDataType = [6 x i8] c"uint1\00"
@.str.3 = [6 x i8] c"char \00"
@.str.4 = [16 x i8] c"gcc -o %s -xc -\00"
@.str.5 = [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 %43
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 %43
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 = tail call i8* @strstr(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @__const.main.newDataType, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %35, label %30
30: ; preds = %16, %30
%31 = phi i8* [ %33, %30 ], [ %28, %16 ]
%32 = tail call i32 @strncpy(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%33 = tail call i8* @strstr(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @__const.main.newDataType, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %30
35: ; preds = %30, %16
%36 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%37 = call i32 @snprintf(i8* %36, i32 500, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%38 = call i32* @popen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @fwrite(i8* %23, i32 1, i32 %19, i32* %38)
%40 = call i32 @puts(i8* dereferenceable(1) %23)
%41 = call i32 @pclose(i32* %38)
%42 = call i32 @free(i8* %23)
br label %43
43: ; preds = %14, %35, %5
%44 = phi i32 [ 1, %5 ], [ 1, %14 ], [ 0, %35 ]
ret i32 %44
}