#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 */
typedef scalar_t__ uint16_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ htons(unsigned short);
int inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
struct sockaddr_in makeSockaddr(const char *localAddr, uint16_t localPort) {
  struct sockaddr_in addr = {0};
  addr.sin_family = AF_INET;
  addr.sin_port = htons((unsigned short)localPort);
  int ok = inet_pton(AF_INET, localAddr, &addr.sin_addr);
  if (!ok)
    addr.sin_family = AF_UNSPEC;
  return addr;
}


x86 assembly (clang, -O0):
<makeSockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
movzwl %ax,%edi
call   1030 <htons@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
add    $0x4,%rdx
call   1050 <inet_pton@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    119e <makeSockaddr+0x6e>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeSockaddr>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2eb0(%rip),%r14
mov    (%r14),%eax
mov    %eax,(%rsp)
movzwl %si,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%r14),%edi
lea    0x4(%rsp),%rdx
mov    %rbx,%rsi
call   1040 <inet_pton@plt>
test   %eax,%eax
jne    116a <makeSockaddr+0x4a>
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    (%rsp),%rax
mov    0x8(%rsp),%rdx
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32, i32 }
@AF_INET = global i32 0
@AF_UNSPEC = global i32 0
define { i64, i64 } @makeSockaddr(i8* %0, i64 %1) {
%3 = alloca { i64, i64 }
%4 = bitcast { i64, i64 }* %3 to %struct.sockaddr_in*
%5 = bitcast { i64, i64 }* %3 to i8*
%6 = load i32, i32* @AF_INET
%7 = bitcast { i64, i64 }* %3 to i32*
store i32 %6, i32* %7
%8 = trunc i64 %1 to i16
%9 = tail call i32 @htons(i16 zeroext %8)
%10 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %3, i64 0, i32 1
%11 = bitcast i64* %10 to i32*
store i32 %9, i32* %11
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%14 = call i32 @inet_pton(i32 %12, i8* %0, i32* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* @AF_UNSPEC
store i32 %17, i32* %7
br label %18
18: ; preds = %16, %2
%19 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %3, i64 0, i32 0
%20 = load i64, i64* %19
%21 = insertvalue { i64, i64 } poison, i64 %20, 0
%22 = load i64, i64* %10
%23 = insertvalue { i64, i64 } %21, i64 %22, 1
ret { i64, i64 } %23
}