#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 errno;
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
void gethostname_f_(char *hostname, int *ierr) {
  char lhostname[256];
  if (gethostname(lhostname, 255)) {
    strcpy(hostname, "\0");
    *ierr = errno;
  } else {
    strcpy(hostname, lhostname);
    *ierr = 0;
  }
}


x86 assembly (clang, -O0):
<gethostname_f_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0xff,%esi
call   1040 <gethostname@plt>
cmp    $0x0,%rax
je     1172 <gethostname_f_+0x52>
mov    -0x8(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    118c <gethostname_f_+0x6c>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethostname_f_>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0xff,%esi
call   1040 <gethostname@plt>
test   %rax,%rax
je     115c <gethostname_f_+0x3c>
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
jmp    1169 <gethostname_f_+0x49>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %eax,(%r14)
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
@errno = global i32 0
define void @gethostname_f_(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = call i64 @gethostname(i8* %6, i32 255)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @errno
%13 = load i32*, i32** %4
store i32 %12, i32* %13
br label %19
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i32*, i32** %4
store i32 0, i32* %18
br label %19
19: ; preds = %14, %9
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
@errno = global i32 0
define void @gethostname_f_(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i64 @gethostname(i8* %4, i32 255)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @errno
br label %12
10: ; preds = %2
%11 = call i32 @strcpy(i8* %0, i8* %4)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ 0, %10 ], [ %9, %7 ]
store i32 %13, i32* %1
ret void
}