#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);
int gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int strlen(char *);
void fortrangethostname_(char *hostnmstring, int *stat, int *lenstr,
                         int hostnmlength) {
  if ((*stat = gethostname(hostnmstring, hostnmlength)) == -1) {
    perror("Failed : gethostname in posixwrapper:fortrangethostname");
    exit(1);
  }
  *lenstr = strlen(hostnmstring);
  *stat = 0;
}


x86 assembly (clang, -O0):
<fortrangethostname_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <gethostname@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    1188 <fortrangethostname_+0x48>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fortrangethostname_>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,%esi
call   1050 <gethostname@plt>
mov    %eax,(%r15)
cmp    $0xffffffff,%eax
je     1175 <fortrangethostname_+0x35>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,(%r14)
movl   $0x0,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe84(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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