#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*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
void junction(const char *target, int argc, char **argv) {
  char *targetPath = malloc(strlen(target) + 3);
  strcpy(targetPath, argv[0]);
  strcat(targetPath, target);
  argv[0] = targetPath;
  execvp(targetPath, argv);
  fprintf(stderr, "Darling dyld multilib junction failed to execute %s!\n",
          targetPath);
  free(targetPath);
  exit(errno);
}


x86 assembly (clang, -O0):
<junction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <execvp@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<junction>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x3(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,(%r15)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <execvp@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"Darling dyld multilib junction failed to execute %s!\0A\00"
@errno = global i32 0
define void @junction(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 3
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @strcpy(i8* %12, i8* %15)
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i8* %17, i8* %18)
%20 = load i8*, i8** %7
%21 = load i8**, i8*** %6
%22 = getelementptr inbounds i8*, i8** %21, i64 0
store i8* %20, i8** %22
%23 = load i8*, i8** %7
%24 = load i8**, i8*** %6
%25 = call i32 @execvp(i8* %23, i8** %24)
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %7
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %7
%30 = call i32 @free(i8* %29)
%31 = load i32, i32* @errno
%32 = call i32 @exit(i32 %31)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"Darling dyld multilib junction failed to execute %s!\0A\00"
@errno = global i32 0
define void @junction(i8* %0, i32 %1, i8** %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 3
%6 = tail call i8* @malloc(i64 %5)
%7 = load i8*, i8** %2
%8 = tail call i32 @strcpy(i8* %6, i8* %7)
%9 = tail call i32 @strcat(i8* %6, i8* %0)
store i8* %6, i8** %2
%10 = tail call i32 @execvp(i8* %6, i8** %2)
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %6)
%13 = tail call i32 @free(i8* %6)
%14 = load i32, i32* @errno
%15 = tail call i32 @exit(i32 %14)
unreachable
}