#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 socklen_t;
typedef int /*<<< orphan*/ serv_in;
typedef int /*<<< orphan*/ flags;
typedef int /*<<< orphan*/ cli_in;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ _err_exit(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ _err_msg(int /*<<< orphan*/, char *, int);
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ htons(unsigned short);
int listen(int, int);
int *malloc(int);
int /*<<< orphan*/ new_thread(int *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void conn_listen(unsigned short port) {
  int flags;
  int sockfd, *fd;
  socklen_t clilen;
  struct sockaddr_in serv_in, cli_in;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    _err_exit(errno,
              "["
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/"
              "server/fmsserver.c"
              ",%d] "
              "socket",
              123);
  flags = 1;
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags,
                 sizeof(flags)) == -1)
    _err_exit(errno,
              "["
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/"
              "server/fmsserver.c"
              ",%d] "
              "setsockopt",
              129);
  bzero(&serv_in, sizeof(serv_in));
  serv_in.sin_family = AF_INET;
  serv_in.sin_port = htons(port);
  serv_in.sin_addr.s_addr = INADDR_ANY;
  if (bind(sockfd, (struct sockaddr *)&serv_in,
           (socklen_t)sizeof(struct sockaddr_in)) == -1)
    _err_exit(errno,
              "["
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/"
              "server/fmsserver.c"
              ",%d] "
              "bind",
              138);
  if (listen(sockfd, 100) == -1)
    _err_exit(errno,
              "["
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/"
              "server/fmsserver.c"
              ",%d] "
              "listen",
              141);
  clilen = sizeof(cli_in);
  while (1) {
    while ((fd = malloc(sizeof(int))) == NULL)
      ;
    *fd = accept(sockfd, (struct sockaddr *)&cli_in, &clilen);
    if (*fd == -1)
      _err_msg(errno,
               "["
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/"
               "master/server/fmsserver.c"
               ",%d] "
               "accept",
               150);
    new_thread(fd);
  }
  close(sockfd);
}


