#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 */
scalar_t__ ENAMETOOLONG;
int /*<<< orphan*/ assert_perror(scalar_t__);
scalar_t__ errno;
int gethostname(char *, int);
char *mx_hostname(void) {
  static char hostname[1024] = "";
  int res;
  if (*hostname)
    return hostname;
  res = gethostname(hostname, 1024);
  if (res == -1) {
    if (errno != ENAMETOOLONG)
      assert_perror(errno);
    hostname[1024 - 1] = 0;
  }
  return hostname;
}


x86 assembly (clang, -O0):
<mx_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpb   $0x0,0x2f11(%rip)
je     1145 <mx_hostname+0x25>
lea    0x2f04(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119e <mx_hostname+0x7e>
lea    0x2ef4(%rip),%rdi
mov    $0x400,%esi
call   1040 <gethostname@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1193 <mx_hostname+0x73>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     118c <mx_hostname+0x6c>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rdi
call   1030 <assert_perror@plt>
movb   $0x0,0x32ac(%rip)
lea    0x2ea6(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mx_hostname>:
push   %rax
cmpb   $0x0,0x2f18(%rip)
jne    1162 <mx_hostname+0x42>
lea    0x2f0f(%rip),%rdi
mov    $0x400,%esi
call   1040 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    1162 <mx_hostname+0x42>
mov    0x2e99(%rip),%rax
mov    (%rax),%rdi
mov    0x2e87(%rip),%rax
cmp    (%rax),%rdi
je     115b <mx_hostname+0x3b>
call   1030 <assert_perror@plt>
movb   $0x0,0x32dd(%rip)
lea    0x2ed7(%rip),%rax
pop    %rcx
ret

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

LLVM IR (-O2):
@mx_hostname.hostname = internal global [1024 x i8] zeroinitializer
@errno = global i64 0
@ENAMETOOLONG = global i64 0
define i8* @mx_hostname() {
%1 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @mx_hostname.hostname, i64 0, i64 0)
%2 = icmp eq i8 %1, 0
br i1 %2, label %3, label %13
3: ; preds = %0
%4 = tail call i32 @gethostname(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @mx_hostname.hostname, i64 0, i64 0), i32 1024)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENAMETOOLONG
%9 = icmp eq i64 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @assert_perror(i64 %7)
br label %12
12: ; preds = %10, %6
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @mx_hostname.hostname, i64 0, i64 1023)
br label %13
13: ; preds = %3, %12, %0
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @mx_hostname.hostname, i64 0, i64 0)
}