#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;
};
typedef int /*<<< orphan*/ s;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close_socket(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int svr_bind(int fd, unsigned short port) {
  struct sockaddr_in s;
  bzero(&s, sizeof(struct sockaddr_in));
  s.sin_family = AF_INET;
  s.sin_port = htons(port);
  s.sin_addr.s_addr = htonl(INADDR_ANY);
  if ((bind(fd, (struct sockaddr *)&s, sizeof(s))) < 0) {
    perror("Bind Server error !");
    close_socket(fd);
    exit(EXIT_FAILURE);
  }
  printf("Bind Server ok\n");
  return 0;
}


x86 assembly (clang, -O0):
<svr_bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movzwl -0x6(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1206 <svr_bind+0x86>
lea    0xe15(%rip),%rdi
call   1080 <perror@plt>
mov    -0x4(%rbp),%edi
call   1060 <close_socket@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svr_bind>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
js     11f2 <svr_bind+0x72>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe07(%rip),%rdi
call   1080 <perror@plt>
mov    %r14d,%edi
call   1060 <close_socket@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   10a0 <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 = [20 x i8] c"Bind Server error !\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"Bind Server ok\0A\00"
define i32 @svr_bind(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 @bzero(%struct.sockaddr_in* %5, 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 = call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 %13, i32* %15
%16 = load i32, i32* %3
%17 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%18 = call i64 @bind(i32 %16, %struct.sockaddr* %17, i32 12)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = call i32 @close_socket(i32 %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
%27 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

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 = [20 x i8] c"Bind Server error !\00"
@EXIT_FAILURE = global i32 0
@str = [15 x i8] c"Bind Server ok\00"
define i32 @svr_bind(i32 %0, i16 zeroext %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = call i32 @bzero(%struct.sockaddr_in* %3, 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 = tail 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 = 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 %struct.sockaddr_in* %3 to %struct.sockaddr*
%14 = call i64 @bind(i32 %0, %struct.sockaddr* %13, i32 12)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @close_socket(i32 %0)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
ret i32 0
}