#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 */
void *dlsym_libc(char *);
char *const *newargv(char const *, char *const *);
char const *observe_handler();
int /*<<< orphan*/ reset_LD_PRELOAD(int /*<<< orphan*/ *);
int execvp(const char *file, char *const argv[]) {
  int (*actual)(const char *file, char *const argv[]);
  *(void **)(&actual) = dlsym_libc("execvp");
  if (actual == NULL)
    return -1;
  ;
  ;
  ;
  ;
  reset_LD_PRELOAD(NULL);
  if (actual(observe_handler(), newargv(file, argv)) == 0)
    return 0;
  ;
  ;
  return -1;
}


x86 assembly (clang, -O0):
<execvp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
call   1060 <dlsym_libc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1177 <execvp+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <execvp+0x89>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <reset_LD_PRELOAD@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <observe_handler@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <newargv@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
mov    -0x28(%rbp),%rax
call   *%rax
cmp    $0x0,%eax
jne    11c2 <execvp+0x82>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <execvp+0x89>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execvp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeab(%rip),%rdi
call   1060 <dlsym_libc@plt>
test   %rax,%rax
je     118c <execvp+0x4c>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <reset_LD_PRELOAD@plt>
xor    %eax,%eax
call   1050 <observe_handler@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <newargv@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   *%rbx
neg    %eax
sbb    %eax,%eax
jmp    1191 <execvp+0x51>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"execvp\00"
define i32 @execvp(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32 (i8*, i8**)*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = call i8* @dlsym_libc(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = bitcast i32 (i8*, i8**)** %6 to i8**
store i8* %7, i8** %8
%9 = load i32 (i8*, i8**)*, i32 (i8*, i8**)** %6
%10 = icmp eq i32 (i8*, i8**)* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %23
12: ; preds = %2
%13 = call i32 @reset_LD_PRELOAD(i32* null)
%14 = load i32 (i8*, i8**)*, i32 (i8*, i8**)** %6
%15 = call i8* (...) @observe_handler()
%16 = load i8*, i8** %4
%17 = load i8**, i8*** %5
%18 = call i8** @newargv(i8* %16, i8** %17)
%19 = call i32 %14(i8* %15, i8** %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %12
store i32 0, i32* %3
br label %23
22: ; preds = %12
store i32 -1, i32* %3
br label %23
23: ; preds = %22, %21, %11
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [7 x i8] c"execvp\00"
define i32 @execvp(i8* %0, i8** %1) {
%3 = tail call i8* @dlsym_libc(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = bitcast i8* %3 to i32 (i8*, i8**)*
%7 = tail call i32 @reset_LD_PRELOAD(i32* null)
%8 = tail call i8* (...) @observe_handler()
%9 = tail call i8** @newargv(i8* %0, i8** %1)
%10 = tail call i32 %6(i8* %8, i8** %9)
%11 = icmp ne i32 %10, 0
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %5, %2
%14 = phi i32 [ -1, %2 ], [ %12, %5 ]
ret i32 %14
}