#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*/ assert(char *);
int chdir(char *);
int /*<<< orphan*/ perror(char *);
int builtin_chdir(char *nam, char **argv, char **stdout) {
  assert(nam);
  assert(argv[0]);
  int ret = 0;
  if (argv[1] == NULL) {
  } else if (argv[1]) {
    ret = chdir(argv[1]);
  }
  if (ret == -1)
    perror("cd");
  return ret;
}


x86 assembly (clang, -O0):
<builtin_chdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1174 <builtin_chdir+0x44>
jmp    1198 <builtin_chdir+0x68>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1193 <builtin_chdir+0x63>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <chdir@plt>
mov    %eax,-0x1c(%rbp)
jmp    1198 <builtin_chdir+0x68>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ae <builtin_chdir+0x7e>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_chdir>:
push   %rbx
mov    %rsi,%rbx
call   1040 <assert@plt>
mov    (%rbx),%rdi
call   1040 <assert@plt>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     1156 <builtin_chdir+0x26>
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
je     115a <builtin_chdir+0x2a>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
lea    0xe9f(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"cd\00"
define i32 @builtin_chdir(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%8 = load i8*, i8** %4
%9 = call i32 @assert(i8* %8)
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @assert(i8* %12)
store i32 0, i32* %7
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %3
br label %30
19: ; preds = %3
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @chdir(i8* %27)
store i32 %28, i32* %7
br label %29
29: ; preds = %24, %19
br label %30
30: ; preds = %29, %18
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"cd\00"
define i32 @builtin_chdir(i8* %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = tail call i32 @assert(i8* %0)
%5 = load i8*, i8** %1
%6 = tail call i32 @assert(i8* %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %3
%11 = tail call i32 @chdir(i8* %8)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %3, %13, %10
%16 = phi i32 [ -1, %13 ], [ %11, %10 ], [ 0, %3 ]
ret i32 %16
}