#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*/ environ_name_to_value(char *, char *);
char *strdup(char *);
char *appaserver_library_get_server_address(void) {
  char server_address[128] = {0};
  if (!environ_name_to_value(server_address, "HTTP_HOST")) {
    if (!environ_name_to_value(server_address, "SERVER_NAME")) {
      if (!environ_name_to_value(server_address, "SERVER_ADDR")) {
        environ_name_to_value(server_address, "HOSTNAME");
      }
    }
  }
  return strdup(server_address);
}


x86 assembly (clang, -O0):
<appaserver_library_get_server_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
lea    -0x80(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1040 <environ_name_to_value@plt>
cmp    $0x0,%eax
jne    11b0 <appaserver_library_get_server_address+0x80>
lea    -0x80(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1040 <environ_name_to_value@plt>
cmp    $0x0,%eax
jne    11ab <appaserver_library_get_server_address+0x7b>
lea    -0x80(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1040 <environ_name_to_value@plt>
cmp    $0x0,%eax
jne    11a6 <appaserver_library_get_server_address+0x76>
lea    -0x80(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1040 <environ_name_to_value@plt>
jmp    11ab <appaserver_library_get_server_address+0x7b>
jmp    11b0 <appaserver_library_get_server_address+0x80>
lea    -0x80(%rbp),%rdi
call   1050 <strdup@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appaserver_library_get_server_address>:
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xea8(%rip),%rsi
mov    %rsp,%rdi
call   1030 <environ_name_to_value@plt>
test   %eax,%eax
jne    1199 <appaserver_library_get_server_address+0x79>
lea    0xe9f(%rip),%rsi
mov    %rsp,%rdi
call   1030 <environ_name_to_value@plt>
test   %eax,%eax
jne    1199 <appaserver_library_get_server_address+0x79>
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
call   1030 <environ_name_to_value@plt>
test   %eax,%eax
jne    1199 <appaserver_library_get_server_address+0x79>
lea    0xe91(%rip),%rsi
mov    %rsp,%rdi
call   1030 <environ_name_to_value@plt>
mov    %rsp,%rdi
call   1040 <strdup@plt>
add    $0x88,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"HTTP_HOST\00"
@.str.1 = [12 x i8] c"SERVER_NAME\00"
@.str.2 = [12 x i8] c"SERVER_ADDR\00"
@.str.3 = [9 x i8] c"HOSTNAME\00"
define i8* @appaserver_library_get_server_address() {
%1 = alloca [128 x i8]
%2 = bitcast [128 x i8]* %1 to i8*
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = call i32 @environ_name_to_value(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%8 = call i32 @environ_name_to_value(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp ne i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%12 = call i32 @environ_name_to_value(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%16 = call i32 @environ_name_to_value(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %14, %10
br label %18
18: ; preds = %17, %6
br label %19
19: ; preds = %18, %0
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%21 = call i8* @strdup(i8* %20)
ret i8* %21
}

LLVM IR (-O2):
@.str = [10 x i8] c"HTTP_HOST\00"
@.str.1 = [12 x i8] c"SERVER_NAME\00"
@.str.2 = [12 x i8] c"SERVER_ADDR\00"
@.str.3 = [9 x i8] c"HOSTNAME\00"
define noalias i8* @appaserver_library_get_server_address() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 @environ_name_to_value(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %0
%6 = call i32 @environ_name_to_value(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = call i32 @environ_name_to_value(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @environ_name_to_value(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %5, %11, %8, %0
%14 = call i8* @strdup(i8* %2)
ret i8* %14
}