#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int chdir(char const *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int builtin_cd(int argc, const char **argv) {
  if (argc < 2) {
    fputs("cd: insufficient arguments\n", stderr);
    return (EXIT_FAILURE);
  }
  if (chdir(argv[1]) == -1) {
    fputs("cd: failed\n", stderr);
    return (EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<builtin_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    115f <builtin_cd+0x3f>
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <builtin_cd+0x87>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    119b <builtin_cd+0x7b>
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <builtin_cd+0x87>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_cd>:
push   %rax
cmp    $0x2,%edi
jge    112f <builtin_cd+0xf>
lea    0xed3(%rip),%rdi
jmp    114d <builtin_cd+0x2d>
mov    0x8(%rsi),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
je     1146 <builtin_cd+0x26>
mov    0x2e8c(%rip),%rax
jmp    1162 <builtin_cd+0x42>
lea    0xecf(%rip),%rdi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"cd: insufficient arguments\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"cd: failed\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @builtin_cd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %3
br label %24
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @chdir(i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = call i32 @fputs(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %24
22: ; preds = %12
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %3
br label %24
24: ; preds = %22, %18, %8
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [28 x i8] c"cd: insufficient arguments\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"cd: failed\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @builtin_cd(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @chdir(i8* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %4, %2
%10 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %4 ]
%11 = load i32, i32* @stderr
%12 = tail call i32 @fputs(i8* %10, i32 %11)
br label %13
13: ; preds = %9, %4
%14 = phi i32* [ @EXIT_SUCCESS, %4 ], [ @EXIT_FAILURE, %9 ]
%15 = load i32, i32* %14
ret i32 %15
}