#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int gethostname(char *, int);
char *host_name(void) {
  static char buf[256];
  int ret;
  do {
    errno = 0;
    do {
      ret = (gethostname(buf, sizeof(buf)));
    } while (ret < 0 && errno == EINTR);
  } while (0);
  ;
  if (ret < 0)
    return "localhost";
  else
    return buf;
}


x86 assembly (clang, -O0):
<host_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec1(%rip),%rax
movq   $0x0,(%rax)
lea    0x2f13(%rip),%rdi
mov    $0x100,%esi
call   1030 <gethostname@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jge    1163 <host_name+0x53>
mov    0x2e90(%rip),%rax
mov    (%rax),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1126 <host_name+0x16>
jmp    1173 <host_name+0x63>
cmpl   $0x0,-0xc(%rbp)
jge    118d <host_name+0x7d>
lea    0xe7c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <host_name+0x88>
lea    0x2eac(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host_name>:
push   %r15
push   %r14
push   %rbx
mov    0x2ec4(%rip),%r14
movq   $0x0,(%r14)
lea    0x2f16(%rip),%rbx
mov    0x2ea7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <gethostname@plt>
test   %eax,%eax
jns    1159 <host_name+0x49>
mov    (%r15),%rcx
cmp    %rcx,(%r14)
je     1140 <host_name+0x30>
test   %eax,%eax
lea    0xe9e(%rip),%rax
cmovs  %rax,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@host_name.buf = internal global [256 x i8] zeroinitializer
@errno = global i64 0
@EINTR = global i64 0
@.str = [10 x i8] c"localhost\00"
define i8* @host_name() {
%1 = alloca i8*
%2 = alloca i32
br label %3
3: ; preds = %0
store i64 0, i64* @errno
br label %4
4: ; preds = %13, %3
%5 = call i32 @gethostname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @host_name.buf, i64 0, i64 0), i32 256)
store i32 %5, i32* %2
br label %6
6: ; preds = %4
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ false, %6 ], [ %12, %9 ]
br i1 %14, label %4, label %15
15: ; preds = %13
br label %16
16: ; preds = %15
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %1
br label %21
20: ; preds = %16
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @host_name.buf, i64 0, i64 0), i8** %1
br label %21
21: ; preds = %20, %19
%22 = load i8*, i8** %1
ret i8* %22
}

LLVM IR (-O2):
@host_name.buf = internal global [256 x i8] zeroinitializer
@errno = global i64 0
@EINTR = global i64 0
@.str = [10 x i8] c"localhost\00"
define i8* @host_name() {
store i64 0, i64* @errno
br label %1
1: ; preds = %1, %0
%2 = tail call i32 @gethostname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @host_name.buf, i64 0, i64 0), i32 256)
%3 = icmp slt i32 %2, 0
%4 = load i64, i64* @errno
%5 = load i64, i64* @EINTR
%6 = icmp eq i64 %4, %5
%7 = select i1 %3, i1 %6, i1 false
br i1 %7, label %1, label %8
8: ; preds = %1
%9 = select i1 %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @host_name.buf, i64 0, i64 0)
ret i8* %9
}