#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
struct sockaddr_in get_server_address(char *ip, int port) {
  struct sockaddr_in server_address;
  server_address.sin_family = AF_INET;
  server_address.sin_port = htons(port);
  if (ip == NULL) {
    server_address.sin_addr.s_addr = htonl(INADDR_ANY);
  } else {
    server_address.sin_addr.s_addr = inet_addr(ip);
  }
  return server_address;
}


x86 assembly (clang, -O0):
<get_server_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <get_server_address+0x47>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x10(%rbp)
jmp    1183 <get_server_address+0x53>
mov    -0x18(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%edx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_server_address>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
mov    0x2eaa(%rip),%rax
mov    (%rax),%r14d
mov    %esi,%edi
call   1030 <htons@plt>
mov    %eax,%ebx
test   %rbp,%rbp
je     1159 <get_server_address+0x29>
mov    %rbp,%rdi
call   1050 <inet_addr@plt>
jmp    1167 <get_server_address+0x37>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
shl    $0x20,%rbx
mov    %eax,%eax
or     %rbx,%rax
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
define { i64, i32 } @get_server_address(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i8*
%5 = alloca i32
%6 = alloca { i64, i32 }
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* %5
%10 = call i32 @htons(i32 %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %10, i32* %11
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
br label %24
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i32 @inet_addr(i8* %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
br label %24
24: ; preds = %19, %14
%25 = bitcast { i64, i32 }* %6 to i8*
%26 = bitcast %struct.sockaddr_in* %3 to i8*
%27 = load { i64, i32 }, { i64, i32 }* %6
ret { i64, i32 } %27
}

LLVM IR (-O2):
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
define { i64, i32 } @get_server_address(i8* %0, i32 %1) {
%3 = load i32, i32* @AF_INET
%4 = tail call i32 @htons(i32 %1)
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @INADDR_ANY
%8 = tail call i32 @htonl(i32 %7)
br label %11
9: ; preds = %2
%10 = tail call i32 @inet_addr(i8* %0)
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %8, %6 ], [ %10, %9 ]
%13 = zext i32 %4 to i64
%14 = shl nuw i64 %13, 32
%15 = zext i32 %12 to i64
%16 = or i64 %14, %15
%17 = insertvalue { i64, i32 } poison, i64 %16, 0
%18 = insertvalue { i64, i32 } %17, i32 %3, 1
ret { i64, i32 } %18
}