#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 */
typedef int /*<<< orphan*/ newpath;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ chdir(char *);
char *dirname(char *);
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ find_yourself(char *, int);
int /*<<< orphan*/ findyourself_init(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sleep(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int main(int argc, char **argv, char *envp[]) {
  extern char **environ;
  findyourself_init(argv[0]);
  char newpath[PATH_MAX];
  find_yourself(newpath, sizeof(newpath));
  if (1 || strcmp(argv[0], newpath)) {
    printf("  findyourself=\"%s\"\n", newpath);
  }
  char *dummy = strdup(newpath);
  char *dname = dirname(dummy);
  printf("  Directory=\"%s\"\n", dname);
  chdir(dname);
  char **args = argv + 1;
  execve(argv[1], args, environ);
  free(dummy);
  sleep(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <findyourself_init@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
call   1060 <find_yourself@plt>
mov    -0x48(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <dirname@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x40(%rbp),%rsi
mov    0x2d95(%rip),%rax
mov    (%rax),%rdx
call   1080 <execve@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <sleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rsi),%rdi
call   1090 <findyourself_init@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1060 <find_yourself@plt>
lea    0xe2f(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <dirname@plt>
mov    %rax,%rbx
lea    0xe1f(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
mov    0x8(%r14),%rdi
add    $0x8,%r14
mov    0x2dcb(%rip),%rax
mov    (%rax),%rdx
mov    %r14,%rsi
call   1080 <execve@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [21 x i8] c" findyourself=\22%s\22\0A\00"
@.str.1 = [18 x i8] c" Directory=\22%s\22\0A\00"
@environ = external global i8**
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8**
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @findyourself_init(i8* %15)
%17 = load i32, i32* @PATH_MAX
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %8
%20 = alloca i8, i64 %18
store i64 %18, i64* %9
%21 = trunc i64 %18 to i32
%22 = call i32 @find_yourself(i8* %20, i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20)
%24 = call i8* @strdup(i8* %20)
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = call i8* @dirname(i8* %25)
store i8* %26, i8** %11
%27 = load i8*, i8** %11
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %11
%30 = call i32 @chdir(i8* %29)
%31 = load i8**, i8*** %6
%32 = getelementptr inbounds i8*, i8** %31, i64 1
store i8** %32, i8*** %12
%33 = load i8**, i8*** %6
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %12
%37 = load i8**, i8*** @environ
%38 = call i32 @execve(i8* %35, i8** %36, i8** %37)
%39 = load i8*, i8** %10
%40 = call i32 @free(i8* %39)
%41 = call i32 @sleep(i32 0)
store i32 0, i32* %4
%42 = load i8*, i8** %8
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [21 x i8] c" findyourself=\22%s\22\0A\00"
@.str.1 = [18 x i8] c" Directory=\22%s\22\0A\00"
@environ = external global i8**
define i32 @main(i32 %0, i8** %1, i8** nocapture readnone %2) {
%4 = load i8*, i8** %1
%5 = tail call i32 @findyourself_init(i8* %4)
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = call i32 @find_yourself(i8* %8, i32 %6)
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %8)
%11 = call i8* @strdup(i8* %8)
%12 = call i8* @dirname(i8* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @chdir(i8* %12)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i8**, i8*** @environ
%18 = call i32 @execve(i8* %16, i8** %15, i8** %17)
%19 = call i32 @free(i8* %11)
%20 = call i32 @sleep(i32 0)
ret i32 0
}