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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int __ipv4_udp_socket(struct sockaddr_in *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_aton(char const *, int /*<<< orphan*/ *);
int ipv4_udp_socket(const char *ipv4_addr, u_int16_t port) {
  struct sockaddr_in addr;
  addr.sin_port = htons(port);
  addr.sin_family = AF_INET;
  inet_aton(ipv4_addr, &(addr.sin_addr));
  return __ipv4_udp_socket(&addr);
}


x86 assembly (clang, -O0):
<ipv4_udp_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <inet_aton@plt>
lea    -0x18(%rbp),%rdi
call   1030 <__ipv4_udp_socket@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_udp_socket>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    %esi,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <inet_aton@plt>
mov    %r14,%rdi
call   1030 <__ipv4_udp_socket@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
define i32 @ipv4_udp_socket(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i32 @htons(i32 %6)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i8*, i8** %3
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%13 = call i32 @inet_aton(i8* %11, i32* %12)
%14 = call i32 @__ipv4_udp_socket(%struct.sockaddr_in* %5)
ret i32 %14
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
define i32 @ipv4_udp_socket(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = tail call i32 @htons(i32 %1)
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %5, i32* %6
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%10 = call i32 @inet_aton(i8* %0, i32* %9)
%11 = call i32 @__ipv4_udp_socket(%struct.sockaddr_in* %3)
ret i32 %11
}