#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*/ PATH_MAX;
scalar_t__ chdir(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ getcwd(char *, int);
int /*<<< orphan*/ my_err(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char buf[PATH_MAX + 1];
  if (argc < 2) {
    printf("my_cd <tartget path>\n");
    exit(1);
  }
  if (chdir(argv[1]) < 0) {
    my_err("chdir", 38);
  }
  if (getcwd(buf, 512) < 0) {
    my_err("getcwd", 41);
  }
  printf("%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b7 <main+0x67>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    11df <main+0x8f>
lea    0xe41(%rip),%rdi
mov    $0x26,%esi
call   1070 <my_err@plt>
mov    -0x28(%rbp),%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
jge    1208 <main+0xb8>
lea    0xe1e(%rip),%rdi
mov    $0x29,%esi
call   1070 <my_err@plt>
mov    -0x28(%rbp),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@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   %rbx
push   %rax
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x1,%edi
jle    11cb <main+0x7b>
mov    0x8(%rsi),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
jns    1197 <main+0x47>
lea    0xe73(%rip),%rdi
mov    $0x26,%esi
call   1070 <my_err@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
test   %rax,%rax
jns    11ba <main+0x6a>
lea    0xe56(%rip),%rdi
mov    $0x29,%esi
call   1070 <my_err@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [22 x i8] c"my_cd <tartget path>\0A\00"
@.str.1 = [6 x i8] c"chdir\00"
@.str.2 = [7 x i8] c"getcwd\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @PATH_MAX
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @chdir(i8* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 38)
br label %26
26: ; preds = %24, %18
%27 = call i64 @getcwd(i8* %12, i32 512)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @my_err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 41)
br label %31
31: ; preds = %29, %26
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %12)
store i32 0, i32* %3
%33 = load i8*, i8** %6
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str.1 = [6 x i8] c"chdir\00"
@.str.2 = [7 x i8] c"getcwd\00"
@str = [21 x i8] c"my_cd <tartget path>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @chdir(i8* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 38)
br label %18
18: ; preds = %16, %11
%19 = call i64 @getcwd(i8* %6, i32 512)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @my_err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 41)
br label %23
23: ; preds = %21, %18
%24 = call i32 @puts(i8* %6)
ret i32 0
}