#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;
scalar_t__ INADDR_ANY;
int /*<<< orphan*/ htonl(scalar_t__);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
extern struct sockaddr_in prepareSocketAddress(struct sockaddr_in sa,
                                               int port) {
  memset(&sa, 0, sizeof sa);
  sa.sin_family = AF_INET;
  sa.sin_port = htons(port);
  if (INADDR_ANY) {
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
  }
  return sa;
}


x86 assembly (clang, -O0):
<prepareSocketAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x30(%rbp)
mov    %esi,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    %edx,-0x34(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x34(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e62(%rip),%rax
cmpq   $0x0,(%rax)
je     119a <prepareSocketAddress+0x6a>
mov    0x2e51(%rip),%rax
mov    (%rax),%rdi
call   1040 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%edx
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepareSocketAddress>:
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rdi,(%rsp)
mov    %esi,0x8(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e73(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     117d <prepareSocketAddress+0x4d>
call   1040 <htonl@plt>
mov    %eax,(%rsp)
mov    (%rsp),%rax
mov    0x8(%rsp),%edx
add    $0x10,%rsp
pop    %rbx
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 i64 0
define { i64, i32 } @prepareSocketAddress(i64 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca { i64, i32 }
%7 = alloca i32
%8 = alloca { i64, i32 }
%9 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %6, i32 0, i32 0
store i64 %0, i64* %9
%10 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %6, i32 0, i32 1
store i32 %1, i32* %10
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = bitcast { i64, i32 }* %6 to i8*
store i32 %2, i32* %7
%13 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* %7
%17 = call i32 @htons(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i64, i64* @INADDR_ANY
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = load i64, i64* @INADDR_ANY
%23 = call i32 @htonl(i64 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
br label %26
26: ; preds = %21, %3
%27 = bitcast %struct.sockaddr_in* %4 to i8*
%28 = bitcast %struct.sockaddr_in* %5 to i8*
%29 = bitcast { i64, i32 }* %8 to i8*
%30 = bitcast %struct.sockaddr_in* %4 to i8*
%31 = load { i64, i32 }, { i64, i32 }* %8
ret { i64, i32 } %31
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i64 0
define { i64, i32 } @prepareSocketAddress(i64 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i64*
store i64 %0, i64* %5
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %1, i32* %6
%7 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%8 = load i32, i32* @AF_INET
store i32 %8, i32* %6
%9 = call i32 @htons(i32 %2)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %9, i32* %10
%11 = load i64, i64* @INADDR_ANY
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = call i32 @htonl(i64 %11)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %14, i32* %15
br label %16
16: ; preds = %13, %3
%17 = load i64, i64* %5
%18 = load i32, i32* %6
%19 = insertvalue { i64, i32 } poison, i64 %17, 0
%20 = insertvalue { i64, i32 } %19, i32 %18, 1
ret { i64, i32 } %20
}