#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 *VsocHomeAdbShellPath();
int /*<<< orphan*/ X_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ execv(char *, char **);
scalar_t__ strcmp(char *, char *);
void TryExecHomeAdbShell(char *argv[]) {
  char *home_shell = VsocHomeAdbShellPath();
  if (access(home_shell, X_OK) != -1 && strcmp(argv[0], home_shell)) {
    argv[0] = home_shell;
    execv(home_shell, argv);
    assert(0 && "execv() returned");
  }
}


x86 assembly (clang, -O0):
<TryExecHomeAdbShell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <VsocHomeAdbShellPath@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11bb <TryExecHomeAdbShell+0x6b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11bb <TryExecHomeAdbShell+0x6b>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <execv@plt>
xor    %edi,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TryExecHomeAdbShell>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <VsocHomeAdbShellPath@plt>
mov    %rax,%rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11a3 <TryExecHomeAdbShell+0x53>
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11a3 <TryExecHomeAdbShell+0x53>
mov    %rbx,(%r14)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <execv@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@X_OK = global i32 0
define void @TryExecHomeAdbShell(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
store i8** %0, i8*** %2
%4 = call i8* (...) @VsocHomeAdbShellPath()
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @X_OK
%7 = call i32 @access(i8* %5, i32 %6)
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %24
9: ; preds = %1
%10 = load i8**, i8*** %2
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = load i8*, i8** %3
%14 = call i64 @strcmp(i8* %12, i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = load i8**, i8*** %2
%19 = getelementptr inbounds i8*, i8** %18, i64 0
store i8* %17, i8** %19
%20 = load i8*, i8** %3
%21 = load i8**, i8*** %2
%22 = call i32 @execv(i8* %20, i8** %21)
%23 = call i32 @assert(i32 0)
br label %24
24: ; preds = %16, %9, %1
ret void
}

LLVM IR (-O2):
@X_OK = global i32 0
define void @TryExecHomeAdbShell(i8** %0) {
%2 = tail call i8* (...) @VsocHomeAdbShellPath()
%3 = load i32, i32* @X_OK
%4 = tail call i32 @access(i8* %2, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = load i8*, i8** %0
%8 = tail call i64 @strcmp(i8* %7, i8* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
store i8* %2, i8** %0
%11 = tail call i32 @execv(i8* %2, i8** %0)
%12 = tail call i32 @assert(i32 0)
br label %13
13: ; preds = %10, %6, %1
ret void
}