#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 *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ *stdout;
int strlen(char *);
int /*<<< orphan*/ system(char *);
char *tempnam(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ unlink(char *);
void jit_dump_code(unsigned char *buf, int buf_size) {
  int i;
  FILE *f = stdout;
  char *source_file_name = tempnam(NULL, "myjit");
  char *obj_file_name = tempnam(NULL, "myjit");
  char *cmd1_fmt = "gcc -x assembler -c -o %s %s";
  char
      cmd1[strlen(cmd1_fmt) + strlen(source_file_name) + strlen(obj_file_name)];
  char *cmd2_fmt = "objdump -d -M intel %s";
  char cmd2[strlen(cmd2_fmt) + strlen(obj_file_name)];
  f = fopen(source_file_name, "w");
  fprintf(f, ".text\n.align 4\n.globl main\n.type main,@function\nmain:\n");
  for (i = 0; i < buf_size; i++)
    fprintf(f, ".byte %d\n", (unsigned int)buf[i]);
  fclose(f);
  sprintf(cmd1, cmd1_fmt, obj_file_name, source_file_name);
  system(cmd1);
  sprintf(cmd2, cmd2_fmt, obj_file_name);
  system(cmd2);
  unlink(source_file_name);
  unlink(obj_file_name);
  free(source_file_name);
  free(obj_file_name);
}


x86 assembly (clang, -O0):
<jit_dump_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe49(%rip),%rsi
mov    %rsi,-0x78(%rbp)
xor    %eax,%eax
mov    %eax,%edi
mov    %rdi,-0x80(%rbp)
call   1090 <tempnam@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %rax,-0x20(%rbp)
call   1090 <tempnam@plt>
mov    %rax,-0x28(%rbp)
lea    0xe22(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
add    %ecx,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
lea    0xde2(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
add    %ecx,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12e2 <jit_dump_code+0x152>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12aa <jit_dump_code+0x11a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x68(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x68(%rbp),%rdi
call   1070 <system@plt>
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x58(%rbp),%rdi
call   1070 <system@plt>
mov    -0x20(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x28(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jit_dump_code>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,-0x2c(%rbp)
mov    %rdi,%rbx
lea    0xe42(%rip),%r14
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <tempnam@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <tempnam@plt>
mov    %rax,%r13
lea    0xe27(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
add    %r14d,%r15d
mov    %r13,%rdi
call   1060 <strlen@plt>
add    %r15d,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
lea    0xe07(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %r13,-0x48(%rbp)
mov    %r13,%rdi
call   1060 <strlen@plt>
add    %r14d,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
lea    0xdeb(%rip),%rsi
mov    %r12,-0x50(%rbp)
mov    %r12,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xdd7(%rip),%rdi
mov    $0x36,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    12ab <jit_dump_code+0x10b>
mov    %eax,%r13d
lea    0xdeb(%rip),%r15
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%r12,1),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r13
jne    1290 <jit_dump_code+0xf0>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd4c(%rip),%rsi
mov    -0x40(%rbp),%rbx
mov    %rbx,%rdi
mov    -0x48(%rbp),%r15
mov    %r15,%rdx
mov    -0x50(%rbp),%r14
mov    %r14,%rcx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0xd3e(%rip),%rsi
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    %r15,%rdi
call   1040 <unlink@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@stdout = global i32* null
@.str = [6 x i8] c"myjit\00"
@.str.1 = [29 x i8] c"gcc -x assembler -c -o %s %s\00"
@.str.2 = [23 x i8] c"objdump -d -M intel %s\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [55 x i8] c".text\0A.align 4\0A.globl main\0A.type main,@function\0Amain:\0A\00"
@.str.5 = [10 x i8] c".byte %d\0A\00"
define void @jit_dump_code(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%14 = load i32*, i32** @stdout
store i32* %14, i32** %6
%15 = call i8* @tempnam(i32* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %7
%16 = call i8* @tempnam(i32* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %8
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8** %9
%17 = load i8*, i8** %9
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %7
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = load i8*, i8** %8
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %21, %23
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %10
%27 = alloca i8, i64 %25
store i64 %25, i64* %11
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %12
%28 = load i8*, i8** %12
%29 = call i32 @strlen(i8* %28)
%30 = load i8*, i8** %8
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %29, %31
%33 = zext i32 %32 to i64
%34 = alloca i8, i64 %33
store i64 %33, i64* %13
%35 = load i8*, i8** %7
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %6
%37 = load i32*, i32** %6
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %39
39: ; preds = %52, %2
%40 = load i32, i32* %5
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = load i32*, i32** %6
%45 = load i8*, i8** %3
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %43
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %39
55: ; preds = %39
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
%58 = load i8*, i8** %9
%59 = load i8*, i8** %8
%60 = load i8*, i8** %7
%61 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %27, i8* %58, i8* %59, i8* %60)
%62 = call i32 @system(i8* %27)
%63 = load i8*, i8** %12
%64 = load i8*, i8** %8
%65 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* %63, i8* %64)
%66 = call i32 @system(i8* %34)
%67 = load i8*, i8** %7
%68 = call i32 @unlink(i8* %67)
%69 = load i8*, i8** %8
%70 = call i32 @unlink(i8* %69)
%71 = load i8*, i8** %7
%72 = call i32 @free(i8* %71)
%73 = load i8*, i8** %8
%74 = call i32 @free(i8* %73)
%75 = load i8*, i8** %10
ret void
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [6 x i8] c"myjit\00"
@.str.1 = [29 x i8] c"gcc -x assembler -c -o %s %s\00"
@.str.2 = [23 x i8] c"objdump -d -M intel %s\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [55 x i8] c".text\0A.align 4\0A.globl main\0A.type main,@function\0Amain:\0A\00"
@.str.5 = [10 x i8] c".byte %d\0A\00"
define void @jit_dump_code(i8* nocapture %0, i32 %1) {
%3 = tail call i8* @tempnam(i32* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @tempnam(i32* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %3)
%7 = add nsw i32 %6, %5
%8 = tail call i32 @strlen(i8* %4)
%9 = add nsw i32 %7, %8
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @strlen(i8* %4)
%14 = add nsw i32 %13, %12
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
%17 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i64 54, i64 1, i32* %17)
%19 = icmp sgt i32 %1, 0
br i1 %19, label %20, label %30
20: ; preds = %2
%21 = zext i32 %1 to i64
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %28, %22 ]
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = add nuw nsw i64 %23, 1
%29 = icmp eq i64 %28, %21
br i1 %29, label %30, label %22
30: ; preds = %22, %2
%31 = tail call i32 @fclose(i32* %17)
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %3)
%33 = call i32 @system(i8* %11)
%34 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%35 = call i32 @system(i8* %16)
%36 = tail call i32 @unlink(i8* %3)
%37 = tail call i32 @unlink(i8* %4)
%38 = tail call i32 @free(i8* %3)
%39 = tail call i32 @free(i8* %4)
ret void
}