#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", X_OK) == 0)
    execv("/usr/libexec/Xorg", argv);
  else 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    11df <main+0x9f>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    11ca <main+0x8a>
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1060 <execv@plt>
jmp    11da <main+0x9a>
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1060 <execv@plt>
jmp    11df <main+0x9f>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xeb1(%rip),%rdi
call   1030 <putenv@plt>
mov    0x2e8d(%rip),%r15
mov    (%r15),%esi
lea    0xeb5(%rip),%rbx
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
je     1192 <main+0x52>
mov    (%r15),%esi
lea    0xeb0(%rip),%r15
mov    %r15,%rdi
call   1040 <access@plt>
test   %rax,%rax
lea    0xeb4(%rip),%rbx
cmove  %r15,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <execv@plt>
lea    0xeac(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"LD_PRELOAD=shmoverride.so\00"
@.str.1 = [18 x i8] c"/usr/libexec/Xorg\00"
@X_OK = global i32 0
@.str.2 = [22 x i8] c"/usr/libexec/Xorg.bin\00"
@.str.3 = [14 x i8] c"/usr/bin/Xorg\00"
@.str.4 = [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 ([18 x i8], [18 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 ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %11)
br label %24
13: ; preds = %2
%14 = load i32, i32* @X_OK
%15 = call i64 @access(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = call i32 @execv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8** %18)
br label %23
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %21)
br label %23
23: ; preds = %20, %17
br label %24
24: ; preds = %23, %10
%25 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [26 x i8] c"LD_PRELOAD=shmoverride.so\00"
@.str.1 = [18 x i8] c"/usr/libexec/Xorg\00"
@X_OK = global i32 0
@.str.2 = [22 x i8] c"/usr/libexec/Xorg.bin\00"
@.str.3 = [14 x i8] c"/usr/bin/Xorg\00"
@.str.4 = [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 ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @X_OK
%9 = tail call i64 @access(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0)
br label %12
12: ; preds = %7, %2
%13 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %11, %7 ]
%14 = tail call i32 @execv(i8* %13, i8** %1)
%15 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
ret i32 1
}