#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*/ free(char *);
char *getcwd(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int main(void) {
  char *dir;
  mtrace();
  dir = getcwd((char *)NULL, 0);
  if (dir == NULL)
    perror("getcwd");
  else {
    puts(dir);
    free(dir);
  }
  return (dir == NULL ? EXIT_FAILURE : EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <mtrace@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1191 <main+0x41>
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
jmp    11a3 <main+0x53>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11bf <main+0x6f>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11cb <main+0x7b>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <mtrace@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1187 <main+0x37>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
jne    1198 <main+0x48>
mov    0x2e5b(%rip),%rax
jmp    119f <main+0x4f>
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
test   %rbx,%rbx
je     117e <main+0x2e>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

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

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