#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 ERANGE;
int errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *getcwd(char *, size_t);
char *xcalloc(size_t, int);
const char *get_current_dir(void) {
  int error = 0;
  size_t size = 64;
  char *buffer = NULL;
  do {
    error = 0;
    buffer = xcalloc(size, sizeof(char));
    if (getcwd(buffer, size) == NULL) {
      error = errno;
      size = size * 2;
      free(buffer);
      buffer = NULL;
    }
  } while (error == ERANGE);
  if (buffer && *buffer != '/') {
    free(buffer);
    return NULL;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<get_current_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movq   $0x40,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1050 <xcalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
jne    11a8 <get_current_dir+0x78>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    11ad <get_current_dir+0x7d>
mov    -0xc(%rbp),%eax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
je     114f <get_current_dir+0x1f>
cmpq   $0x0,-0x20(%rbp)
je     11f0 <get_current_dir+0xc0>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11f0 <get_current_dir+0xc0>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <get_current_dir+0xc8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_current_dir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x40,%r14d
mov    0x2e93(%rip),%r15
mov    0x2e9c(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <xcalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <getcwd@plt>
test   %rax,%rax
je     1179 <get_current_dir+0x49>
cmpl   $0x0,(%r12)
je     1150 <get_current_dir+0x20>
jmp    118f <get_current_dir+0x5f>
mov    (%r15),%ebp
add    %r14,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
cmp    (%r12),%ebp
je     1150 <get_current_dir+0x20>
jmp    11a1 <get_current_dir+0x71>
test   %rbx,%rbx
je     11a1 <get_current_dir+0x71>
cmpb   $0x2f,(%rbx)
je     11a3 <get_current_dir+0x73>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@ERANGE = global i32 0
define i8* @get_current_dir() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i64
%4 = alloca i8*
store i32 0, i32* %2
store i64 64, i64* %3
store i8* null, i8** %4
br label %5
5: ; preds = %19, %0
store i32 0, i32* %2
%6 = load i64, i64* %3
%7 = call i8* @xcalloc(i64 %6, i32 1)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = load i64, i64* %3
%10 = call i32* @getcwd(i8* %8, i64 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %5
%13 = load i32, i32* @errno
store i32 %13, i32* %2
%14 = load i64, i64* %3
%15 = mul i64 %14, 2
store i64 %15, i64* %3
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
store i8* null, i8** %4
br label %18
18: ; preds = %12, %5
br label %19
19: ; preds = %18
%20 = load i32, i32* %2
%21 = load i32, i32* @ERANGE
%22 = icmp eq i32 %20, %21
br i1 %22, label %5, label %23
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 47
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
store i8* null, i8** %1
br label %36
34: ; preds = %26, %23
%35 = load i8*, i8** %4
store i8* %35, i8** %1
br label %36
36: ; preds = %34, %31
%37 = load i8*, i8** %1
ret i8* %37
}

LLVM IR (-O2):
@errno = global i32 0
@ERANGE = global i32 0
define i8* @get_current_dir() {
br label %1
1: ; preds = %10, %0
%2 = phi i64 [ %12, %10 ], [ 64, %0 ]
br label %3
3: ; preds = %1, %7
%4 = tail call i8* @xcalloc(i64 %2, i32 1)
%5 = tail call i32* @getcwd(i8* %4, i64 %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i32, i32* @ERANGE
%9 = icmp eq i32 %8, 0
br i1 %9, label %3, label %16
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = shl i64 %2, 1
%13 = tail call i32 @free(i8* %4)
%14 = load i32, i32* @ERANGE
%15 = icmp eq i32 %11, %14
br i1 %15, label %1, label %23
16: ; preds = %7
%17 = icmp eq i8* %4, null
br i1 %17, label %23, label %18
18: ; preds = %16
%19 = load i8, i8* %4
%20 = icmp eq i8 %19, 47
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @free(i8* %4)
br label %23
23: ; preds = %10, %16, %18, %21
%24 = phi i8* [ null, %21 ], [ %4, %18 ], [ null, %16 ], [ null, %10 ]
ret i8* %24
}