#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char const *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
void set_addr(struct sockaddr_in *addr, const char *s_addr, int port) {
  memset(addr, 0, sizeof(addr));
  addr->sin_family = AF_INET;
  addr->sin_addr.s_addr = inet_addr(s_addr);
  addr->sin_port = htons(port);
}


x86 assembly (clang, -O0):
<set_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
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):
<set_addr>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbp)
mov    %rbx,%rdi
call   1050 <inet_addr@plt>
mov    %eax,0x4(%rbp)
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, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define void @set_addr(%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 %struct.sockaddr_in*, %struct.sockaddr_in** %4
%8 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 8)
%9 = load i32, i32* @AF_INET
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %9, i32* %11
%12 = load i8*, i8** %5
%13 = call i32 @inet_addr(i8* %12)
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %13, i32* %16
%17 = load i32, i32* %6
%18 = call i32 @htons(i32 %17)
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
store i32 %18, i32* %20
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define void @set_addr(%struct.sockaddr_in* %0, i8* %1, i32 %2) {
%4 = tail call i32 @memset(%struct.sockaddr_in* %0, i32 0, i32 8)
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %5, i32* %6
%7 = tail call i32 @inet_addr(i8* %1)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1, i32 0
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 0
store i32 %9, i32* %10
ret void
}