#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 */
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int get_server_ip(char *server_ip, char *server_port) {
  const char *gs_server = getenv("GPUSOCK_SERVER"),
             *gs_port = getenv("GPUSOCK_PORT");
  if (gs_server == NULL) {
    gs_server = "localhost";
    ("GPUSOCK_SERVER not defined, using default server ip: %s\n", gs_server);
  }
  if (gs_port == NULL) {
    gs_port = "8888";
    ("GPUSOCK_PORT not defined, using default server port: %s\n", gs_port);
  }
  sprintf(server_ip, "%s", gs_server);
  sprintf(server_port, "%s", gs_port);
  if (server_ip[0] != '\0' && server_port[0] != '\0')
    return 0;
  else if (server_port[0] != '\0')
    return 1;
  else if (server_ip[0] != '\0')
    return 2;
  else
    return 3;
}


x86 assembly (clang, -O0):
<get_server_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xec9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
lea    0xec8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1166 <get_server_ip+0x46>
lea    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117c <get_server_ip+0x5c>
lea    0xee7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xf12(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xefe(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d0 <get_server_ip+0xb0>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d0 <get_server_ip+0xb0>
movl   $0x0,-0x4(%rbp)
jmp    120f <get_server_ip+0xef>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ec <get_server_ip+0xcc>
movl   $0x1,-0x4(%rbp)
jmp    120f <get_server_ip+0xef>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1208 <get_server_ip+0xe8>
movl   $0x2,-0x4(%rbp)
jmp    120f <get_server_ip+0xef>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_server_ip>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xece(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xece(%rip),%rdi
call   1030 <getenv@plt>
test   %rbx,%rbx
lea    0xecc(%rip),%rsi
cmovne %rbx,%rsi
test   %rax,%rax
lea    0xec8(%rip),%rbx
cmovne %rax,%rbx
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
xor    %ecx,%ecx
cmpb   $0x0,(%r15)
sete   %cl
lea    0x2(%rcx),%eax
cmpb   $0x0,(%r14)
cmovne %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"GPUSOCK_SERVER\00"
@.str.1 = [13 x i8] c"GPUSOCK_PORT\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [57 x i8] c"GPUSOCK_SERVER not defined, using default server ip: %s\0A\00"
@.str.4 = [5 x i8] c"8888\00"
@.str.5 = [57 x i8] c"GPUSOCK_PORT not defined, using default server port: %s\0A\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @get_server_ip(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
%9 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %6
%13 = load i8*, i8** %6
br label %14
14: ; preds = %12, %2
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %7
%18 = load i8*, i8** %7
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %4
%21 = load i8*, i8** %6
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %5
%24 = load i8*, i8** %7
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %19
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 0, i32* %3
br label %53
38: ; preds = %31, %19
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 1, i32* %3
br label %53
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %45
store i32 2, i32* %3
br label %53
52: ; preds = %45
store i32 3, i32* %3
br label %53
53: ; preds = %52, %51, %44, %37
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [15 x i8] c"GPUSOCK_SERVER\00"
@.str.1 = [13 x i8] c"GPUSOCK_PORT\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.4 = [5 x i8] c"8888\00"
define i32 @get_server_ip(i8* %0, i8* %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %3, null
%6 = select i1 %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %3
%7 = icmp eq i8* %4, null
%8 = select i1 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %4
%9 = tail call i8* @strcpy(i8* dereferenceable(1) %0, i8* dereferenceable(1) %6)
%10 = tail call i8* @strcpy(i8* dereferenceable(1) %1, i8* dereferenceable(1) %8)
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 0
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 0
%15 = select i1 %12, i32 3, i32 2
%16 = zext i1 %12 to i32
%17 = select i1 %14, i32 %15, i32 %16
ret i32 %17
}