#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getcwd(char *, int);
scalar_t__ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char path_buf[PATH_MAX + 1];
  if (argc > 1) {
    int i;
    fflush(stdout);
    fputs(argv[0], stderr);
    fputs(": ignoring garbage arguments\n", stderr);
  }
  if (!getcwd(path_buf, PATH_MAX + 1)) {
    fflush(stdout);
    fputs(argv[0], stderr);
    fputs(": can\'t get current working directory: ", stderr);
    fputs(strerror(errno), stderr);
    fputc('\n', stderr);
    return 1;
  }
  if (puts(path_buf) < 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
add    $0x1,%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)
cmpl   $0x1,-0x8(%rbp)
jle    11e7 <main+0x87>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x30(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
add    $0x1,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%eax
jne    1282 <main+0x122>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    0xde6(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rdi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    12b6 <main+0x156>
mov    -0x30(%rbp),%rdi
call   1030 <puts@plt>
cmp    $0x0,%rax
jge    12a8 <main+0x148>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    12b6 <main+0x156>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    0x2e7b(%rip),%r15
mov    (%r15),%esi
add    $0x1,%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jl     11c8 <main+0x68>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    (%r14),%rdi
mov    0x2e2f(%rip),%r12
mov    (%r12),%esi
call   1040 <fputs@plt>
mov    (%r12),%esi
lea    0xe43(%rip),%rdi
call   1040 <fputs@plt>
mov    (%r15),%esi
add    $0x1,%esi
mov    %rbx,%rdi
call   1050 <getcwd@plt>
test   %eax,%eax
je     11e2 <main+0x82>
mov    %rbx,%rdi
call   1030 <puts@plt>
shr    $0x3f,%rax
jmp    1238 <main+0xd8>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    (%r14),%rdi
mov    0x2dde(%rip),%rbx
mov    (%rbx),%esi
call   1040 <fputs@plt>
mov    (%rbx),%esi
lea    0xe14(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    (%rbx),%esi
mov    %rax,%rdi
call   1040 <fputs@plt>
mov    (%rbx),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    $0x1,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c": ignoring garbage arguments\0A\00"
@.str.1 = [40 x i8] c": can't get current working directory: \00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @PATH_MAX
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %27
17: ; preds = %2
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = load i32, i32* @stderr
%24 = call i32 @fputs(i8* %22, i32 %23)
%25 = load i32, i32* @stderr
%26 = call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %17, %2
%28 = load i32, i32* @PATH_MAX
%29 = add nsw i32 %28, 1
%30 = call i32 @getcwd(i8* %14, i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %48, label %32
32: ; preds = %27
%33 = load i32, i32* @stdout
%34 = call i32 @fflush(i32 %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = load i32, i32* @stderr
%39 = call i32 @fputs(i8* %37, i32 %38)
%40 = load i32, i32* @stderr
%41 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* %43, i32 %44)
%46 = load i32, i32* @stderr
%47 = call i32 @fputc(i8 signext 10, i32 %46)
store i32 1, i32* %3
store i32 1, i32* %9
br label %53
48: ; preds = %27
%49 = call i64 @puts(i8* %14)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %48
store i32 1, i32* %3
store i32 1, i32* %9
br label %53
52: ; preds = %48
store i32 0, i32* %3
store i32 1, i32* %9
br label %53
53: ; preds = %52, %51, %32
%54 = load i8*, i8** %6
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c": ignoring garbage arguments\0A\00"
@.str.1 = [40 x i8] c": can't get current working directory: \00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = load i8*, i8** %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fputs(i8* %11, i32 %12)
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @PATH_MAX
%17 = add nsw i32 %16, 1
br label %18
18: ; preds = %8, %2
%19 = phi i32 [ %17, %8 ], [ %4, %2 ]
%20 = call i32 @getcwd(i8* %6, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
%25 = load i8*, i8** %1
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* %25, i32 %26)
%28 = load i32, i32* @stderr
%29 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = load i32, i32* @stderr
%33 = call i32 @fputs(i8* %31, i32 %32)
%34 = load i32, i32* @stderr
%35 = call i32 @fputc(i8 signext 10, i32 %34)
br label %40
36: ; preds = %18
%37 = call i64 @puts(i8* %6)
%38 = lshr i64 %37, 63
%39 = trunc i64 %38 to i32
br label %40
40: ; preds = %36, %22
%41 = phi i32 [ 1, %22 ], [ %39, %36 ]
ret i32 %41
}