#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 */
typedef int /*<<< orphan*/ uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ htons(int /*<<< orphan*/);
struct sockaddr *setPort(struct sockaddr_in *addr, uint16_t port) {
  addr->sin_family = AF_INET;
  addr->sin_addr.s_addr = INADDR_ANY;
  addr->sin_port = htons(port);
  return (struct sockaddr *)addr;
}


x86 assembly (clang, -O0):
<setPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2ec2(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2eaa(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setPort>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ecd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rdi)
mov    0x2eb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rdi)
mov    %esi,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
define %struct.sockaddr* @setPort(%struct.sockaddr_in* writeonly %0, i32 %1) {
%3 = load i32, i32* @AF_INET
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %3, i32* %4
%5 = load i32, i32* @INADDR_ANY
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1, i32 0
store i32 %5, i32* %6
%7 = tail call i32 @htons(i32 %1)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
store i32 %7, i32* %8
%9 = bitcast %struct.sockaddr_in* %0 to %struct.sockaddr*
ret %struct.sockaddr* %9
}