#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 */
char *appendtostring(char *, int);
int chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
void fortranchdir_(char *pathnm, int *stat, int pathnmlength) {
  int status;
  char *pathname;
  if (!(pathname = appendtostring(pathnm, pathnmlength))) {
    perror("Failed : appendtostring (pathname) in posixwrapper:fortranchdir");
    exit(1);
  }
  if ((status = chdir(pathname)) == -1) {
    perror("Failed : chdir in posixwrapper:fortranchdir");
    exit(1);
  }
  *stat = status;
}


x86 assembly (clang, -O0):
<fortranchdir_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <appendtostring@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1183 <fortranchdir_+0x43>
lea    0xe8c(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11ae <fortranchdir_+0x6e>
lea    0xea1(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fortranchdir_>:
push   %rbx
mov    %rsi,%rbx
mov    %edx,%esi
call   1030 <appendtostring@plt>
test   %rax,%rax
je     1161 <fortranchdir_+0x21>
mov    %rax,%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     116a <fortranchdir_+0x2a>
mov    %eax,(%rbx)
pop    %rbx
ret
lea    0xe98(%rip),%rdi
jmp    1171 <fortranchdir_+0x31>
lea    0xecf(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [64 x i8] c"Failed : appendtostring (pathname) in posixwrapper:fortranchdir\00"
@.str.1 = [44 x i8] c"Failed : chdir in posixwrapper:fortranchdir\00"
define void @fortranchdir_(i8* %0, i32* nocapture writeonly %1, i32 %2) {
%4 = tail call i8* @appendtostring(i8* %0, i32 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %3
%10 = tail call i32 @chdir(i8* %4)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9
store i32 %10, i32* %1
ret void
}