#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(int);
int cd_var(char *);
int secure_chdir(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int builtin_cd(char **argv) {
  assert(argv && argv[0]);
  if (!argv[1])
    return cd_var("HOME");
  if (!strcmp("-", argv[1]))
    return cd_var("OLDPWD");
  return secure_chdir(argv[1]);
}


x86 assembly (clang, -O0):
<builtin_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     116a <builtin_cd+0x2a>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    119a <builtin_cd+0x5a>
lea    0xe73(%rip),%rdi
call   1060 <cd_var@plt>
mov    %eax,-0x4(%rbp)
jmp    11db <builtin_cd+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5c(%rip),%rdi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11cb <builtin_cd+0x8b>
lea    0xe49(%rip),%rdi
call   1060 <cd_var@plt>
mov    %eax,-0x4(%rbp)
jmp    11db <builtin_cd+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <secure_chdir@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_cd>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1155 <builtin_cd+0x15>
xor    %edi,%edi
cmpq   $0x0,(%rbx)
setne  %dil
jmp    1157 <builtin_cd+0x17>
xor    %edi,%edi
call   1040 <assert@plt>
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     1181 <builtin_cd+0x41>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     118e <builtin_cd+0x4e>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <secure_chdir@plt>
lea    0xe78(%rip),%rdi
pop    %rbx
jmp    1060 <cd_var@plt>
lea    0xe72(%rip),%rdi
pop    %rbx
jmp    1060 <cd_var@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [7 x i8] c"OLDPWD\00"
define i32 @builtin_cd(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
br label %7
7: ; preds = %3, %1
%8 = phi i32 [ 0, %1 ], [ %6, %3 ]
%9 = tail call i32 @assert(i32 %8)
%10 = getelementptr inbounds i8*, i8** %0, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @cd_var(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
15: ; preds = %7
%16 = tail call i32 @strcmp(i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @cd_var(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %15
%21 = tail call i32 @secure_chdir(i8* %11)
br label %22
22: ; preds = %20, %18, %13
%23 = phi i32 [ %21, %20 ], [ %19, %18 ], [ %14, %13 ]
ret i32 %23
}