#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 */
struct exitinfo {
  int dummy;
};

/* Variables and functions */
scalar_t__ chdir(char *);
int /*<<< orphan*/ exitinfo_exit(struct exitinfo *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ warn(char *, char *);
void cmd_chdir(int ac, char *av[], struct exitinfo *ei) {
  if (ac == 2) {
    if (chdir(av[1])) {
      warn("chdir: %s", av[1]);
      exitinfo_exit(ei, 1);
      return;
    }
    exitinfo_exit(ei, 0);
    return;
  }
  printf("Usage: chdir dir\n");
  exitinfo_exit(ei, 1);
}


x86 assembly (clang, -O0):
<cmd_chdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    11ab <cmd_chdir+0x6b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     119b <cmd_chdir+0x5b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe7d(%rip),%rdi
call   1030 <warn@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <exitinfo_exit@plt>
jmp    11c5 <cmd_chdir+0x85>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1060 <exitinfo_exit@plt>
jmp    11c5 <cmd_chdir+0x85>
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <exitinfo_exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_chdir>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
cmp    $0x2,%edi
jne    116f <cmd_chdir+0x2f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
je     1182 <cmd_chdir+0x42>
mov    0x8(%rbx),%rsi
lea    0xe98(%rip),%rdi
call   1030 <warn@plt>
jmp    117b <cmd_chdir+0x3b>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%esi
jmp    1184 <cmd_chdir+0x44>
xor    %esi,%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <exitinfo_exit@plt>

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

LLVM IR (-O2):
%struct.exitinfo = type { i32 }
@.str = [10 x i8] c"chdir: %s\00"
@str = [17 x i8] c"Usage: chdir dir\00"
define void @cmd_chdir(i32 %0, i8** nocapture %1, %struct.exitinfo* %2) {
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @chdir(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = load i8*, i8** %6
%12 = tail call i32 @warn(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %15
13: ; preds = %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %5, %13, %10
%16 = phi i32 [ 1, %13 ], [ 1, %10 ], [ 0, %5 ]
%17 = tail call i32 @exitinfo_exit(%struct.exitinfo* %2, i32 %16)
ret void
}