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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ assert(char const *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char const *,
                             int /*<<< orphan*/ *);
void net_setaddress(struct sockaddr_in *addr, const char *ip, int port) {
  assert(ip);
  bzero(addr, sizeof(struct sockaddr_in));
  addr->sin_family = AF_INET;
  inet_pton(AF_INET, ip, &(addr->sin_addr));
  addr->sin_port = htons(port);
}


x86 assembly (clang, -O0):
<net_setaddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0xc,%esi
call   1060 <bzero@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
add    $0x4,%rdx
call   1050 <inet_pton@plt>
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_setaddress>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <assert@plt>
mov    %rbp,%rdi
mov    $0xc,%esi
call   1060 <bzero@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x8(%rbp)
lea    0x4(%rbp),%rdx
mov    %rbx,%rsi
call   1050 <inet_pton@plt>
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x0(%rbp)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
define void @net_setaddress(%struct.sockaddr_in* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in*
%5 = alloca i8*
%6 = alloca i32
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i8*, i8** %5
%8 = call i32 @assert(i8* %7)
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%10 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%11 = load i32, i32* @AF_INET
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %11, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i8*, i8** %5
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
%18 = call i32 @inet_pton(i32 %14, i8* %15, i32* %17)
%19 = load i32, i32* %6
%20 = call i32 @htons(i32 %19)
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
store i32 %20, i32* %22
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
define void @net_setaddress(%struct.sockaddr_in* %0, i8* %1, i32 %2) {
%4 = tail call i32 @assert(i8* %1)
%5 = tail call i32 @bzero(%struct.sockaddr_in* %0, i32 12)
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
%9 = tail call i32 @inet_pton(i32 %6, i8* %1, i32* %8)
%10 = tail call i32 @htons(i32 %2)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
store i32 %10, i32* %11
ret void
}