#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*/ fail(char *, ...);
void xchdir(char *dir) {
  if (!dir || !dir[0])
    fail("Null pointer or empty string passed to xchdir()");
  if (chdir(dir) < 0)
    fail("cannot change directory to %s", dir);
}


x86 assembly (clang, -O0):
<xchdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1144 <xchdir+0x24>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1152 <xchdir+0x32>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <fail@plt>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jge    1177 <xchdir+0x57>
mov    -0x8(%rbp),%rsi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <fail@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xchdir>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     112e <xchdir+0xe>
cmpb   $0x0,(%rbx)
jne    113c <xchdir+0x1c>
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1030 <fail@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
js     114b <xchdir+0x2b>
pop    %rbx
ret
lea    0xede(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1030 <fail@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"Null pointer or empty string passed to xchdir()\00"
@.str.1 = [30 x i8] c"cannot change directory to %s\00"
define void @xchdir(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %5, %1
%11 = call i32 (i8*, ...) @fail(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
%13 = load i8*, i8** %2
%14 = call i64 @chdir(i8* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i32 (i8*, ...) @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %12
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"Null pointer or empty string passed to xchdir()\00"
@.str.1 = [30 x i8] c"cannot change directory to %s\00"
define void @xchdir(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3, %1
%7 = tail call i32 (i8*, ...) @fail(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = tail call i64 @chdir(i8* %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %8
ret void
}