#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 */

/* Variables and functions */
int /*<<< orphan*/ clean_cache_dir(char *);
int /*<<< orphan*/ free(char *);
char *join(char **, int, char *);
char *random_cache_dir();
int run_dex(char *, char *, char *);
int system(char *);
int run_java(char *java, char *main_class, char *parameters) {
  int status;
  char *cache_dir = random_cache_dir();
  char *ecj_strs[4] = {"ecj", java, "-d", cache_dir};
  char *ecj_cmd = join(ecj_strs, 4, " ");
  status = system(ecj_cmd);
  free(ecj_cmd);
  if (status != 0) {
    clean_cache_dir(cache_dir);
    return status;
  }
  char *dx_strs[3] = {"cd ", cache_dir,
                      " && dx --dex --output=run.dex *.class"};
  char *dx_cmd = join(dx_strs, 3, "");
  status = system(dx_cmd);
  free(dx_cmd);
  if (status != 0) {
    clean_cache_dir(cache_dir);
    return status;
  }
  char *dex_strs[2] = {cache_dir, "run.dex"};
  char *dex_name = join(dex_strs, 2, "");
  status = run_dex(dex_name, main_class, parameters);
  free(dex_name);
  clean_cache_dir(cache_dir);
  return status;
}


x86 assembly (clang, -O0):
<run_java>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1070 <random_cache_dir@plt>
mov    %rax,-0x30(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe68(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x4,%esi
lea    0xe51(%rip),%rdx
call   1080 <join@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x24(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
je     11f4 <run_java+0x94>
mov    -0x30(%rbp),%rdi
call   1060 <clean_cache_dir@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12c8 <run_java+0x168>
lea    0xe0c(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xdfd(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x3,%esi
lea    0xde8(%rip),%rdx
call   1080 <join@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x24(%rbp)
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
je     125e <run_java+0xfe>
mov    -0x30(%rbp),%rdi
call   1060 <clean_cache_dir@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12c8 <run_java+0x168>
mov    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    0xdc1(%rip),%rax
mov    %rax,-0x88(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x2,%esi
lea    0xd80(%rip),%rdx
call   1080 <join@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <run_dex@plt>
mov    %eax,-0x24(%rbp)
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1060 <clean_cache_dir@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_java>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %eax,%eax
call   1070 <random_cache_dir@plt>
mov    %rax,%r12
lea    0xe7a(%rip),%rax
mov    %rax,0x30(%rsp)
mov    %rbp,0x38(%rsp)
lea    0xe6d(%rip),%rax
mov    %rax,0x40(%rsp)
mov    %r12,0x48(%rsp)
lea    0xe61(%rip),%rdx
lea    0x30(%rsp),%rdi
mov    $0x4,%esi
call   1080 <join@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <system@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
jne    125f <run_java+0xff>
lea    0xe2c(%rip),%rax
mov    %rax,0x10(%rsp)
mov    %r12,0x18(%rsp)
lea    0xe1f(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe12(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x3,%esi
call   1080 <join@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <system@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
jne    125f <run_java+0xff>
mov    %r12,(%rsp)
lea    0xe06(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xdd3(%rip),%rdx
mov    %rsp,%rdi
mov    $0x2,%esi
call   1080 <join@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <run_dex@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1060 <clean_cache_dir@plt>
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ecj\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"cd \00"
@.str.4 = [38 x i8] c" && dx --dex --output=run.dex *.class\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [8 x i8] c"run.dex\00"
define i32 @run_java(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [4 x i8*]
%11 = alloca i8*
%12 = alloca [3 x i8*]
%13 = alloca i8*
%14 = alloca [2 x i8*]
%15 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%16 = call i8* (...) @random_cache_dir()
store i8* %16, i8** %9
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %5
store i8* %19, i8** %18
%20 = getelementptr inbounds i8*, i8** %18, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %9
store i8* %22, i8** %21
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 0
%24 = call i8* @join(i8** %23, i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %24, i8** %11
%25 = load i8*, i8** %11
%26 = call i32 @system(i8* %25)
store i32 %26, i32* %8
%27 = load i8*, i8** %11
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %3
%32 = load i8*, i8** %9
%33 = call i32 @clean_cache_dir(i8* %32)
%34 = load i32, i32* %8
store i32 %34, i32* %4
br label %67
35: ; preds = %3
%36 = getelementptr inbounds [3 x i8*], [3 x i8*]* %12, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %36
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %9
store i8* %38, i8** %37
%39 = getelementptr inbounds i8*, i8** %37, i64 1
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8** %39
%40 = getelementptr inbounds [3 x i8*], [3 x i8*]* %12, i64 0, i64 0
%41 = call i8* @join(i8** %40, i32 3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
store i8* %41, i8** %13
%42 = load i8*, i8** %13
%43 = call i32 @system(i8* %42)
store i32 %43, i32* %8
%44 = load i8*, i8** %13
%45 = call i32 @free(i8* %44)
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %35
%49 = load i8*, i8** %9
%50 = call i32 @clean_cache_dir(i8* %49)
%51 = load i32, i32* %8
store i32 %51, i32* %4
br label %67
52: ; preds = %35
%53 = getelementptr inbounds [2 x i8*], [2 x i8*]* %14, i64 0, i64 0
%54 = load i8*, i8** %9
store i8* %54, i8** %53
%55 = getelementptr inbounds i8*, i8** %53, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %55
%56 = getelementptr inbounds [2 x i8*], [2 x i8*]* %14, i64 0, i64 0
%57 = call i8* @join(i8** %56, i32 2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
store i8* %57, i8** %15
%58 = load i8*, i8** %15
%59 = load i8*, i8** %6
%60 = load i8*, i8** %7
%61 = call i32 @run_dex(i8* %58, i8* %59, i8* %60)
store i32 %61, i32* %8
%62 = load i8*, i8** %15
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %9
%65 = call i32 @clean_cache_dir(i8* %64)
%66 = load i32, i32* %8
store i32 %66, i32* %4
br label %67
67: ; preds = %52, %48, %31
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
@.str = [4 x i8] c"ecj\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"cd \00"
@.str.4 = [38 x i8] c" && dx --dex --output=run.dex *.class\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [8 x i8] c"run.dex\00"
define i32 @run_java(i8* %0, i8* %1, i8* %2) {
%4 = alloca [4 x i8*]
%5 = alloca [3 x i8*]
%6 = alloca [2 x i8*]
%7 = tail call i8* (...) @random_cache_dir()
%8 = bitcast [4 x i8*]* %4 to i8*
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 1
store i8* %0, i8** %10
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 3
store i8* %7, i8** %12
%13 = call i8* @join(i8** %9, i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @system(i8* %13)
%15 = call i32 @free(i8* %13)
%16 = icmp eq i32 %14, 0
br i1 %16, label %19, label %17
17: ; preds = %3
%18 = call i32 @clean_cache_dir(i8* %7)
br label %40
19: ; preds = %3
%20 = bitcast [3 x i8*]* %5 to i8*
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 1
store i8* %7, i8** %22
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 2
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8** %23
%24 = call i8* @join(i8** %21, i32 3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 @system(i8* %24)
%26 = call i32 @free(i8* %24)
%27 = icmp eq i32 %25, 0
br i1 %27, label %30, label %28
28: ; preds = %19
%29 = call i32 @clean_cache_dir(i8* %7)
br label %38
30: ; preds = %19
%31 = bitcast [2 x i8*]* %6 to i8*
%32 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
store i8* %7, i8** %32
%33 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %33
%34 = call i8* @join(i8** %32, i32 2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @run_dex(i8* %34, i8* %1, i8* %2)
%36 = call i32 @free(i8* %34)
%37 = call i32 @clean_cache_dir(i8* %7)
br label %38
38: ; preds = %30, %28
%39 = phi i32 [ %25, %28 ], [ %35, %30 ]
br label %40
40: ; preds = %38, %17
%41 = phi i32 [ %14, %17 ], [ %39, %38 ]
ret i32 %41
}