#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int system(char *);
int cb_compile_cxx(const char *cmd, const char *code) {
  char srcpath[1024];
  sprintf(srcpath, "/tmp/codebomb_compilation.cpp");
  char binpath[1024];
  sprintf(binpath, "/tmp/codebomb_compilation.bin");
  FILE *f = fopen(srcpath, "w");
  fprintf(f, "%s\n", code);
  fclose(f);
  char cmdline[1024];
  sprintf(cmdline, "%s %s -o %s", cmd, srcpath, binpath);
  int e = system(cmdline);
  return (e != 0);
}


x86 assembly (clang, -O0):
<cb_compile_cxx>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x810(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x818(%rbp)
mov    -0x818(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x818(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0xc20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x410(%rbp),%rcx
lea    -0x810(%rbp),%r8
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0xc20(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0xc24(%rbp)
cmpl   $0x0,-0xc24(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0xc30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cb_compile_cxx>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc08,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
movups 0xea3(%rip),%xmm0
movups %xmm0,0x40e(%rsp)
movups 0xe86(%rip),%xmm0
movaps %xmm0,0x400(%rsp)
movups 0xea3(%rip),%xmm0
movups %xmm0,0xe(%rsp)
movups 0xe89(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe9c(%rip),%rsi
lea    0x400(%rsp),%r15
mov    %r15,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe6e(%rip),%rsi
lea    0x800(%rsp),%rbx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
mov    %ecx,%eax
add    $0xc08,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/tmp/codebomb_compilation.cpp\00"
@.str.1 = [30 x i8] c"/tmp/codebomb_compilation.bin\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [12 x i8] c"%s %s -o %s\00"
define i32 @cb_compile_cxx(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = load i8*, i8** %4
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %22, i8* %23, i8* %24)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = call i32 @system(i8* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i32
ret i32 %30
}

LLVM IR (-O2):
@.str = [30 x i8] c"/tmp/codebomb_compilation.cpp\00"
@.str.1 = [30 x i8] c"/tmp/codebomb_compilation.bin\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [12 x i8] c"%s %s -o %s\00"
define i32 @cb_compile_cxx(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%10 = tail call i32 @fclose(i32* %8)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %6, i8* %7)
%13 = call i32 @system(i8* %11)
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
ret i32 %15
}