#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 */
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ fossil_fatal(char *, int);
scalar_t__ getcwd(char *, int);
int strerror(scalar_t__);
void file_getcwd(char *zBuf, int nBuf) {
  if (getcwd(zBuf, nBuf - 1) == 0) {
    if (errno == ERANGE) {
      fossil_fatal("pwd too big: max %d\n", nBuf - 1);
    } else {
      fossil_fatal("cannot find current working directory; %s",
                   strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<file_getcwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
jne    11ab <file_getcwd+0x7b>
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%rax
jne    1189 <file_getcwd+0x59>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
lea    0xe81(%rip),%rdi
call   1030 <fossil_fatal@plt>
jmp    11a6 <file_getcwd+0x76>
mov    0x2e48(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe74(%rip),%rdi
call   1030 <fossil_fatal@plt>
jmp    11ab <file_getcwd+0x7b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_getcwd>:
push   %rbx
mov    %esi,%ebx
add    $0xffffffff,%ebx
mov    %ebx,%esi
call   1040 <getcwd@plt>
test   %rax,%rax
je     1144 <file_getcwd+0x14>
pop    %rbx
ret
mov    0x2e8d(%rip),%rax
mov    (%rax),%rdi
mov    0x2e93(%rip),%rax
cmp    (%rax),%rdi
jne    1169 <file_getcwd+0x39>
lea    0xe9f(%rip),%rdi
mov    %ebx,%esi
pop    %rbx
jmp    1030 <fossil_fatal@plt>
call   1050 <strerror@plt>
lea    0xea0(%rip),%rdi
mov    %eax,%esi
pop    %rbx
jmp    1030 <fossil_fatal@plt>

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [21 x i8] c"pwd too big: max %d\0A\00"
@.str.1 = [42 x i8] c"cannot find current working directory; %s\00"
define void @file_getcwd(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = load i32, i32* %4
%7 = sub nsw i32 %6, 1
%8 = call i64 @getcwd(i8* %5, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i64, i64* @errno
%12 = load i64, i64* @ERANGE
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = call i32 @fossil_fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %22
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = call i32 @strerror(i64 %19)
%21 = call i32 @fossil_fatal(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %14
br label %23
23: ; preds = %22, %2
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [21 x i8] c"pwd too big: max %d\0A\00"
@.str.1 = [42 x i8] c"cannot find current working directory; %s\00"
define void @file_getcwd(i8* %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = tail call i64 @getcwd(i8* %0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @fossil_fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %15
12: ; preds = %6
%13 = tail call i32 @strerror(i64 %7)
%14 = tail call i32 @fossil_fatal(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %10, %12, %2
ret void
}