#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 errno;
int /*<<< orphan*/ free(char *);
scalar_t__ getcwd(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
void getcwd_f_(char *path, int *len, int *ierr) {
  char *buf = (char *)malloc((*len + 1));
  if (getcwd(buf, *len)) {
    strcpy(path, buf);
    *ierr = 0;
  } else {
    strcpy(path, "\0");
    *ierr = errno;
  }
  free(buf);
}


x86 assembly (clang, -O0):
<getcwd_f_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
je     119b <getcwd_f_+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    11ba <getcwd_f_+0x7a>
mov    -0x8(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcwd_f_>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    (%rbx),%esi
mov    %rax,%rdi
call   1050 <getcwd@plt>
test   %rax,%rax
je     117c <getcwd_f_+0x3c>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
jmp    1194 <getcwd_f_+0x54>
lea    0xe7d(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
@errno = global i32 0
define void @getcwd_f_(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%8 = load i32*, i32** %5
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = call i64 @getcwd(i8* %13, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = load i8*, i8** %7
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i32*, i32** %6
store i32 0, i32* %22
br label %28
23: ; preds = %3
%24 = load i8*, i8** %4
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @errno
%27 = load i32*, i32** %6
store i32 %26, i32* %27
br label %28
28: ; preds = %23, %18
%29 = load i8*, i8** %7
%30 = call i32 @free(i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
@errno = global i32 0
define void @getcwd_f_(i8* %0, i32* nocapture %1, i32* nocapture writeonly %2) {
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = load i32, i32* %1
%9 = tail call i64 @getcwd(i8* %7, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = tail call i32 @strcpy(i8* %0, i8* %7)
br label %16
13: ; preds = %3
%14 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @errno
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ %15, %13 ], [ 0, %11 ]
store i32 %17, i32* %2
%18 = tail call i32 @free(i8* %7)
ret void
}