#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 {
  TYPE_1__ sin_addr;
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ name;
typedef scalar_t__ in_port_t;

/* Variables and functions */
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
scalar_t__ htons(int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
void bind_to_port(int socket, int port) {
  struct sockaddr_in name;
  name.sin_family = PF_INET;
  name.sin_port = (in_port_t)htons(port);
  name.sin_addr.s_addr = htonl(INADDR_ANY);
  int reuse = 1;
  int res =
      setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(int));
  if (res == -1)
    error("Can't set the 'reuse' option on the socket");
  res = bind(socket, (struct sockaddr *)&name, sizeof(name));
  if (res == -1)
    error("Can't bind to socket");
}


x86 assembly (clang, -O0):
<bind_to_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11cb <bind_to_port+0x7b>
lea    0xe3a(%rip),%rdi
call   1070 <error@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x18,%edx
call   1060 <bind@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11f5 <bind_to_port+0xa5>
lea    0xe3b(%rip),%rdi
call   1070 <error@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind_to_port>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %esi,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
movl   $0x1,0x4(%rsp)
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11bf <bind_to_port+0x6f>
lea    0xe46(%rip),%rdi
call   1070 <error@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   1060 <bind@plt>
cmp    $0xffffffff,%eax
jne    11e1 <bind_to_port+0x91>
lea    0xe4f(%rip),%rdi
call   1070 <error@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [43 x i8] c"Can't set the 'reuse' option on the socket\00"
@.str.1 = [21 x i8] c"Can't bind to socket\00"
define void @bind_to_port(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* @PF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* %4
%11 = call i64 @htons(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i64 %11, i64* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
store i32 1, i32* %6
%17 = load i32, i32* %3
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = bitcast i32* %6 to i8*
%21 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i8* %20, i32 4)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %2
%27 = load i32, i32* %3
%28 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 24)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %26
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [43 x i8] c"Can't set the 'reuse' option on the socket\00"
@.str.1 = [21 x i8] c"Can't bind to socket\00"
define void @bind_to_port(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = load i32, i32* @PF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %6, i32* %7
%8 = tail call i64 @htons(i32 %1)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i64 %8, i64* %9
%10 = load i32, i32* @INADDR_ANY
%11 = tail call i32 @htonl(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %11, i32* %12
%13 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_REUSEADDR
%16 = call i32 @setsockopt(i32 %0, i32 %14, i32 %15, i8* %13, i32 4)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @bind(i32 %0, %struct.sockaddr* %21, i32 24)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
ret void
}