#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*/ exit(int);
char *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int strlen(char *);
void fortrangetcwd_(char *pathnm, int *stat, int *lenstr, int pathnmlength) {
  char *buf = "getcwd";
  if (!(buf = getcwd(pathnm, pathnmlength))) {
    perror("Failed : getcwd in posixwrapper:fortrangetcwd");
    *stat = -1;
    exit(1);
  }
  *stat = 0;
  *lenstr = strlen(pathnm);
}


x86 assembly (clang, -O0):
<fortrangetcwd_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    0xec9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <getcwd@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    119c <fortrangetcwd_+0x5c>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fortrangetcwd_>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,%esi
call   1040 <getcwd@plt>
test   %rax,%rax
je     1172 <fortrangetcwd_+0x32>
movl   $0x0,(%r15)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,(%r15)
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"getcwd\00"
@.str.1 = [46 x i8] c"Failed : getcwd in posixwrapper:fortrangetcwd\00"
define void @fortrangetcwd_(i8* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %5
%11 = load i32, i32* %8
%12 = call i8* @getcwd(i8* %10, i32 %11)
store i8* %12, i8** %9
%13 = icmp ne i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32*, i32** %6
store i32 -1, i32* %16
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %4
%19 = load i32*, i32** %6
store i32 0, i32* %19
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = load i32*, i32** %7
store i32 %21, i32* %22
ret void
}

LLVM IR (-O2):
@.str.1 = [46 x i8] c"Failed : getcwd in posixwrapper:fortrangetcwd\00"
define void @fortrangetcwd_(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32 %3) {
%5 = tail call i8* @getcwd(i8* %0, i32 %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4
store i32 0, i32* %1
%11 = tail call i32 @strlen(i8* %0)
store i32 %11, i32* %2
ret void
}