#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 */
struct stat {
  int /*<<< orphan*/ st_ino;
  int /*<<< orphan*/ st_dev;
};

/* Variables and functions */
int /*<<< orphan*/ __set_errno(int);
int errno;
char *recurser(char *, unsigned long, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int __syscall_getcwd(char *buf, unsigned long size) {
  int len;
  char *cwd;
  struct stat st;
  int olderrno;
  olderrno = errno;
  len = -1;
  cwd = recurser(buf, size, st.st_dev, st.st_ino);
  if (cwd) {
    len = strlen(buf);
    __set_errno(olderrno);
  }
  return len;
}


x86 assembly (clang, -O0):
<__syscall_getcwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1040 <recurser@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1189 <__syscall_getcwd+0x59>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <__set_errno@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__syscall_getcwd>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea3(%rip),%rax
mov    (%rax),%ebp
call   1040 <recurser@plt>
test   %rax,%rax
je     115e <__syscall_getcwd+0x2e>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <__set_errno@plt>
mov    %ebx,%eax
jmp    1163 <__syscall_getcwd+0x33>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@errno = global i32 0
define i32 @__syscall_getcwd(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.stat
%8 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = load i32, i32* @errno
store i32 %9, i32* %8
store i32 -1, i32* %5
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i8* @recurser(i8* %10, i64 %11, i32 %13, i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %5
%22 = load i32, i32* %8
%23 = call i32 @__set_errno(i32 %22)
br label %24
24: ; preds = %19, %2
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @__syscall_getcwd(i8* %0, i64 %1) {
%3 = load i32, i32* @errno
%4 = tail call i8* @recurser(i8* %0, i64 %1, i32 undef, i32 undef)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @__set_errno(i32 %3)
br label %9
9: ; preds = %6, %2
%10 = phi i32 [ %7, %6 ], [ -1, %2 ]
ret i32 %10
}