#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*/ fatal(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gethostname(char *, int const);
scalar_t__ malloc(int const);
extern char *str_host() {
  static char *name = 0;
  if (!name) {
    const int max = 80;
    name = (char *)malloc(max + 1);
    if (!name)
      fatal(0, "str_host(): malloc() failed");
    gethostname(name, max);
  }
  return name;
}


x86 assembly (clang, -O0):
<str_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpq   $0x0,0x2f00(%rip)
jne    118b <str_host+0x5b>
movl   $0x50,-0x4(%rbp)
mov    $0x51,%edi
call   1030 <malloc@plt>
mov    %rax,0x2ee2(%rip)
cmpq   $0x0,0x2eda(%rip)
jne    117a <str_host+0x4a>
xor    %edi,%edi
lea    0xe8b(%rip),%rsi
call   1050 <fatal@plt>
mov    0x2ebf(%rip),%rdi
mov    $0x50,%esi
call   1040 <gethostname@plt>
mov    0x2eae(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_host>:
push   %rax
mov    0x2f08(%rip),%rax
test   %rax,%rax
je     113f <str_host+0xf>
pop    %rcx
ret
mov    $0x51,%edi
call   1030 <malloc@plt>
mov    %rax,0x2ef0(%rip)
test   %rax,%rax
jne    116a <str_host+0x3a>
lea    0xea4(%rip),%rsi
xor    %edi,%edi
call   1050 <fatal@plt>
mov    0x2ed6(%rip),%rax
mov    %rax,%rdi
mov    $0x50,%esi
call   1040 <gethostname@plt>
mov    0x2ec2(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@str_host.name = internal global i8* null
@.str = [28 x i8] c"str_host(): malloc() failed\00"
define i8* @str_host() {
%1 = alloca i32
%2 = load i8*, i8** @str_host.name
%3 = icmp ne i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %0
store i32 80, i32* %1
%5 = call i64 @malloc(i32 81)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** @str_host.name
%7 = load i8*, i8** @str_host.name
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = load i8*, i8** @str_host.name
%13 = call i32 @gethostname(i8* %12, i32 80)
br label %14
14: ; preds = %11, %0
%15 = load i8*, i8** @str_host.name
ret i8* %15
}

LLVM IR (-O2):
@str_host.name = internal unnamed_addr global i8* null
@.str = [28 x i8] c"str_host(): malloc() failed\00"
define i8* @str_host() {
%1 = load i8*, i8** @str_host.name
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %14
3: ; preds = %0
%4 = tail call i64 @malloc(i32 81)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** @str_host.name
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @fatal(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** @str_host.name
br label %10
10: ; preds = %7, %3
%11 = phi i8* [ %9, %7 ], [ %5, %3 ]
%12 = tail call i32 @gethostname(i8* %11, i32 80)
%13 = load i8*, i8** @str_host.name
br label %14
14: ; preds = %10, %0
%15 = phi i8* [ %13, %10 ], [ %1, %0 ]
ret i8* %15
}