#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*/ atoi(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int to_sockaddr_in(char *ip, char *port, struct sockaddr_in *a) {
  a->sin_family = AF_INET;
  a->sin_port = htons(atoi(port));
  a->sin_addr.s_addr = inet_addr(ip);
  return 0;
}


x86 assembly (clang, -O0):
<to_sockaddr_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_sockaddr_in>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rdx)
mov    %rsi,%rdi
call   1050 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    %r14,%rdi
call   1040 <inet_addr@plt>
mov    %eax,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define i32 @to_sockaddr_in(i8* %0, i8* nocapture %1, %struct.sockaddr_in* nocapture writeonly %2) {
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %4, i32* %5
%6 = tail call i32 @atoi(i8* %1)
%7 = tail call i32 @htons(i32 %6)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = tail call i32 @inet_addr(i8* %0)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %9, i32* %10
ret i32 0
}