#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 ft_cmd_cd_goto(char *);
int ft_cmd_cd_home();
int ft_cmd_cd_oldpwd();
int ft_sh_error(char *);
size_t ft_sh_tablen(char **);
int ft_strlen(char *);
int ft_cmd_cd(char **argv) {
  size_t len;
  len = ft_sh_tablen(argv);
  if (len == 1)
    return (ft_cmd_cd_home());
  else if (len == 2) {
    if (ft_strlen(argv[1]) == 1 && argv[1][0] == '-')
      return (ft_cmd_cd_oldpwd());
    else
      return (ft_cmd_cd_goto(argv[1]));
  } else if (len > 2)
    return (ft_sh_error("42sh: cd: Too many arguments."));
  return (0);
}


x86 assembly (clang, -O0):
<ft_cmd_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ft_sh_tablen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jne    1193 <ft_cmd_cd+0x33>
mov    $0x0,%al
call   1050 <ft_cmd_cd_home@plt>
mov    %eax,-0x4(%rbp)
jmp    121c <ft_cmd_cd+0xbc>
cmpq   $0x2,-0x18(%rbp)
jne    11ec <ft_cmd_cd+0x8c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <ft_strlen@plt>
cmp    $0x1,%eax
jne    11d7 <ft_cmd_cd+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11d7 <ft_cmd_cd+0x77>
mov    $0x0,%al
call   1060 <ft_cmd_cd_oldpwd@plt>
mov    %eax,-0x4(%rbp)
jmp    121c <ft_cmd_cd+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <ft_cmd_cd_goto@plt>
mov    %eax,-0x4(%rbp)
jmp    121c <ft_cmd_cd+0xbc>
cmpq   $0x2,-0x18(%rbp)
jbe    120b <ft_cmd_cd+0xab>
lea    0xe02(%rip),%rdi
call   1070 <ft_sh_error@plt>
mov    %eax,-0x4(%rbp)
jmp    121c <ft_cmd_cd+0xbc>
jmp    1210 <ft_cmd_cd+0xb0>
jmp    1215 <ft_cmd_cd+0xb5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_cmd_cd>:
push   %rbx
mov    %rdi,%rbx
call   1040 <ft_sh_tablen@plt>
cmp    $0x2,%rax
je     117d <ft_cmd_cd+0x1d>
cmp    $0x1,%rax
jne    119c <ft_cmd_cd+0x3c>
xor    %eax,%eax
pop    %rbx
jmp    1050 <ft_cmd_cd_home@plt>
mov    0x8(%rbx),%rdi
call   1030 <ft_strlen@plt>
mov    0x8(%rbx),%rdi
cmp    $0x1,%eax
jne    11af <ft_cmd_cd+0x4f>
cmpb   $0x2d,(%rdi)
jne    11af <ft_cmd_cd+0x4f>
xor    %eax,%eax
pop    %rbx
jmp    1060 <ft_cmd_cd_oldpwd@plt>
cmp    $0x3,%rax
jb     11b5 <ft_cmd_cd+0x55>
lea    0xe57(%rip),%rdi
pop    %rbx
jmp    1070 <ft_sh_error@plt>
pop    %rbx
jmp    1080 <ft_cmd_cd_goto@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"42sh: cd: Too many arguments.\00"
define i32 @ft_cmd_cd(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i64
store i8** %0, i8*** %3
%5 = load i8**, i8*** %3
%6 = call i64 @ft_sh_tablen(i8** %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (...) @ft_cmd_cd_home()
store i32 %10, i32* %2
br label %43
11: ; preds = %1
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 2
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @ft_strlen(i8* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %30
20: ; preds = %14
%21 = load i8**, i8*** %3
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 45
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 (...) @ft_cmd_cd_oldpwd()
store i32 %29, i32* %2
br label %43
30: ; preds = %20, %14
%31 = load i8**, i8*** %3
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @ft_cmd_cd_goto(i8* %33)
store i32 %34, i32* %2
br label %43
35: ; preds = %11
%36 = load i64, i64* %4
%37 = icmp ugt i64 %36, 2
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @ft_sh_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 %39, i32* %2
br label %43
40: ; preds = %35
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41
store i32 0, i32* %2
br label %43
43: ; preds = %42, %38, %30, %28, %9
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [30 x i8] c"42sh: cd: Too many arguments.\00"
define i32 @ft_cmd_cd(i8** %0) {
%2 = tail call i64 @ft_sh_tablen(i8** %0)
switch i64 %2, label %18 [
i64 1, label %3
i64 2, label %5
]
3: ; preds = %1
%4 = tail call i32 (...) @ft_cmd_cd_home()
br label %22
5: ; preds = %1
%6 = getelementptr inbounds i8*, i8** %0, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @ft_strlen(i8* %7)
%9 = icmp eq i32 %8, 1
%10 = load i8*, i8** %6
br i1 %9, label %11, label %16
11: ; preds = %5
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 45
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 (...) @ft_cmd_cd_oldpwd()
br label %22
16: ; preds = %5, %11
%17 = tail call i32 @ft_cmd_cd_goto(i8* %10)
br label %22
18: ; preds = %1
%19 = icmp ugt i64 %2, 2
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = tail call i32 @ft_sh_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %18, %20, %16, %14, %3
%23 = phi i32 [ %4, %3 ], [ %15, %14 ], [ %17, %16 ], [ %21, %20 ], [ 0, %18 ]
ret i32 %23
}