#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 */
char *getenv(char *);
int /*<<< orphan*/ uname(struct utsname *);
const char *cgi_server_name(void) {
  const char *sn;
  struct utsname un;
  sn = getenv("SERVER_NAME");
  if (!sn) {
    sn = getenv("HOSTNAME");
    if (!sn) {
      uname(&un);
      sn = un.nodename;
    }
  }
  return (sn);
}


x86 assembly (clang, -O0):
<cgi_server_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1174 <cgi_server_name+0x54>
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116f <cgi_server_name+0x4f>
lea    -0x10(%rbp),%rdi
call   1040 <uname@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1174 <cgi_server_name+0x54>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgi_server_name>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1134 <cgi_server_name+0x14>
pop    %rcx
ret
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1132 <cgi_server_name+0x12>
mov    %rsp,%rdi
call   1040 <uname@plt>
mov    (%rsp),%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.utsname = type { i8* }
@.str = [12 x i8] c"SERVER_NAME\00"
@.str.1 = [9 x i8] c"HOSTNAME\00"
define i8* @cgi_server_name() {
%1 = alloca i8*
%2 = alloca %struct.utsname
%3 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
br i1 %5, label %15, label %6
6: ; preds = %0
%7 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = icmp ne i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = call i32 @uname(%struct.utsname* %2)
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%13 = load i8*, i8** %12
store i8* %13, i8** %1
br label %14
14: ; preds = %10, %6
br label %15
15: ; preds = %14, %0
%16 = load i8*, i8** %1
ret i8* %16
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
@.str = [12 x i8] c"SERVER_NAME\00"
@.str.1 = [9 x i8] c"HOSTNAME\00"
define i8* @cgi_server_name() {
%1 = alloca %struct.utsname
%2 = bitcast %struct.utsname* %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = call i32 @uname(%struct.utsname* %1)
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%11 = load i8*, i8** %10
br label %12
12: ; preds = %5, %8, %0
%13 = phi i8* [ %3, %0 ], [ %6, %5 ], [ %11, %8 ]
ret i8* %13
}