#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 *);
int /*<<< orphan*/ warn(char *);
int cmd_chdir(int ac, char *av[]) {
  if (ac == 2) {
    if (chdir(av[1])) {
      warn("chdir");
      return 1;
    }
    return 0;
  }
  printf("Usage: chdir dir\n");
  return 1;
}


x86 assembly (clang, -O0):
<cmd_chdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1184 <cmd_chdir+0x54>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     1178 <cmd_chdir+0x48>
lea    0xe99(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    1197 <cmd_chdir+0x67>
movl   $0x0,-0x4(%rbp)
jmp    1197 <cmd_chdir+0x67>
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_chdir>:
push   %rax
cmp    $0x2,%edi
jne    1152 <cmd_chdir+0x22>
mov    0x8(%rsi),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
je     1165 <cmd_chdir+0x35>
lea    0xeb5(%rip),%rdi
call   1030 <warn@plt>
jmp    115e <cmd_chdir+0x2e>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

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