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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int bind(int const, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short const);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
void bindSocket(const int sock, const unsigned short port) {
  struct sockaddr_in myAddr;
  memset(&myAddr, 0, sizeof(struct sockaddr_in));
  myAddr.sin_family = AF_INET;
  myAddr.sin_port = htons(port);
  myAddr.sin_addr.s_addr = INADDR_ANY;
  if (bind(sock, (struct sockaddr *)&myAddr, sizeof(struct sockaddr_in)) ==
      -1) {
    perror("Socket binding failed");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<bindSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movzwl -0x6(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
cmp    $0xffffffff,%eax
jne    11ca <bindSocket+0x7a>
lea    0xe49(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bindSocket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
cmp    $0xffffffff,%eax
je     11af <bindSocket+0x5f>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [22 x i8] c"Socket binding failed\00"
@EXIT_FAILURE = global i32 0
define void @bindSocket(i32 %0, i16 zeroext %1) {
%3 = alloca i32
%4 = alloca i16
%5 = alloca %struct.sockaddr_in
store i32 %0, i32* %3
store i16 %1, i16* %4
%6 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %7, i32* %8
%9 = load i16, i16* %4
%10 = call i32 @htons(i16 zeroext %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = load i32, i32* %3
%16 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%17 = call i32 @bind(i32 %15, %struct.sockaddr* %16, i32 12)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [22 x i8] c"Socket binding failed\00"
@EXIT_FAILURE = global i32 0
define void @bindSocket(i32 %0, i16 zeroext %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %6, i32* %7
%8 = call i32 @htons(i16 zeroext %1)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_ANY
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %10, i32* %11
%12 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%13 = call i32 @bind(i32 %0, %struct.sockaddr* %12, i32 12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
ret void
}