#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(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int chdir_proc(char **args) {
  if (*args == NULL)
    return -1;
  else if (chdir(*args++) != 0) {
    fprintf(stderr, "*** craSh: cd ***");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<chdir_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1146 <chdir_proc+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <chdir_proc+0x76>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %eax,%edi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     118a <chdir_proc+0x6a>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <chdir_proc+0x76>
jmp    118f <chdir_proc+0x6f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chdir_proc>:
push   %rbx
mov    (%rdi),%rdi
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     1154 <chdir_proc+0x34>
call   1030 <chdir@plt>
test   %rax,%rax
je     114f <chdir_proc+0x2f>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1154 <chdir_proc+0x34>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"*** craSh: cd ***\00"
define i32 @chdir_proc(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
store i8** %0, i8*** %3
%4 = load i8**, i8*** %3
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %20
8: ; preds = %1
%9 = load i8**, i8*** %3
%10 = getelementptr inbounds i8*, i8** %9, i32 1
store i8** %10, i8*** %3
%11 = load i8*, i8** %9
%12 = ptrtoint i8* %11 to i32
%13 = call i64 @chdir(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %20
18: ; preds = %8
br label %19
19: ; preds = %18
store i32 1, i32* %2
br label %20
20: ; preds = %19, %15, %7
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"*** craSh: cd ***\00"
define i32 @chdir_proc(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = ptrtoint i8* %2 to i64
%6 = trunc i64 %5 to i32
%7 = tail call i64 @chdir(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %4, %1, %9
%13 = phi i32 [ -1, %9 ], [ -1, %1 ], [ 1, %4 ]
ret i32 %13
}