#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 PATH_MAX;
int /*<<< orphan*/ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  char prog[PATH_MAX];
  int len;
  strcpy(prog, argv[0]);
  len = strlen(prog);
  memcpy(prog + len - 15, "multi-arch-exec-hello", 21);
  prog[len + 6] = 0;
  execl(prog, prog, (char *)NULL);
  perror("execl failed");
  exit(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    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffff1,%rdi
lea    0xe30(%rip),%rsi
mov    $0x15,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%eax
add    $0x6,%eax
cltq
movb   $0x0,(%rsi,%rax,1)
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1080 <execl@plt>
lea    0xe19(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rsi),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
lea    (%r14,%rbx,1),%rdi
add    $0xfffffffffffffff1,%rdi
lea    0xe5a(%rip),%rsi
mov    $0x15,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x6(%r14,%rbx,1)
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
lea    0xe4c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [22 x i8] c"multi-arch-exec-hello\00"
@.str.1 = [13 x i8] c"execl failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @strcpy(i8* %12, i8* %15)
%17 = call i32 @strlen(i8* %12)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %12, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 -15
%22 = call i32 @memcpy(i8* %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 21)
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %12, i64 %25
store i8 0, i8* %26
%27 = call i32 @execl(i8* %12, i8* %12, i8* null)
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [22 x i8] c"multi-arch-exec-hello\00"
@.str.1 = [13 x i8] c"execl failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i8*, i8** %1
%7 = call i32 @strcpy(i8* %5, i8* %6)
%8 = call i32 @strlen(i8* %5)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %5, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -15
%12 = call i32 @memcpy(i8* %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 21)
%13 = add nsw i32 %8, 6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %5, i64 %14
store i8 0, i8* %15
%16 = call i32 @execl(i8* %5, i8* %5, i8* null)
%17 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
}