#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*/ val;
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sockaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int __chk_error(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ socket(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int server_socket(void) {
  int val, fd;
  struct sockaddr_in sockaddr;
  fd = __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/BCLinux/qga-bc/refs/"
                   "heads/ai-touchbook/agent/qemu-0.12.4/tests/linux-test.c",
                   285, (socket(PF_INET, SOCK_STREAM, 0)));
  val = 1;
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/BCLinux/qga-bc/refs/heads/"
              "ai-touchbook/agent/qemu-0.12.4/tests/linux-test.c",
              288,
              (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val))));
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_port = htons(7654);
  sockaddr.sin_addr.s_addr = 0;
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/BCLinux/qga-bc/refs/heads/"
              "ai-touchbook/agent/qemu-0.12.4/tests/linux-test.c",
              293, (bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))));
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/BCLinux/qga-bc/refs/heads/"
              "ai-touchbook/agent/qemu-0.12.4/tests/linux-test.c",
              294, (listen(fd, 0)));
  return fd;
}


x86 assembly (clang, -O0):
<server_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%edx
lea    0xe76(%rip),%rdi
mov    $0x11d,%esi
call   1040 <__chk_error@plt>
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
lea    -0x4(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%edx
lea    0xe35(%rip),%rdi
mov    $0x120,%esi
call   1040 <__chk_error@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x1de6,%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
mov    %eax,%edx
lea    0xdf0(%rip),%rdi
mov    $0x125,%esi
call   1040 <__chk_error@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1060 <listen@plt>
mov    %eax,%edx
lea    0xdd3(%rip),%rdi
mov    $0x126,%esi
call   1040 <__chk_error@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_socket>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
lea    0xe7a(%rip),%rbx
mov    %rbx,%rdi
mov    $0x11d,%esi
mov    %eax,%edx
call   1040 <__chk_error@plt>
mov    %eax,%ebp
movl   $0x1,0x4(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %rbx,%rdi
mov    $0x120,%esi
mov    %eax,%edx
call   1040 <__chk_error@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x1de6,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1070 <bind@plt>
mov    %rbx,%rdi
mov    $0x125,%esi
mov    %eax,%edx
call   1040 <__chk_error@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <listen@plt>
mov    %rbx,%rdi
mov    $0x126,%esi
mov    %eax,%edx
call   1040 <__chk_error@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [166 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BCLinux/qga-bc/refs/heads/ai-touchbook/agent/qemu-0.12.4/tests/linux-test.c\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
define i32 @server_socket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 285, i32 %6)
store i32 %7, i32* %2
store i32 1, i32* %1
%8 = load i32, i32* %2
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_REUSEADDR
%11 = call i32 @setsockopt(i32 %8, i32 %9, i32 %10, i32* %1, i32 4)
%12 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 288, i32 %11)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 7654)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i64 0, i64* %18
%19 = load i32, i32* %2
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i32 @bind(i32 %19, %struct.sockaddr* %20, i32 16)
%22 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 293, i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @listen(i32 %23, i32 0)
%25 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 294, i32 %24)
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [166 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BCLinux/qga-bc/refs/heads/ai-touchbook/agent/qemu-0.12.4/tests/linux-test.c\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
define i32 @server_socket() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = tail call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 285, i32 %7)
store i32 1, i32* %1
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_REUSEADDR
%11 = call i32 @setsockopt(i32 %8, i32 %9, i32 %10, i32* %1, i32 4)
%12 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 288, i32 %11)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 7654)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i64 0, i64* %17
%18 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%19 = call i32 @bind(i32 %8, %struct.sockaddr* %18, i32 16)
%20 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 293, i32 %19)
%21 = call i32 @listen(i32 %8, i32 0)
%22 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 294, i32 %21)
ret i32 %8
}