#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 */
typedef int /*<<< orphan*/ junk;
typedef int /*<<< orphan*/ crap;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
char *getcwd(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char *foo;
  char junk[12];
  char crap[100];
  foo = getcwd(NULL, 0);
  printf("getcwd(NULL, 0)='%s'\n", foo);
  if (foo) {
    free(foo);
  }
  foo = getcwd(NULL, 100);
  printf("\ngetcwd(NULL, 100)='%s'\n", foo);
  if (foo) {
    free(foo);
  }
  foo = getcwd(junk, sizeof(junk));
  printf("\nchar junk[12];\n");
  printf("getcwd(junk, sizeof(junk))='%s'\n", foo);
  foo = getcwd(crap, sizeof(crap));
  printf("\nchar crap[100];\n");
  printf("getcwd(crap, sizeof(crap))='%s'\n", foo);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1177 <main+0x47>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x64,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11af <main+0x7f>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    -0x1c(%rbp),%rdi
mov    $0xc,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x10(%rbp)
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x10(%rbp)
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,%rbx
lea    0xea5(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbx,%rbx
je     1172 <main+0x32>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1060 <getcwd@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbx,%rbx
je     119f <main+0x5f>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x4(%rsp),%rdi
mov    $0xc,%esi
call   1060 <getcwd@plt>
mov    %rax,%rbx
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1060 <getcwd@plt>
mov    %rax,%rbx
lea    0xe9a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"getcwd(NULL, 0)='%s'\0A\00"
@.str.1 = [25 x i8] c"\0Agetcwd(NULL, 100)='%s'\0A\00"
@.str.2 = [17 x i8] c"\0Achar junk[12];\0A\00"
@.str.3 = [33 x i8] c"getcwd(junk, sizeof(junk))='%s'\0A\00"
@.str.4 = [18 x i8] c"\0Achar crap[100];\0A\00"
@.str.5 = [33 x i8] c"getcwd(crap, sizeof(crap))='%s'\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [12 x i8]
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = call i8* @getcwd(i8* null, i32 0)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = call i32 @free(i8* %11)
br label %13
13: ; preds = %10, %0
%14 = call i8* @getcwd(i8* null, i32 100)
store i8* %14, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %2
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i8*, i8** %2
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %19, %13
%23 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%24 = call i8* @getcwd(i8* %23, i32 12)
store i8* %24, i8** %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8*, i8** %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%29 = call i8* @getcwd(i8* %28, i32 100)
store i8* %29, i8** %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%31 = load i8*, i8** %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}

LLVM IR (-O2):
@.str = [22 x i8] c"getcwd(NULL, 0)='%s'\0A\00"
@.str.1 = [25 x i8] c"\0Agetcwd(NULL, 100)='%s'\0A\00"
@.str.3 = [33 x i8] c"getcwd(junk, sizeof(junk))='%s'\0A\00"
@.str.5 = [33 x i8] c"getcwd(crap, sizeof(crap))='%s'\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [16 x i8] c"\0Achar junk[12];\00"
@str.6 = [17 x i8] c"\0Achar crap[100];\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i8* @getcwd(i8* null, i32 0)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = icmp eq i8* %5, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = tail call i32 @free(i8* %5)
br label %10
10: ; preds = %8, %0
%11 = tail call i8* @getcwd(i8* null, i32 100)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = icmp eq i8* %11, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @free(i8* %11)
br label %16
16: ; preds = %14, %10
%17 = call i8* @getcwd(i8* %3, i32 12)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%20 = call i8* @getcwd(i8* %4, i32 100)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}