#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) {
    free(full_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    137e <main+0x1ce>
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    12bb <main+0x10b>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xd6b(%rip),%rdi
call   10a0 <error@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    137e <main+0x1ce>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd79(%rip),%rsi
lea    0xd3c(%rip),%rcx
call   10c0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd5e(%rip),%rsi
lea    0xd4a(%rip),%rcx
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2cbb(%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    0xd20(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <execle@plt>
lea    0xd18(%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     1221 <main+0x71>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
jne    1241 <main+0x91>
mov    %r13,%rdi
call   1030 <free@plt>
lea    0xded(%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    0xdf8(%rip),%rbp
lea    0xdbb(%rip),%rcx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10c0 <sprintf@plt>
lea    0xdcf(%rip),%rcx
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdc5(%rip),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0xdaf(%rip),%rdx
mov    %r13,%rdi
mov    %r13,%rsi
mov    %r12,%rcx
xor    %r8d,%r8d
mov    %r14,%r9
call   10d0 <execle@plt>
lea    0xd9d(%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    1232 <main+0x82>

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 = [26 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 %72
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 %42, label %38
38: ; preds = %28
%39 = load i8*, i8** %9
%40 = call i32 @free(i8* %39)
%41 = 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 %72
42: ; preds = %28
%43 = load i8*, i8** %9
%44 = load i8*, i8** %8
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%46 = load i8*, i8** %10
%47 = load i8*, i8** %8
%48 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%49 = load i8*, i8** %8
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %9
%52 = load i8*, i8** %10
%53 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %51, i8* %52)
%54 = load i32, i32* @stdout
%55 = call i32 @fflush(i32 %54)
%56 = load i32, i32* @stderr
%57 = call i32 @fflush(i32 %56)
%58 = load i8*, i8** %9
%59 = load i8*, i8** %9
%60 = load i8*, i8** %10
%61 = load i8**, i8*** %7
%62 = call i32 @execle(i8* %58, i8* %59, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %60, i32* null, i8** %61)
%63 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%64 = load i8**, i8*** %6
%65 = getelementptr inbounds i8*, i8** %64, i64 0
%66 = load i8*, i8** %65
%67 = call i32 @perror(i8* %66)
%68 = load i8*, i8** %9
%69 = call i32 @free(i8* %68)
%70 = load i8*, i8** %10
%71 = call i32 @free(i8* %70)
store i32 -1, i32* %4
br label %72
72: ; preds = %42, %38, %26
%73 = load i32, i32* %4
ret i32 %73
}

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 = [26 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 %39
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 %24
21: ; preds = %15
%22 = tail call i32 @free(i8* %11)
%23 = tail call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %39
24: ; preds = %15
%25 = 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))
%26 = 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))
%27 = tail call i32 @free(i8* %7)
%28 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %11, i8* %19)
%29 = load i32, i32* @stdout
%30 = tail call i32 @fflush(i32 %29)
%31 = load i32, i32* @stderr
%32 = tail call i32 @fflush(i32 %31)
%33 = 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)
%34 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%35 = load i8*, i8** %1
%36 = tail call i32 @perror(i8* %35)
%37 = tail call i32 @free(i8* %11)
%38 = tail call i32 @free(i8* %19)
br label %39
39: ; preds = %24, %21, %13
%40 = phi i32 [ -1, %24 ], [ -2, %21 ], [ -2, %13 ]
ret i32 %40
}