#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 */
struct utsname {
  char *nodename;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *smalloc(scalar_t__);
char *sstrdup(char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ uname(struct utsname *);
char *value(char *);
char *nodename(int mayoverride) {
  static char *hostname;
  char *hn;
  struct utsname ut;
  if (mayoverride && (hn = value("hostname")) != NULL && *hn) {
    free(hostname);
    hostname = sstrdup(hn);
  }
  if (hostname == NULL) {
    uname(&ut);
    hn = ut.nodename;
    hostname = smalloc(strlen(hn) + 1);
    strcpy(hostname, hn);
  }
  return hostname;
}


x86 assembly (clang, -O0):
<nodename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11cb <nodename+0x5b>
lea    0xe74(%rip),%rdi
call   1080 <value@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11cb <nodename+0x5b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cb <nodename+0x5b>
mov    0x2eaa(%rip),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1070 <sstrdup@plt>
mov    %rax,0x2e95(%rip)
cmpq   $0x0,0x2e8d(%rip)
jne    1216 <nodename+0xa6>
lea    -0x18(%rbp),%rdi
call   1060 <uname@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <smalloc@plt>
mov    %rax,0x2e5a(%rip)
mov    0x2e53(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    0x2e43(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nodename>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     11b4 <nodename+0x44>
lea    0xe80(%rip),%rdi
call   1080 <value@plt>
test   %rax,%rax
je     11b4 <nodename+0x44>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11b4 <nodename+0x44>
mov    0x2ec7(%rip),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <sstrdup@plt>
mov    %rax,0x2eb3(%rip)
test   %rax,%rax
jne    11f9 <nodename+0x89>
jmp    11c0 <nodename+0x50>
mov    0x2ea5(%rip),%rax
test   %rax,%rax
jne    11f9 <nodename+0x89>
lea    0x8(%rsp),%rdi
call   1060 <uname@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1090 <smalloc@plt>
mov    %rax,0x2e79(%rip)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0x2e67(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.utsname = type { i8* }
@nodename.hostname = internal global i8* null
@.str = [9 x i8] c"hostname\00"
define i8* @nodename(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.utsname
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = call i8* @value(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i8*, i8** @nodename.hostname
%17 = call i32 @free(i8* %16)
%18 = load i8*, i8** %3
%19 = call i8* @sstrdup(i8* %18)
store i8* %19, i8** @nodename.hostname
br label %20
20: ; preds = %15, %10, %7, %1
%21 = load i8*, i8** @nodename.hostname
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %34
23: ; preds = %20
%24 = call i32 @uname(%struct.utsname* %4)
%25 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%26 = load i8*, i8** %25
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i8* @smalloc(i64 %29)
store i8* %30, i8** @nodename.hostname
%31 = load i8*, i8** @nodename.hostname
%32 = load i8*, i8** %3
%33 = call i32 @strcpy(i8* %31, i8* %32)
br label %34
34: ; preds = %23, %20
%35 = load i8*, i8** @nodename.hostname
ret i8* %35
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
@nodename.hostname = internal unnamed_addr global i8* null
@.str = [9 x i8] c"hostname\00"
define i8* @nodename(i32 %0) {
%2 = alloca %struct.utsname
%3 = bitcast %struct.utsname* %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = tail call i8* @value(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i8*, i8** @nodename.hostname
%13 = tail call i32 @free(i8* %12)
%14 = tail call i8* @sstrdup(i8* %6)
store i8* %14, i8** @nodename.hostname
br label %17
15: ; preds = %1, %5, %8
%16 = load i8*, i8** @nodename.hostname
br label %17
17: ; preds = %15, %11
%18 = phi i8* [ %16, %15 ], [ %14, %11 ]
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = call i32 @uname(%struct.utsname* %2)
%22 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = tail call i64 @strlen(i8* dereferenceable(1) %23)
%25 = add nsw i64 %24, 1
%26 = tail call i8* @smalloc(i64 %25)
store i8* %26, i8** @nodename.hostname
%27 = tail call i32 @strcpy(i8* %26, i8* %23)
%28 = load i8*, i8** @nodename.hostname
br label %29
29: ; preds = %20, %17
%30 = phi i8* [ %28, %20 ], [ %18, %17 ]
ret i8* %30
}