#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 */

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
scalar_t__ bind(int /*<<< orphan*/ const, struct sockaddr *, int);
scalar_t__ listen(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ log_and_exit(char *);
void bind_and_listen_to_port(const uint32_t sock,
                             const struct sockaddr_in server) {
  if (bind(sock, (struct sockaddr *)&server, sizeof(struct sockaddr)) < 0) {
    log_and_exit("Failed to bind the server socket");
  }
  if (listen(sock, 1) < 0) {
    log_and_exit("Failed to listen on the server socket");
  }
}


x86 assembly (clang, -O0):
<bind_and_listen_to_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    1165 <bind_and_listen_to_port+0x35>
lea    0xea0(%rip),%rdi
call   1030 <log_and_exit@plt>
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1040 <listen@plt>
cmp    $0x0,%rax
jge    1188 <bind_and_listen_to_port+0x58>
lea    0xe9e(%rip),%rdi
call   1030 <log_and_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind_and_listen_to_port>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
test   %rax,%rax
jns    115b <bind_and_listen_to_port+0x2b>
lea    0xeaa(%rip),%rdi
call   1030 <log_and_exit@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <listen@plt>
test   %rax,%rax
jns    1178 <bind_and_listen_to_port+0x48>
lea    0xeae(%rip),%rdi
call   1030 <log_and_exit@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [33 x i8] c"Failed to bind the server socket\00"
@.str.1 = [38 x i8] c"Failed to listen on the server socket\00"
define void @bind_and_listen_to_port(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %1, i32* %5
store i32 %0, i32* %4
%6 = load i32, i32* %4
%7 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%8 = call i64 @bind(i32 %6, %struct.sockaddr* %7, i32 4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @log_and_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* %4
%14 = call i64 @listen(i32 %13, i32 1)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @log_and_exit(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [33 x i8] c"Failed to bind the server socket\00"
@.str.1 = [38 x i8] c"Failed to listen on the server socket\00"
define void @bind_and_listen_to_port(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %1, i32* %4
%5 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%6 = call i64 @bind(i32 %0, %struct.sockaddr* %5, i32 4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @log_and_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i64 @listen(i32 %0, i32 1)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @log_and_exit(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
ret void
}