#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 */
char **calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ ship_execute(char *, char **, int);
char *ship_find_base_folder();
char *ship_find_jvm_path(char *);
char *ship_find_launcher_jar_path(char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s [args]\n", argv[0]);
    return 1;
  }
  char *baseFolder = ship_find_base_folder();
  char *jvmPath = ship_find_jvm_path(baseFolder);
  char **args = calloc(512, sizeof(char *));
  int argIndex = 0;
  args[argIndex++] = jvmPath;
  args[argIndex++] = "-jar";
  args[argIndex++] = ship_find_launcher_jar_path(baseFolder);
  args[argIndex++] = jvmPath;
  args[argIndex++] = baseFolder;
  for (int i = 1; i < argc; ++i)
    args[argIndex++] = strdup(argv[i]);
  args[argIndex] = NULL;
  const char *debug = getenv("SHIP_LAUNCHER_DEBUG");
  if (debug) {
    fprintf(stderr, "ship: executing:");
    for (int i = 0; i < argIndex; ++i)
      fprintf(stderr, " '%s'", args[i]);
    fprintf(stderr, "\n");
  }
  ship_execute(jvmPath, args, argIndex);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ca <main+0x4a>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1388 <main+0x208>
mov    $0x0,%al
call   1090 <ship_find_base_folder@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <ship_find_jvm_path@plt>
mov    %rax,-0x20(%rbp)
mov    $0x200,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
lea    0xde3(%rip),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdi
call   1040 <ship_find_launcher_jar_path@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d4 <main+0x154>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1290 <main+0x110>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
lea    0xd2c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1371 <main+0x1f1>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    135a <main+0x1da>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xcf7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    131d <main+0x19d>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
lea    0xca6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <ship_execute@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
cmp    $0x1,%edi
jg     11b8 <main+0x38>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe59(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    12ad <main+0x12d>
mov    %edi,%r15d
xor    %eax,%eax
call   1090 <ship_find_base_folder@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <ship_find_jvm_path@plt>
mov    %rax,%r14
mov    $0x200,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %r14,(%rax)
lea    0xe26(%rip),%rax
mov    %rax,0x8(%rbx)
mov    %r13,%rdi
call   1040 <ship_find_launcher_jar_path@plt>
mov    %rax,0x10(%rbx)
mov    %r14,0x18(%rbx)
mov    %r13,0x20(%rbx)
add    $0x4,%r15d
mov    $0x5,%ebp
nopl   (%rax)
mov    -0x20(%r12,%rbp,8),%rdi
call   10a0 <strdup@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1210 <main+0x90>
movq   $0x0,(%rbx,%r15,8)
lea    0xde1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     129d <main+0x11d>
mov    0x2d99(%rip),%r13
mov    0x0(%r13),%edi
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xddc(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%edi
mov    (%rbx,%rbp,8),%rdx
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1270 <main+0xf0>
mov    0x0(%r13),%edi
lea    0xd7a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <ship_execute@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s [args]\0A\00"
@.str.1 = [5 x i8] c"-jar\00"
@.str.2 = [20 x i8] c"SHIP_LAUNCHER_DEBUG\00"
@.str.3 = [17 x i8] c"ship: executing:\00"
@.str.4 = [6 x i8] c" '%s'\00"
@.str.5 = [2 x i8] c"\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 i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %109
21: ; preds = %2
%22 = call i8* (...) @ship_find_base_folder()
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = call i8* @ship_find_jvm_path(i8* %23)
store i8* %24, i8** %7
%25 = call i8** @calloc(i32 512, i32 8)
store i8** %25, i8*** %8
store i32 0, i32* %9
%26 = load i8*, i8** %7
%27 = load i8**, i8*** %8
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
store i8* %26, i8** %31
%32 = load i8**, i8*** %8
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8*, i8** %32, i64 %35
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %36
%37 = load i8*, i8** %6
%38 = call i8* @ship_find_launcher_jar_path(i8* %37)
%39 = load i8**, i8*** %8
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8*, i8** %39, i64 %42
store i8* %38, i8** %43
%44 = load i8*, i8** %7
%45 = load i8**, i8*** %8
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8*, i8** %45, i64 %48
store i8* %44, i8** %49
%50 = load i8*, i8** %6
%51 = load i8**, i8*** %8
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8*, i8** %51, i64 %54
store i8* %50, i8** %55
store i32 1, i32* %10
br label %56
56: ; preds = %72, %21
%57 = load i32, i32* %10
%58 = load i32, i32* %4
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %75
60: ; preds = %56
%61 = load i8**, i8*** %5
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i8* @strdup(i8* %65)
%67 = load i8**, i8*** %8
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
%70 = sext i32 %68 to i64
%71 = getelementptr inbounds i8*, i8** %67, i64 %70
store i8* %66, i8** %71
br label %72
72: ; preds = %60
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %56
75: ; preds = %56
%76 = load i8**, i8*** %8
%77 = load i32, i32* %9
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
store i8* null, i8** %79
%80 = call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i8* %80, i8** %11
%81 = load i8*, i8** %11
%82 = icmp ne i8* %81, null
br i1 %82, label %83, label %104
83: ; preds = %75
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %12
br label %86
86: ; preds = %98, %83
%87 = load i32, i32* %12
%88 = load i32, i32* %9
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %101
90: ; preds = %86
%91 = load i32, i32* @stderr
%92 = load i8**, i8*** %8
%93 = load i32, i32* %12
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8*, i8** %92, i64 %94
%96 = load i8*, i8** %95
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %96)
br label %98
98: ; preds = %90
%99 = load i32, i32* %12
%100 = add nsw i32 %99, 1
store i32 %100, i32* %12
br label %86
101: ; preds = %86
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %104
104: ; preds = %101, %75
%105 = load i8*, i8** %7
%106 = load i8**, i8*** %8
%107 = load i32, i32* %9
%108 = call i32 @ship_execute(i8* %105, i8** %106, i32 %107)
store i32 0, i32* %3
br label %109
109: ; preds = %104, %15
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s [args]\0A\00"
@.str.1 = [5 x i8] c"-jar\00"
@.str.2 = [20 x i8] c"SHIP_LAUNCHER_DEBUG\00"
@.str.3 = [17 x i8] c"ship: executing:\00"
@.str.4 = [6 x i8] c" '%s'\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %50
8: ; preds = %2
%9 = tail call i8* (...) @ship_find_base_folder()
%10 = tail call i8* @ship_find_jvm_path(i8* %9)
%11 = tail call i8** @calloc(i32 512, i32 8)
store i8* %10, i8** %11
%12 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %12
%13 = tail call i8* @ship_find_launcher_jar_path(i8* %9)
%14 = getelementptr inbounds i8*, i8** %11, i64 2
store i8* %13, i8** %14
%15 = getelementptr inbounds i8*, i8** %11, i64 3
store i8* %10, i8** %15
%16 = getelementptr inbounds i8*, i8** %11, i64 4
store i8* %9, i8** %16
%17 = add nuw i32 %0, 4
%18 = zext i32 %17 to i64
br label %24
19: ; preds = %24
%20 = zext i32 %17 to i64
%21 = getelementptr inbounds i8*, i8** %11, i64 %20
store i8* null, i8** %21
%22 = tail call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %48, label %34
24: ; preds = %8, %24
%25 = phi i64 [ 5, %8 ], [ %30, %24 ]
%26 = phi i64 [ 1, %8 ], [ %32, %24 ]
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i8* @strdup(i8* %28)
%30 = add nuw nsw i64 %25, 1
%31 = getelementptr inbounds i8*, i8** %11, i64 %25
store i8* %29, i8** %31
%32 = add nuw nsw i64 %26, 1
%33 = icmp eq i64 %30, %18
br i1 %33, label %19, label %24
34: ; preds = %19
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %40
37: ; preds = %40
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %48
40: ; preds = %34, %40
%41 = phi i64 [ 0, %34 ], [ %46, %40 ]
%42 = load i32, i32* @stderr
%43 = getelementptr inbounds i8*, i8** %11, i64 %41
%44 = load i8*, i8** %43
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = add nuw nsw i64 %41, 1
%47 = icmp eq i64 %46, %20
br i1 %47, label %37, label %40
48: ; preds = %37, %19
%49 = tail call i32 @ship_execute(i8* %10, i8** %11, i32 %17)
br label %50
50: ; preds = %48, %4
%51 = phi i32 [ 1, %4 ], [ 0, %48 ]
ret i32 %51
}