#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*/ dirname(char *);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ execle(char *, char *, char *, char *, int /*<<< orphan*/ *,
                          char **);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
char *realpath(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
int main(int argc, char *argv[], char *envp[]) {
  char *cwd = NULL;
  char *full_path = NULL;
  char *full_profile_path = NULL;
  printf("Starting %s\n", "b2g-bin");
  cwd = realpath(dirname(argv[0]), NULL);
  full_path = (char *)malloc(strlen(cwd) + strlen("b2g-bin") + 2);
  if (!full_path) {
    error("Could not allocate enough memory");
    return -2;
  }
  full_profile_path = (char *)malloc(strlen(cwd) + strlen("gaia/profile") + 2);
  if (!full_profile_path) {
    error("Could not allocate enough memory");
    return -2;
  }
  sprintf(full_path, "%s/%s", cwd, "b2g-bin");
  sprintf(full_profile_path, "%s/%s", cwd, "gaia/profile");
  free(cwd);
  printf("Running: %s -profile %s\n", full_path, full_profile_path);
  fflush(stdout);
  fflush(stderr);
  execle(full_path, full_path, "-profile", full_profile_path, NULL, envp);
  error("unable to start");
  perror(argv[0]);
  free(full_path);
  free(full_profile_path);
  return -1;
}


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)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe17(%rip),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <dirname@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <realpath@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    0xde7(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1262 <main+0xb2>
lea    0xdc4(%rip),%rdi
call   10a0 <error@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1375 <main+0x1c5>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
lea    0xdc0(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12b2 <main+0x102>
lea    0xd74(%rip),%rdi
call   10a0 <error@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1375 <main+0x1c5>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd82(%rip),%rsi
lea    0xd45(%rip),%rcx
call   10c0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd67(%rip),%rsi
lea    0xd53(%rip),%rcx
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r9
lea    0xd28(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <execle@plt>
lea    0xd20(%rip),%rdi
call   10a0 <error@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-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    %rdx,%r14
mov    %rsi,%r15
lea    0xe38(%rip),%rdi
lea    0xe3e(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%rdi
call   1060 <dirname@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1070 <realpath@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x9(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     1219 <main+0x69>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
jne    1239 <main+0x89>
lea    0xdf5(%rip),%rdi
call   10a0 <error@plt>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%r12
lea    0xe00(%rip),%rbp
lea    0xdc3(%rip),%rcx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10c0 <sprintf@plt>
lea    0xdd7(%rip),%rcx
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdcd(%rip),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0xdb6(%rip),%rdx
mov    %r13,%rdi
mov    %r13,%rsi
mov    %r12,%rcx
xor    %r8d,%r8d
mov    %r14,%r9
call   10d0 <execle@plt>
lea    0xda4(%rip),%rdi
call   10a0 <error@plt>
mov    (%r15),%rdi
call   10b0 <perror@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
jmp    122a <main+0x7a>

LLVM IR (-O0):
@.str = [13 x i8] c"Starting %s\0A\00"
@.str.1 = [8 x i8] c"b2g-bin\00"
@.str.2 = [33 x i8] c"Could not allocate enough memory\00"
@.str.3 = [13 x i8] c"gaia/profile\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [25 x i8] c"Running: %s -profile %s\0A\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.6 = [9 x i8] c"-profile\00"
@.str.7 = [16 x i8] c"unable to start\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @dirname(i8* %14)
%16 = call i8* @realpath(i32 %15, i32* null)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = call i64 @strlen(i8* %17)
%19 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = add nsw i64 %18, %19
%21 = add nsw i64 %20, 2
%22 = call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %3
%27 = call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %4
br label %70
28: ; preds = %3
%29 = load i8*, i8** %8
%30 = call i64 @strlen(i8* %29)
%31 = call i64 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%32 = add nsw i64 %30, %31
%33 = add nsw i64 %32, 2
%34 = call i64 @malloc(i64 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = icmp ne i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %28
%39 = call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %4
br label %70
40: ; preds = %28
%41 = load i8*, i8** %9
%42 = load i8*, i8** %8
%43 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%44 = load i8*, i8** %10
%45 = load i8*, i8** %8
%46 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %45, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
%49 = load i8*, i8** %9
%50 = load i8*, i8** %10
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %49, i8* %50)
%52 = load i32, i32* @stdout
%53 = call i32 @fflush(i32 %52)
%54 = load i32, i32* @stderr
%55 = call i32 @fflush(i32 %54)
%56 = load i8*, i8** %9
%57 = load i8*, i8** %9
%58 = load i8*, i8** %10
%59 = load i8**, i8*** %7
%60 = call i32 @execle(i8* %56, i8* %57, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %58, i32* null, i8** %59)
%61 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%62 = load i8**, i8*** %6
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i32 @perror(i8* %64)
%66 = load i8*, i8** %9
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %10
%69 = call i32 @free(i8* %68)
store i32 -1, i32* %4
br label %70
70: ; preds = %40, %38, %26
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [13 x i8] c"Starting %s\0A\00"
@.str.1 = [8 x i8] c"b2g-bin\00"
@.str.2 = [33 x i8] c"Could not allocate enough memory\00"
@.str.3 = [13 x i8] c"gaia/profile\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [25 x i8] c"Running: %s -profile %s\0A\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.6 = [9 x i8] c"-profile\00"
@.str.7 = [16 x i8] c"unable to start\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** %2) {
%4 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = load i8*, i8** %1
%6 = tail call i32 @dirname(i8* %5)
%7 = tail call i8* @realpath(i32 %6, i32* null)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%9 = add nsw i64 %8, 9
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %38
15: ; preds = %3
%16 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%17 = add nsw i64 %16, 14
%18 = tail call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
%20 = icmp eq i64 %18, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = tail call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %38
23: ; preds = %15
%24 = tail call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%26 = tail call i32 @free(i8* %7)
%27 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %11, i8* %19)
%28 = load i32, i32* @stdout
%29 = tail call i32 @fflush(i32 %28)
%30 = load i32, i32* @stderr
%31 = tail call i32 @fflush(i32 %30)
%32 = tail call i32 @execle(i8* %11, i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %19, i32* null, i8** %2)
%33 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%34 = load i8*, i8** %1
%35 = tail call i32 @perror(i8* %34)
%36 = tail call i32 @free(i8* %11)
%37 = tail call i32 @free(i8* %19)
br label %38
38: ; preds = %23, %21, %13
%39 = phi i32 [ -1, %23 ], [ -2, %21 ], [ -2, %13 ]
ret i32 %39
}