#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 _cd_chdir(int *, char *);
int _cd_home();
int _cd_previous();
int _cd_usage();
int /*<<< orphan*/ _getopt_reset(int, char **);
int getopt(int, char **, char *);
int optind;
scalar_t__ strcmp(char *, char *);
int builtin_cd(int argc, char *argv[]) {
  int o;
  int prefs = 0;
  _getopt_reset(argc, argv);
  while ((o = getopt(argc, argv, "LP")) != -1)
    switch (o) {
    case 'L':
      prefs = 0;
      break;
    case 'P':
      prefs = 1;
      break;
    default:
      return _cd_usage();
    }
  if (argc - optind > 1)
    return _cd_usage();
  if (argc - optind == 0)
    return _cd_home();
  if (strcmp("-", argv[optind]) == 0)
    return _cd_previous();
  return _cd_chdir(&prefs, argv[optind]);
}


x86 assembly (clang, -O0):
<builtin_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <_getopt_reset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe60(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1202 <builtin_cd+0x92>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x4c,%eax
je     11d6 <builtin_cd+0x66>
jmp    11c5 <builtin_cd+0x55>
mov    -0x1c(%rbp),%eax
sub    $0x50,%eax
je     11e2 <builtin_cd+0x72>
jmp    11ee <builtin_cd+0x7e>
movl   $0x0,-0x18(%rbp)
jmp    11fd <builtin_cd+0x8d>
movl   $0x1,-0x18(%rbp)
jmp    11fd <builtin_cd+0x8d>
mov    $0x0,%al
call   1050 <_cd_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    129f <builtin_cd+0x12f>
jmp    1192 <builtin_cd+0x22>
mov    -0x8(%rbp),%eax
mov    0x2ddc(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jle    1226 <builtin_cd+0xb6>
mov    $0x0,%al
call   1050 <_cd_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    129f <builtin_cd+0x12f>
mov    -0x8(%rbp),%eax
mov    0x2db8(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jne    124a <builtin_cd+0xda>
mov    $0x0,%al
call   1070 <_cd_home@plt>
mov    %eax,-0x4(%rbp)
jmp    129f <builtin_cd+0x12f>
mov    -0x10(%rbp),%rax
mov    0x2d93(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xda0(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1281 <builtin_cd+0x111>
mov    $0x0,%al
call   1030 <_cd_previous@plt>
mov    %eax,-0x4(%rbp)
jmp    129f <builtin_cd+0x12f>
mov    -0x10(%rbp),%rax
mov    0x2d5c(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x18(%rbp),%rdi
call   1040 <_cd_chdir@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_cd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
call   1080 <_getopt_reset@plt>
xor    %ecx,%ecx
lea    0xe76(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1090 <getopt@plt>
mov    $0x0,%ecx
cmp    $0x4c,%eax
je     1190 <builtin_cd+0x20>
cmp    $0x50,%eax
jne    11b5 <builtin_cd+0x45>
mov    $0x1,%ecx
jmp    1190 <builtin_cd+0x20>
cmp    $0xffffffff,%eax
jne    11cf <builtin_cd+0x5f>
mov    %ebx,0x4(%rsp)
mov    0x2e23(%rip),%r14
movslq (%r14),%rax
sub    %eax,%ebp
cmp    $0x2,%ebp
jl     11e0 <builtin_cd+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_cd_usage@plt>
test   %ebp,%ebp
je     1215 <builtin_cd+0xa5>
mov    (%r15,%rax,8),%rsi
lea    0xe14(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1226 <builtin_cd+0xb6>
movslq (%r14),%rax
mov    (%r15,%rax,8),%rsi
lea    0x4(%rsp),%rdi
call   1040 <_cd_chdir@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <_cd_home@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_cd_previous@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"LP\00"
@optind = global i32 0
@.str.1 = [2 x i8] c"-\00"
define i32 @builtin_cd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @_getopt_reset(i32 %8, i8** %9)
br label %11
11: ; preds = %22, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %20 [
i32 76, label %18
i32 80, label %19
]
18: ; preds = %16
store i32 0, i32* %7
br label %22
19: ; preds = %16
store i32 1, i32* %7
br label %22
20: ; preds = %16
%21 = call i32 (...) @_cd_usage()
store i32 %21, i32* %3
br label %54
22: ; preds = %19, %18
br label %11
23: ; preds = %11
%24 = load i32, i32* %4
%25 = load i32, i32* @optind
%26 = sub nsw i32 %24, %25
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 (...) @_cd_usage()
store i32 %29, i32* %3
br label %54
30: ; preds = %23
%31 = load i32, i32* %4
%32 = load i32, i32* @optind
%33 = sub nsw i32 %31, %32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 (...) @_cd_home()
store i32 %36, i32* %3
br label %54
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = load i32, i32* @optind
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = call i32 (...) @_cd_previous()
store i32 %46, i32* %3
br label %54
47: ; preds = %37
%48 = load i8**, i8*** %5
%49 = load i32, i32* @optind
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 @_cd_chdir(i32* %7, i8* %52)
store i32 %53, i32* %3
br label %54
54: ; preds = %47, %45, %35, %28, %20
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"LP\00"
@optind = global i32 0
@.str.1 = [2 x i8] c"-\00"
define i32 @builtin_cd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @_getopt_reset(i32 %0, i8** %1)
br label %6
6: ; preds = %9, %2
%7 = phi i32 [ 0, %2 ], [ %10, %9 ]
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %12 [
i32 -1, label %14
i32 76, label %9
i32 80, label %11
]
9: ; preds = %6, %11
%10 = phi i32 [ 1, %11 ], [ 0, %6 ]
br label %6
11: ; preds = %6
br label %9
12: ; preds = %6
%13 = tail call i32 (...) @_cd_usage()
br label %38
14: ; preds = %6
store i32 %7, i32* %3
%15 = load i32, i32* @optind
%16 = sub nsw i32 %0, %15
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 (...) @_cd_usage()
br label %38
20: ; preds = %14
%21 = icmp eq i32 %16, 0
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 (...) @_cd_home()
br label %38
24: ; preds = %20
%25 = sext i32 %15 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = tail call i32 (...) @_cd_previous()
br label %38
32: ; preds = %24
%33 = load i32, i32* @optind
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @_cd_chdir(i32* %3, i8* %36)
br label %38
38: ; preds = %32, %30, %22, %18, %12
%39 = phi i32 [ %13, %12 ], [ %19, %18 ], [ %23, %22 ], [ %31, %30 ], [ %37, %32 ]
ret i32 %39
}