#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 /*<<< orphan*/ free(char *);
char *getcwd(char **, int);
char getcwd_ok() {
  char *cwd = getcwd(NULL, 0);
  if (cwd != NULL) {
    char result = cwd[0];
    free(cwd);
    return result;
  }
  char buf[16];
  cwd = getcwd(&buf, 16);
  if (cwd != NULL) {
    return cwd[0];
  }
  return 'a';
}


x86 assembly (clang, -O0):
<getcwd_ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1040 <getcwd@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115f <getcwd_ok+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x11(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    118e <getcwd_ok+0x6e>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1040 <getcwd@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118a <getcwd_ok+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    118e <getcwd_ok+0x6e>
movb   $0x61,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcwd_ok>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   1040 <getcwd@plt>
test   %rax,%rax
je     113f <getcwd_ok+0x1f>
mov    (%rax),%bl
mov    %rax,%rdi
call   1030 <free@plt>
jmp    1157 <getcwd_ok+0x37>
mov    %rsp,%rdi
mov    $0x10,%esi
call   1040 <getcwd@plt>
test   %rax,%rax
je     1155 <getcwd_ok+0x35>
mov    (%rax),%bl
jmp    1157 <getcwd_ok+0x37>
mov    $0x61,%bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @getcwd_ok() {
%1 = alloca i8
%2 = alloca i8*
%3 = alloca i8
%4 = alloca [16 x i8]
%5 = call i8* @getcwd(i8** null, i32 0)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
store i8 %11, i8* %3
%12 = load i8*, i8** %2
%13 = call i32 @free(i8* %12)
%14 = load i8, i8* %3
store i8 %14, i8* %1
br label %25
15: ; preds = %0
%16 = bitcast [16 x i8]* %4 to i8**
%17 = call i8* @getcwd(i8** %16, i32 16)
store i8* %17, i8** %2
%18 = load i8*, i8** %2
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
store i8 %23, i8* %1
br label %25
24: ; preds = %15
store i8 97, i8* %1
br label %25
25: ; preds = %24, %20, %8
%26 = load i8, i8* %1
ret i8 %26
}

LLVM IR (-O2):
define signext i8 @getcwd_ok() {
%1 = alloca [16 x i8]
%2 = tail call i8* @getcwd(i8** null, i32 0)
%3 = icmp eq i8* %2, null
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = load i8, i8* %2
%6 = tail call i32 @free(i8* %2)
br label %16
7: ; preds = %0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%9 = bitcast [16 x i8]* %1 to i8**
%10 = call i8* @getcwd(i8** %9, i32 16)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = load i8, i8* %10
br label %14
14: ; preds = %7, %12
%15 = phi i8 [ %13, %12 ], [ 97, %7 ]
br label %16
16: ; preds = %14, %4
%17 = phi i8 [ %5, %4 ], [ %15, %14 ]
ret i8 %17
}