#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 /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ reuse;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEPORT;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ doprocessing(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char const *,
                      int);
int /*<<< orphan*/ shutdown(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, portno, clilen;
  char buffer[256];
  struct sockaddr_in serv_addr, cli_addr;
  int n, pid;
  if (argc == 2) {
    portno = atoi(argv[1]);
  } else {
    portno = 5001;
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("# vulnserver_cov: ERROR opening socket");
    exit(1);
  }
  int reuse = 1;
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (const char *)&reuse,
                 sizeof(reuse)) < 0)
    perror("# vulnserver_cov: setsockopt(SO_REUSEPORT) failed");
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);
  printf("# vulnserver_cov: Listening on port: %i\n", portno);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    perror("# vulnserver_cov: ERROR on binding");
    exit(1);
  }
  listen(sockfd, 5);
  clilen = sizeof(cli_addr);
  while (1) {
    newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
    if (newsockfd < 0) {
      perror("# vulnserver_cov: ERROR on accept");
      exit(1);
    }
    printf("# vulnserver_cov: New client connected\n");
    doprocessing(newsockfd, sockfd);
    printf("# vulnserver_cov: Closing...\n");
    shutdown(newsockfd, 2);
    close(newsockfd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1218 <main+0x38>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    121f <main+0x3f>
movl   $0x1389,-0x1c(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    125b <main+0x7b>
lea    0xdb4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0x1,-0x14c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
mov    0x2d60(%rip),%rax
mov    (%rax),%edx
lea    -0x14c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12a2 <main+0xc2>
lea    0xd8a(%rip),%rdi
call   10a0 <perror@plt>
lea    -0x130(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x128(%rbp)
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x130(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1324 <main+0x144>
lea    0xd6d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    136e <main+0x18e>
lea    0xd46(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   10e0 <doprocessing@plt>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
jmp    1338 <main+0x158>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x1389,%ebp
cmp    $0x2,%edi
jne    1213 <main+0x23>
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebp
mov    0x2dc6(%rip),%r15
mov    (%r15),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
jns    123d <main+0x4d>
lea    0xdc8(%rip),%rdi
jmp    1366 <main+0x176>
mov    %eax,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jns    127c <main+0x8c>
lea    0xdb0(%rip),%rdi
call   10b0 <perror@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xda5(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    12dd <main+0xed>
lea    0xdaa(%rip),%rdi
jmp    1366 <main+0x176>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
movl   $0xc,(%rsp)
lea    0x18(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   10d0 <accept@plt>
test   %eax,%eax
js     135f <main+0x16f>
mov    %eax,%ebp
lea    0xdbb(%rip),%r14
lea    0xddb(%rip),%r15
lea    0x18(%rsp),%r12
mov    %rsp,%r13
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   10f0 <doprocessing@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   10d0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1320 <main+0x130>
lea    0xd3f(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

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
@.str = [39 x i8] c"# vulnserver_cov: ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [50 x i8] c"# vulnserver_cov: setsockopt(SO_REUSEPORT) failed\00"
@INADDR_ANY = global i32 0
@.str.2 = [41 x i8] c"# vulnserver_cov: Listening on port: %i\0A\00"
@.str.3 = [35 x i8] c"# vulnserver_cov: ERROR on binding\00"
@.str.4 = [34 x i8] c"# vulnserver_cov: ERROR on accept\00"
@.str.5 = [40 x i8] c"# vulnserver_cov: New client connected\0A\00"
@.str.6 = [30 x i8] c"# vulnserver_cov: Closing...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %8
br label %24
23: ; preds = %2
store i32 5001, i32* %8
br label %24
24: ; preds = %23, %18
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
store i32 1, i32* %15
%34 = load i32, i32* %6
%35 = load i32, i32* @SOL_SOCKET
%36 = load i32, i32* @SO_REUSEPORT
%37 = bitcast i32* %15 to i8*
%38 = call i64 @setsockopt(i32 %34, i32 %35, i32 %36, i8* %37, i32 4)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %33
%43 = bitcast %struct.sockaddr_in* %11 to i8*
%44 = call i32 @bzero(i8* %43, i32 12)
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %45, i32* %46
%47 = load i32, i32* @INADDR_ANY
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = load i32, i32* %8
%51 = call i32 @htons(i32 %50)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %51, i32* %52
%53 = load i32, i32* %8
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %6
%56 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%57 = call i64 @bind(i32 %55, %struct.sockaddr* %56, i32 12)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %42
%60 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %42
%63 = load i32, i32* %6
%64 = call i32 @listen(i32 %63, i32 5)
store i32 12, i32* %9
br label %65
65: ; preds = %62, %74
%66 = load i32, i32* %6
%67 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%68 = call i32 @accept(i32 %66, %struct.sockaddr* %67, i32* %9)
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %65
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%76 = load i32, i32* %7
%77 = load i32, i32* %6
%78 = call i32 @doprocessing(i32 %76, i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%80 = load i32, i32* %7
%81 = call i32 @shutdown(i32 %80, i32 2)
%82 = load i32, i32* %7
%83 = call i32 @close(i32 %82)
br label %65
}

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
@.str = [39 x i8] c"# vulnserver_cov: ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [50 x i8] c"# vulnserver_cov: setsockopt(SO_REUSEPORT) failed\00"
@INADDR_ANY = global i32 0
@.str.2 = [41 x i8] c"# vulnserver_cov: Listening on port: %i\0A\00"
@.str.3 = [35 x i8] c"# vulnserver_cov: ERROR on binding\00"
@.str.4 = [34 x i8] c"# vulnserver_cov: ERROR on accept\00"
@str = [39 x i8] c"# vulnserver_cov: New client connected\00"
@str.7 = [29 x i8] c"# vulnserver_cov: Closing...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
br label %15
15: ; preds = %2, %11
%16 = phi i32 [ %14, %11 ], [ 5001, %2 ]
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_REUSEPORT
%28 = call i64 @setsockopt(i32 %19, i32 %26, i32 %27, i8* %25, i32 4)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = call i32 @bzero(i8* %8, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %36, i32* %37
%38 = call i32 @htons(i32 %16)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %38, i32* %39
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%41 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%42 = call i64 @bind(i32 %19, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %32
%45 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %32
%48 = call i32 @listen(i32 %19, i32 5)
store i32 12, i32* %3
%49 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%50 = call i32 @accept(i32 %19, %struct.sockaddr* %49, i32* %3)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %55, %47
%53 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %47, %55
%56 = phi i32 [ %62, %55 ], [ %50, %47 ]
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%58 = call i32 @doprocessing(i32 %56, i32 %19)
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
%60 = call i32 @shutdown(i32 %56, i32 2)
%61 = call i32 @close(i32 %56)
%62 = call i32 @accept(i32 %19, %struct.sockaddr* %49, i32* %3)
%63 = icmp slt i32 %62, 0
br i1 %63, label %52, label %55
}