#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*/ execv(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) {
  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;
  execv(argv[1], args);
  free(dummy);
  sleep(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <findyourself_init@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%esi
call   1060 <find_yourself@plt>
mov    -0x40(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <dirname@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x38(%rbp),%rsi
call   10b0 <execv@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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   1080 <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   1090 <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    %r14,%rsi
call   10b0 <execv@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10a0 <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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @findyourself_init(i8* %13)
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %6
%18 = alloca i8, i64 %16
store i64 %16, i64* %7
%19 = trunc i64 %16 to i32
%20 = call i32 @find_yourself(i8* %18, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %18)
%22 = call i8* @strdup(i8* %18)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = call i8* @dirname(i8* %23)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %9
%28 = call i32 @chdir(i8* %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
store i8** %30, i8*** %10
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %10
%35 = call i32 @execv(i8* %33, i8** %34)
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
%38 = call i32 @sleep(i32 0)
store i32 0, i32* %3
%39 = load i8*, i8** %6
%40 = load i32, i32* %3
ret i32 %40
}

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"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @findyourself_init(i8* %3)
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @find_yourself(i8* %7, i32 %5)
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
%10 = call i8* @strdup(i8* %7)
%11 = call i8* @dirname(i8* %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 @chdir(i8* %11)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @execv(i8* %15, i8** %14)
%17 = call i32 @free(i8* %10)
%18 = call i32 @sleep(i32 0)
ret i32 0
}