#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *pgr_name;
  int pathname_len = 4096;
  char pathname[pathname_len];
  pgr_name = argv[0];
  if (getcwd(pathname, pathname_len) == NULL) {
    perror(pgr_name);
    return EXIT_FAILURE;
  }
  printf("%s\n", pathname);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1000,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
jne    11b1 <main+0x81>
mov    -0x18(%rbp),%rdi
call   1050 <perror@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11d4 <main+0xa4>
mov    -0x40(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1000,%rsp
mov    (%rsi),%rbx
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1040 <getcwd@plt>
test   %rax,%rax
je     116e <main+0x3e>
lea    0xeac(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
add    $0x1000,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    0x2e63(%rip),%rax
jmp    1163 <main+0x33>

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

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = call i32* @getcwd(i8* %4, i32 4096)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @perror(i8* %5)
br label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %12
12: ; preds = %10, %8
%13 = phi i32* [ @EXIT_FAILURE, %8 ], [ @EXIT_SUCCESS, %10 ]
%14 = load i32, i32* %13
ret i32 %14
}