#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 */
int PATH_MAX;
int chdir(char const *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ puts(char *);
int cmd_path(const char *jobid) {
  char path[PATH_MAX];
  if (jobid && chdir(jobid) == -1) {
    perror(jobid);
    return 1;
  }
  if (getcwd(path, PATH_MAX) == NULL) {
    perror("cwd");
    return 1;
  }
  puts(path);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b1 <cmd_path+0x71>
mov    -0x10(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11b1 <cmd_path+0x71>
mov    -0x10(%rbp),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1203 <cmd_path+0xc3>
mov    -0x30(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
jne    11ec <cmd_path+0xac>
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1203 <cmd_path+0xc3>
mov    -0x30(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e9f(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rdi,%rdi
je     117a <cmd_path+0x3a>
mov    %rdi,%r14
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     11a5 <cmd_path+0x65>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <getcwd@plt>
test   %rax,%rax
je     119c <cmd_path+0x5c>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5d(%rip),%rdi
jmp    11a8 <cmd_path+0x68>
mov    %r14,%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    1191 <cmd_path+0x51>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [4 x i8] c"cwd\00"
define i32 @cmd_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i8, i64 %8
store i64 %8, i64* %5
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @chdir(i8* %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i32 @perror(i8* %18)
store i32 1, i32* %2
store i32 1, i32* %6
br label %28
20: ; preds = %13, %1
%21 = load i32, i32* @PATH_MAX
%22 = call i32* @getcwd(i8* %10, i32 %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
store i32 1, i32* %6
br label %28
26: ; preds = %20
%27 = call i32 @puts(i8* %10)
store i32 0, i32* %2
store i32 1, i32* %6
br label %28
28: ; preds = %26, %24, %17
%29 = load i8*, i8** %4
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [4 x i8] c"cwd\00"
define i32 @cmd_path(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp eq i8* %0, null
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = tail call i32 @chdir(i8* %0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = load i32, i32* @PATH_MAX
br label %13
11: ; preds = %6
%12 = tail call i32 @perror(i8* %0)
br label %21
13: ; preds = %9, %1
%14 = phi i32 [ %10, %9 ], [ %2, %1 ]
%15 = call i32* @getcwd(i8* %4, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %21
19: ; preds = %13
%20 = call i32 @puts(i8* %4)
br label %21
21: ; preds = %19, %17, %11
%22 = phi i32 [ 1, %11 ], [ 1, %17 ], [ 0, %19 ]
ret i32 %22
}