#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*/ execvp(char *, char **);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int const);
int main(int argc, char **argv) {
  const int prefixLength = strlen(argv[0]) - strlen("xcrun");
  char *toolPath = calloc(prefixLength + strlen(argv[1]), sizeof(char));
  strncpy(toolPath, argv[0], prefixLength);
  strcpy(toolPath + prefixLength, argv[1]);
  argv++;
  argv[0] = toolPath;
  execvp(argv[0], argv);
  printf("Failed to execute program %s\n", argv[0]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
lea    0xe74(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
add    %eax,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <execvp@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde5(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    (%rsi),%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0xe83(%rip),%rdi
call   1050 <strlen@plt>
sub    %eax,%r12d
lea    0x8(%r15),%r14
mov    0x8(%r15),%rdi
call   1050 <strlen@plt>
lea    (%rax,%r12,1),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    (%r15),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movslq %r12d,%rdi
add    %rbx,%rdi
mov    0x8(%r15),%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x8(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <execvp@plt>
mov    0x8(%r15),%rsi
lea    0xe2c(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"xcrun\00"
@.str.1 = [30 x i8] c"Failed to execute program %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %14, %18
%20 = call i8* @calloc(i32 %19, i32 1)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = load i32, i32* %6
%26 = call i32 @strncpy(i8* %21, i8* %24, i32 %25)
%27 = load i8*, i8** %7
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %30, i8* %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i32 1
store i8** %36, i8*** %5
%37 = load i8*, i8** %7
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
store i8* %37, i8** %39
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %5
%44 = call i32 @execvp(i8* %42, i8** %43)
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %47)
ret i32 1
}

LLVM IR (-O2):
@.str = [6 x i8] c"xcrun\00"
@.str.1 = [30 x i8] c"Failed to execute program %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @strlen(i8* %3)
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = sub nsw i32 %4, %5
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, %6
%11 = tail call i8* @calloc(i32 %10, i32 1)
%12 = load i8*, i8** %1
%13 = tail call i32 @strncpy(i8* %11, i8* %12, i32 %6)
%14 = sext i32 %6 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8*, i8** %7
%17 = tail call i32 @strcpy(i8* %15, i8* %16)
store i8* %11, i8** %7
%18 = tail call i32 @execvp(i8* %11, i8** %7)
%19 = load i8*, i8** %7
%20 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %19)
ret i32 1
}