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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_SNDBUF;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int setupSocket(int port) {
  int err = 0;
  int listenfd = 0;
  socklen_t buf_size = 32 * 1024 * 1024;
  socklen_t size = sizeof(buf_size);
  struct sockaddr_in serv_addr;
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  err =
      setsockopt(listenfd, SOL_SOCKET, SO_SNDBUF, &buf_size, sizeof(buf_size));
  err =
      setsockopt(listenfd, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size));
  err = getsockopt(listenfd, SOL_SOCKET, SO_SNDBUF, &buf_size, &size);
  memset(&serv_addr, '0', sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  serv_addr.sin_port = htons(port);
  bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  listen(listenfd, 24);
  return listenfd;
}


x86 assembly (clang, -O0):
<setupSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x2000000,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1070 <getsockopt@plt>
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x30,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    -0xc(%rbp),%edi
mov    $0x18,%esi
call   1080 <listen@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setupSocket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
movl   $0x2000000,0x4(%rsp)
02
movl   $0x4,(%rsp)
mov    0x2e39(%rip),%r15
mov    (%r15),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    0x2e25(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2e0b(%rip),%r13
mov    0x0(%r13),%edx
lea    0x4(%rsp),%r12
mov    %eax,%edi
mov    %r12,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x0(%rbp),%esi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r12,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x0(%rbp),%esi
mov    0x0(%r13),%edx
mov    %rsp,%r8
mov    %ebx,%edi
mov    %r12,%rcx
call   1070 <getsockopt@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x30,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %r14d,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %ebx,%edi
mov    $0x18,%esi
call   1080 <listen@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
@INADDR_ANY = global i32 0
define i32 @setupSocket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 33554432, i32* %5
store i32 4, i32* %6
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_SNDBUF
%14 = call i32 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %5, i32 4)
store i32 %14, i32* %3
%15 = load i32, i32* %4
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_RCVBUF
%18 = call i32 @setsockopt(i32 %15, i32 %16, i32 %17, i32* %5, i32 4)
store i32 %18, i32* %3
%19 = load i32, i32* %4
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_SNDBUF
%22 = call i32 @getsockopt(i32 %19, i32 %20, i32 %21, i32* %5, i32* %6)
store i32 %22, i32* %3
%23 = call i32 @memset(%struct.sockaddr_in* %7, i32 48, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %2
%31 = call i32 @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %4
%34 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%35 = call i32 @bind(i32 %33, %struct.sockaddr* %34, i32 12)
%36 = load i32, i32* %4
%37 = call i32 @listen(i32 %36, i32 24)
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
@INADDR_ANY = global i32 0
define i32 @setupSocket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %2 to i8*
store i32 33554432, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_SNDBUF
%13 = call i32 @setsockopt(i32 %10, i32 %11, i32 %12, i32* %2, i32 4)
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_RCVBUF
%16 = call i32 @setsockopt(i32 %10, i32 %14, i32 %15, i32* %2, i32 4)
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_SNDBUF
%19 = call i32 @getsockopt(i32 %10, i32 %17, i32 %18, i32* %2, i32* %3)
%20 = call i32 @memset(%struct.sockaddr_in* %4, i32 48, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %24, i32* %25
%26 = call i32 @htons(i32 %0)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = call i32 @bind(i32 %10, %struct.sockaddr* %28, i32 12)
%30 = call i32 @listen(i32 %10, i32 24)
ret i32 %10
}