#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*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putenv(char *);
int main(int argc, char **argv) {
  putenv("LD_PRELOAD="
         "shmoverride.so");
  if (access("/usr/libexec/Xorg.bin", X_OK) == 0)
    execv("/usr/libexec/Xorg.bin", argv);
  else
    execv("/usr/bin/Xorg", argv);
  perror("X-wrapper-qubes: execv");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <putenv@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    1196 <main+0x56>
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1060 <execv@plt>
jmp    11a6 <main+0x66>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1060 <execv@plt>
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xeb2(%rip),%rdi
call   1030 <putenv@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rbx
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
lea    0xebb(%rip),%rdi
cmove  %rbx,%rdi
mov    %r14,%rsi
call   1060 <execv@plt>
lea    0xeb6(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"LD_PRELOAD=shmoverride.so\00"
@.str.1 = [22 x i8] c"/usr/libexec/Xorg.bin\00"
@X_OK = global i32 0
@.str.2 = [14 x i8] c"/usr/bin/Xorg\00"
@.str.3 = [23 x i8] c"X-wrapper-qubes: execv\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @putenv(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @X_OK
%8 = call i64 @access(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = call i32 @execv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %11)
br label %16
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %14)
br label %16
16: ; preds = %13, %10
%17 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [26 x i8] c"LD_PRELOAD=shmoverride.so\00"
@.str.1 = [22 x i8] c"/usr/libexec/Xorg.bin\00"
@X_OK = global i32 0
@.str.2 = [14 x i8] c"/usr/bin/Xorg\00"
@.str.3 = [23 x i8] c"X-wrapper-qubes: execv\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @putenv(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @X_OK
%5 = tail call i64 @access(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 @execv(i8* %7, i8** %1)
%9 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}