#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_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, unsigned char *, int);
struct sockaddr *iptoaddr(struct sockaddr *ifaddr, unsigned char ip[4],
                          int port) {
  struct sockaddr_in *in = (struct sockaddr_in *)ifaddr;
  in->sin_family = AF_INET;
  in->sin_port = htons(port);
  memcpy(&(in->sin_addr), ip, sizeof in->sin_addr);
  return ifaddr;
}


x86 assembly (clang, -O0):
<iptoaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iptoaddr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rdi)
mov    %edx,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define %struct.sockaddr* @iptoaddr(%struct.sockaddr* returned %0, i8* %1, i32 %2) {
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 2, i32 0
store i32 %4, i32* %5
%6 = tail call i32 @htons(i32 %2)
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 1, i32 0
store i32 %6, i32* %7
%8 = getelementptr %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%9 = tail call i32 @memcpy(i32* %8, i8* %1, i32 4)
ret %struct.sockaddr* %0
}