x86 assembly (clang, -O0):
<conn_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11fe <conn_listen+0x4e>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    $0x7b,%edx
call   1060 <_err_exit@plt>
movl   $0x1,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    124c <conn_listen+0x9c>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    $0x81,%edx
call   1060 <_err_exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movzwl -0x2(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    12b2 <conn_listen+0x102>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    $0x8a,%edx
call   1060 <_err_exit@plt>
mov    -0xc(%rbp),%edi
mov    $0x64,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    12e2 <conn_listen+0x132>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xefe(%rip),%rsi
mov    $0x8d,%edx
call   1060 <_err_exit@plt>
movl   $0xc,-0x1c(%rbp)
jmp    12ee <conn_listen+0x13e>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    130b <conn_listen+0x15b>
jmp    12ee <conn_listen+0x13e>
mov    -0xc(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    134a <conn_listen+0x19a>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
lea    0xf32(%rip),%rsi
mov    $0x96,%edx
call   10b0 <_err_msg@plt>
mov    -0x18(%rbp),%rdi
call   1040 <new_thread@plt>
jmp    12e9 <conn_listen+0x139>

x86 assembly (clang, -O2):
<conn_listen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
mov    0x2e19(%rip),%r15
mov    (%r15),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11fc <conn_listen+0x4c>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    $0x7b,%edx
call   1060 <_err_exit@plt>
movl   $0x1,0x4(%rsp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1248 <conn_listen+0x98>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x81,%edx
call   1060 <_err_exit@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
movzwl %bp,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    12a9 <conn_listen+0xf9>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
mov    $0x8a,%edx
call   1060 <_err_exit@plt>
mov    %r14d,%edi
mov    $0x64,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    12d5 <conn_listen+0x125>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xf0b(%rip),%rsi
mov    $0x8d,%edx
call   1060 <_err_exit@plt>
movl   $0xc,(%rsp)
lea    0x18(%rsp),%r12
mov    %rsp,%rbx
mov    0x2cd5(%rip),%r13
lea    0xf80(%rip),%r15
jmp    1308 <conn_listen+0x158>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
call   1040 <new_thread@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1308 <conn_listen+0x158>
mov    %rax,%rbp
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10c0 <accept@plt>
mov    %eax,0x0(%rbp)
cmp    $0xffffffff,%eax
jne    1300 <conn_listen+0x150>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    $0x96,%edx
call   10b0 <_err_msg@plt>
jmp    1300 <conn_listen+0x150>

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
@SOCK_STREAM = global i32 0
@errno = global i32 0
@.str = [156 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [160 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] setsockopt\00"
@INADDR_ANY = global i32 0
@.str.2 = [154 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] bind\00"
@.str.3 = [156 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] listen\00"
@.str.4 = [156 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] accept\00"
define void @conn_listen(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
store i16 %0, i16* %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = call i32 @_err_exit(i32 %14, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0), i32 123)
br label %16
16: ; preds = %13, %1
store i32 1, i32* %3
%17 = load i32, i32* %4
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = bitcast i32* %3 to i8*
%21 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i8* %20, i32 4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @errno
%25 = call i32 @_err_exit(i32 %24, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %26
26: ; preds = %23, %16
%27 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %28, i32* %29
%30 = load i16, i16* %2
%31 = call i32 @htons(i16 zeroext %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = load i32, i32* %4
%37 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%38 = call i32 @bind(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %26
%41 = load i32, i32* @errno
%42 = call i32 @_err_exit(i32 %41, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0), i32 138)
br label %43
43: ; preds = %40, %26
%44 = load i32, i32* %4
%45 = call i32 @listen(i32 %44, i32 100)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @errno
%49 = call i32 @_err_exit(i32 %48, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.3, i64 0, i64 0), i32 141)
br label %50
50: ; preds = %47, %43
store i32 12, i32* %6
br label %51
51: ; preds = %50, %67
br label %52
52: ; preds = %55, %51
%53 = call i32* @malloc(i32 4)
store i32* %53, i32** %5
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %56
55: ; preds = %52
br label %52
56: ; preds = %52
%57 = load i32, i32* %4
%58 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%59 = call i32 @accept(i32 %57, %struct.sockaddr* %58, i32* %6)
%60 = load i32*, i32** %5
store i32 %59, i32* %60
%61 = load i32*, i32** %5
%62 = load i32, i32* %61
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %56
%65 = load i32, i32* @errno
%66 = call i32 @_err_msg(i32 %65, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.4, i64 0, i64 0), i32 150)
br label %67
67: ; preds = %64, %56
%68 = load i32*, i32** %5
%69 = call i32 @new_thread(i32* %68)
br label %51
}

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
@SOCK_STREAM = global i32 0
@errno = global i32 0
@.str = [156 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [160 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] setsockopt\00"
@INADDR_ANY = global i32 0
@.str.2 = [154 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] bind\00"
@.str.3 = [156 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] listen\00"
@.str.4 = [156 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/server/fmsserver.c,%d] accept\00"
define void @conn_listen(i16 zeroext %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* @errno
%16 = tail call i32 @_err_exit(i32 %15, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0), i32 123)
br label %17
17: ; preds = %14, %1
store i32 1, i32* %2
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i32 @setsockopt(i32 %12, i32 %18, i32 %19, i8* %6, i32 4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* @errno
%24 = call i32 @_err_exit(i32 %23, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %25
25: ; preds = %22, %17
%26 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @htons(i16 zeroext %0)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %31, i32* %32
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i32 @bind(i32 %12, %struct.sockaddr* %33, i32 12)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = load i32, i32* @errno
%38 = call i32 @_err_exit(i32 %37, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0), i32 138)
br label %39
39: ; preds = %36, %25
%40 = call i32 @listen(i32 %12, i32 100)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* @errno
%44 = call i32 @_err_exit(i32 %43, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.3, i64 0, i64 0), i32 141)
br label %45
45: ; preds = %42, %39
store i32 12, i32* %3
%46 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %47
47: ; preds = %50, %45
%48 = call i32* @malloc(i32 4)
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %51
50: ; preds = %47, %57
br label %47
51: ; preds = %47
%52 = call i32 @accept(i32 %12, %struct.sockaddr* %46, i32* %3)
store i32 %52, i32* %48
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @errno
%56 = call i32 @_err_msg(i32 %55, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.4, i64 0, i64 0), i32 150)
br label %57
57: ; preds = %54, %51
%58 = call i32 @new_thread(i32* %48)
br label %50
}