#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 in_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in_addr *, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int fillsockaddrRaw(struct sockaddr_in *sockaddr, unsigned int rawIP,
                    int portN) {
  struct in_addr *iap = (struct in_addr *)&rawIP;
  memset(sockaddr, 0, sizeof(struct sockaddr_in));
  sockaddr->sin_family = AF_INET;
  sockaddr->sin_port = htons(portN);
  memcpy(&sockaddr->sin_addr, iap, sizeof(struct in_addr));
  return 0;
}


x86 assembly (clang, -O0):
<fillsockaddrRaw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillsockaddrRaw>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
mov    %esi,0x4(%rsp)
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
define i32 @fillsockaddrRaw(%struct.sockaddr_in* %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.in_addr*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = bitcast i32* %5 to %struct.in_addr*
store %struct.in_addr* %8, %struct.in_addr** %7
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%10 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, 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* %6
%15 = call i32 @htons(i32 %14)
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
store i32 %15, i32* %17
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = load %struct.in_addr*, %struct.in_addr** %7
%21 = call i32 @memcpy(i32* %19, %struct.in_addr* %20, i32 4)
ret i32 0
}

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