#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 */
scalar_t__ chdir(char *);
int /*<<< orphan*/ printf(char *, char *);
int cd_cmd(int argc, char **argv) {
  char *buffer;
  if (argc == 1) {
    buffer = "/";
  } else if (argc == 2) {
    buffer = argv[1];
  } else {
    return 2;
  }
  if (chdir(buffer)) {
    printf("cd: aucun fichier ou dossier de ce type: %s\n", buffer);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cd_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1149 <cd_cmd+0x29>
lea    0xec0(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <cd_cmd+0x55>
cmpl   $0x2,-0x8(%rbp)
jne    1164 <cd_cmd+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1170 <cd_cmd+0x50>
movl   $0x2,-0x4(%rbp)
jmp    11ab <cd_cmd+0x8b>
jmp    1175 <cd_cmd+0x55>
mov    -0x18(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     11a4 <cd_cmd+0x84>
mov    -0x18(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ab <cd_cmd+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd_cmd>:
push   %rbx
cmp    $0x1,%edi
je     1136 <cd_cmd+0x16>
mov    $0x2,%eax
cmp    $0x2,%edi
jne    115e <cd_cmd+0x3e>
mov    0x8(%rsi),%rbx
jmp    113d <cd_cmd+0x1d>
lea    0xec3(%rip),%rbx
mov    %rbx,%rdi
call   1030 <chdir@plt>
test   %rax,%rax
je     1160 <cd_cmd+0x40>
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [45 x i8] c"cd: aucun fichier ou dossier de ce type: %s\0A\00"
define i32 @cd_cmd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
br label %19
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
br label %18
17: ; preds = %10
store i32 2, i32* %3
br label %27
18: ; preds = %13
br label %19
19: ; preds = %18, %9
%20 = load i8*, i8** %6
%21 = call i64 @chdir(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %27
26: ; preds = %19
store i32 0, i32* %3
br label %27
27: ; preds = %26, %23, %17
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [45 x i8] c"cd: aucun fichier ou dossier de ce type: %s\0A\00"
define i32 @cd_cmd(i32 %0, i8** nocapture %1) {
switch i32 %0, label %12 [
i32 1, label %6
i32 2, label %3
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
br label %6
6: ; preds = %2, %3
%7 = phi i8* [ %5, %3 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%8 = tail call i64 @chdir(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %12
12: ; preds = %6, %2, %10
%13 = phi i32 [ 1, %10 ], [ 2, %2 ], [ 0, %6 ]
ret i32 %13
}