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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_IP;
int /*<<< orphan*/ SOL_SOCKET;
int SO_REUSEADDR;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int make_socket(uint16_t port) {
  int sock, flag = 1;
  struct sockaddr_in name;
  sock = socket(PF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)) < 0) {
    perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)");
    exit(EXIT_FAILURE);
  }
  if (setsockopt(sock, SOL_IP, 19, &flag, sizeof(flag)) < 0) {
    perror("setsockopt(SOL_IP, IP_TRANSPARENT)");
    exit(EXIT_FAILURE);
  }
  name.sin_family = AF_INET;
  name.sin_port = htons(port);
  name.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0) {
    perror("bind");
    exit(EXIT_FAILURE);
  }
  return sock;
}


x86 assembly (clang, -O0):
<make_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c2 <make_socket+0x52>
lea    0xe51(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    120a <make_socket+0x9a>
lea    0xe10(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    $0x13,%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    124e <make_socket+0xde>
lea    0xdf1(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    12ab <make_socket+0x13b>
lea    0xdb7(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_socket>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
movl   $0x1,0x4(%rsp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     123a <make_socket+0xca>
mov    %eax,%ebx
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1243 <make_socket+0xd3>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x13,%edx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     124c <make_socket+0xdc>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1060 <bind@plt>
test   %rax,%rax
js     1255 <make_socket+0xe5>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdbf(%rip),%rdi
jmp    125c <make_socket+0xec>
lea    0xdbd(%rip),%rdi
jmp    125c <make_socket+0xec>
lea    0xdd9(%rip),%rdi
jmp    125c <make_socket+0xec>
lea    0xdf3(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [37 x i8] c"setsockopt(SOL_SOCKET, SO_REUSEADDR)\00"
@SOL_IP = global i32 0
@.str.2 = [35 x i8] c"setsockopt(SOL_IP, IP_TRANSPARENT)\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.3 = [5 x i8] c"bind\00"
define i32 @make_socket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
store i32 1, i32* %4
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i32, i32* %3
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i64 @setsockopt(i32 %16, i32 %17, i32 %18, i32* %4, i32 4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %15
%26 = load i32, i32* %3
%27 = load i32, i32* @SOL_IP
%28 = call i64 @setsockopt(i32 %26, i32 %27, i32 19, i32* %4, i32 4)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %25
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %35, i32* %36
%37 = load i32, i32* %2
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %38, i32* %39
%40 = load i32, i32* @INADDR_ANY
%41 = call i32 @htonl(i32 %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = load i32, i32* %3
%45 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%46 = call i64 @bind(i32 %44, %struct.sockaddr* %45, i32 12)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %34
%49 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %34
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [37 x i8] c"setsockopt(SOL_SOCKET, SO_REUSEADDR)\00"
@SOL_IP = global i32 0
@.str.2 = [35 x i8] c"setsockopt(SOL_IP, IP_TRANSPARENT)\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.3 = [5 x i8] c"bind\00"
define i32 @make_socket(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_REUSEADDR
%17 = call i64 @setsockopt(i32 %8, i32 %15, i32 %16, i32* %2, i32 4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = load i32, i32* @SOL_IP
%25 = call i64 @setsockopt(i32 %8, i32 %24, i32 19, i32* %2, i32 4)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %32, i32* %33
%34 = call i32 @htons(i32 %0)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = call i32 @htonl(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %37, i32* %38
%39 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%40 = call i64 @bind(i32 %8, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %31
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %31
ret i32 %8
}