#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 */

/* Type definitions */
struct sockaddr_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ listen(int, int);
char *malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, int *, int, int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int server(int pings, int size) {
  printf("starting server\n");
  struct addrinfo hints, *res;
  int error, server_socket;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = PF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  error = getaddrinfo(NULL, "8079", &hints, &res);
  if (error) {
    printf("server error: %s\n", gai_strerror(error));
    return -1;
  }
  server_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (server_socket < 0) {
    printf("server error: could not create socket\n");
    return -1;
  }
  int yes = 1;
  if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) <
      0) {
    printf("server error: could not set socket options\n");
    return -1;
  }
  if (bind(server_socket, res->ai_addr, res->ai_addrlen) < 0) {
    printf("server error: could not bind to socket\n");
    return -1;
  }
  listen(server_socket, 5);
  int client_socket;
  struct sockaddr_storage client_addr;
  socklen_t addr_size;
  client_socket =
      accept(server_socket, (struct sockaddr *)&client_addr, &addr_size);
  int i = 0, counter = 0;
  for (i = 0; i < pings; i++) {
    char *buf = malloc(size);
    ssize_t read = 0;
    for (; size - read;)
      read += recv(client_socket, buf, size - read, 0);
    counter++;
    free(buf);
  }
  size_t sent;
  for (; sizeof(int) - sent;)
    sent += send(client_socket, &counter, sizeof(int) - sent, 0);
  freeaddrinfo(res);
  return 0;
}


x86 assembly (clang, -O0):
<server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd6(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     127a <server+0x9a>
mov    -0x34(%rbp),%edi
call   1080 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    143a <server+0x25a>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    12bb <server+0xdb>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    143a <server+0x25a>
movl   $0x1,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
mov    0x2ceb(%rip),%rax
mov    (%rax),%edx
lea    -0x3c(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    130a <server+0x12a>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    143a <server+0x25a>
mov    -0x38(%rbp),%edi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    1343 <server+0x163>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    143a <server+0x25a>
mov    -0x38(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
mov    -0x38(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13ec <server+0x20c>
mov    -0xc(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x64(%rbp),%eax
cmp    $0x0,%eax
je     13cc <server+0x1ec>
mov    -0x40(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    -0x64(%rbp),%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x64(%rbp)
jmp    1397 <server+0x1b7>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1378 <server+0x198>
jmp    13f1 <server+0x211>
mov    $0x4,%eax
sub    -0x70(%rbp),%rax
cmp    $0x0,%rax
je     142a <server+0x24a>
mov    -0x40(%rbp),%edi
mov    $0x4,%eax
sub    -0x70(%rbp),%rax
mov    %eax,%edx
lea    -0x54(%rbp),%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
add    -0x70(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    13f1 <server+0x211>
mov    -0x30(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,%r15d
mov    %edi,%r14d
lea    0xe0c(%rip),%rdi
call   1050 <puts@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10a0 <memset@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
lea    0xdae(%rip),%rsi
lea    0x8(%rsp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
je     1282 <server+0x92>
mov    %eax,%edi
call   1090 <gai_strerror@plt>
lea    0xd92(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13a3 <server+0x1b3>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1110 <socket@plt>
test   %eax,%eax
js     1368 <server+0x178>
mov    %eax,%ebp
movl   $0x1,0x14(%rsp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
mov    0x2d09(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
test   %rax,%rax
js     138e <server+0x19e>
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   10d0 <bind@plt>
test   %rax,%rax
js     1397 <server+0x1a7>
mov    %ebp,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
lea    0x18(%rsp),%rsi
lea    0x1c(%rsp),%rdx
mov    %ebp,%edi
call   10e0 <accept@plt>
mov    %eax,%r13d
movl   $0x0,0x4(%rsp)
test   %r14d,%r14d
jle    1371 <server+0x181>
xor    %r12d,%r12d
jmp    1336 <server+0x146>
add    $0x1,%r12d
mov    %r12d,0x4(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
cmp    %r14d,%r12d
je     1371 <server+0x181>
mov    %r15d,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
je     1320 <server+0x130>
xor    %ebp,%ebp
mov    %r15d,%edx
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1040 <recv@plt>
add    %eax,%ebp
mov    %r15d,%edx
sub    %ebp,%edx
jne    1350 <server+0x160>
jmp    1320 <server+0x130>
lea    0xd0a(%rip),%rdi
jmp    139e <server+0x1ae>
lea    0x4(%rsp),%rsi
xor    %ebx,%ebx
mov    %r13d,%edi
xor    %ecx,%ecx
call   1070 <send@plt>
mov    0x8(%rsp),%rdi
call   1100 <freeaddrinfo@plt>
jmp    13a8 <server+0x1b8>
lea    0xcb9(%rip),%rdi
jmp    139e <server+0x1ae>
lea    0xc89(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"starting server\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [5 x i8] c"8079\00"
@.str.2 = [18 x i8] c"server error: %s\0A\00"
@.str.3 = [39 x i8] c"server error: could not create socket\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [44 x i8] c"server error: could not set socket options\0A\00"
@.str.5 = [40 x i8] c"server error: could not bind to socket\0A\00"
define i32 @server(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_storage
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 24)
%21 = load i32, i32* @PF_INET
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %21, i32* %22
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %23, i32* %24
%25 = load i32, i32* @AI_PASSIVE
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store i32 %25, i32* %26
%27 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %2
%31 = load i32, i32* %8
%32 = call i8* @gai_strerror(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %3
br label %122
34: ; preds = %2
%35 = load %struct.addrinfo*, %struct.addrinfo** %7
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 4
%37 = load i32, i32* %36
%38 = load %struct.addrinfo*, %struct.addrinfo** %7
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 3
%40 = load i32, i32* %39
%41 = load %struct.addrinfo*, %struct.addrinfo** %7
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 2
%43 = load i32, i32* %42
%44 = call i32 @socket(i32 %37, i32 %40, i32 %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %34
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %122
49: ; preds = %34
store i32 1, i32* %10
%50 = load i32, i32* %9
%51 = load i32, i32* @SOL_SOCKET
%52 = load i32, i32* @SO_REUSEADDR
%53 = call i64 @setsockopt(i32 %50, i32 %51, i32 %52, i32* %10, i32 4)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %49
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %122
57: ; preds = %49
%58 = load i32, i32* %9
%59 = load %struct.addrinfo*, %struct.addrinfo** %7
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = load %struct.addrinfo*, %struct.addrinfo** %7
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = call i64 @bind(i32 %58, i32 %61, i32 %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %57
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %122
69: ; preds = %57
%70 = load i32, i32* %9
%71 = call i32 @listen(i32 %70, i32 5)
%72 = load i32, i32* %9
%73 = bitcast %struct.sockaddr_storage* %12 to %struct.sockaddr*
%74 = call i32 @accept(i32 %72, %struct.sockaddr* %73, i32* %13)
store i32 %74, i32* %11
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %14
br label %75
75: ; preds = %103, %69
%76 = load i32, i32* %14
%77 = load i32, i32* %4
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %106
79: ; preds = %75
%80 = load i32, i32* %5
%81 = call i8* @malloc(i32 %80)
store i8* %81, i8** %16
store i32 0, i32* %17
br label %82
82: ; preds = %87, %79
%83 = load i32, i32* %5
%84 = load i32, i32* %17
%85 = sub nsw i32 %83, %84
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %98
87: ; preds = %82
%88 = load i32, i32* %11
%89 = load i8*, i8** %16
%90 = load i32, i32* %5
%91 = load i32, i32* %17
%92 = sub nsw i32 %90, %91
%93 = call i64 @recv(i32 %88, i8* %89, i32 %92, i32 0)
%94 = load i32, i32* %17
%95 = sext i32 %94 to i64
%96 = add nsw i64 %95, %93
%97 = trunc i64 %96 to i32
store i32 %97, i32* %17
br label %82
98: ; preds = %82
%99 = load i32, i32* %15
%100 = add nsw i32 %99, 1
store i32 %100, i32* %15
%101 = load i8*, i8** %16
%102 = call i32 @free(i8* %101)
br label %103
103: ; preds = %98
%104 = load i32, i32* %14
%105 = add nsw i32 %104, 1
store i32 %105, i32* %14
br label %75
106: ; preds = %75
br label %107
107: ; preds = %111, %106
%108 = load i64, i64* %18
%109 = sub i64 4, %108
%110 = icmp ne i64 %109, 0
br i1 %110, label %111, label %119
111: ; preds = %107
%112 = load i32, i32* %11
%113 = load i64, i64* %18
%114 = sub i64 4, %113
%115 = trunc i64 %114 to i32
%116 = call i64 @send(i32 %112, i32* %15, i32 %115, i32 0)
%117 = load i64, i64* %18
%118 = add i64 %117, %116
store i64 %118, i64* %18
br label %107
119: ; preds = %107
%120 = load %struct.addrinfo*, %struct.addrinfo** %7
%121 = call i32 @freeaddrinfo(%struct.addrinfo* %120)
store i32 0, i32* %3
br label %122
122: ; preds = %119, %67, %55, %47, %30
%123 = load i32, i32* %3
ret i32 %123
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [5 x i8] c"8079\00"
@.str.2 = [18 x i8] c"server error: %s\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@str = [16 x i8] c"starting server\00"
@str.6 = [39 x i8] c"server error: could not bind to socket\00"
@str.7 = [43 x i8] c"server error: could not set socket options\00"
@str.8 = [38 x i8] c"server error: could not create socket\00"
define i32 @server(i32 %0, i32 %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca i32
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = alloca i32
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%10 = bitcast %struct.addrinfo* %3 to i8*
%11 = bitcast %struct.addrinfo** %4 to i8*
%12 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 24)
%13 = load i32, i32* @PF_INET
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %15, i32* %16
%17 = load i32, i32* @AI_PASSIVE
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %17, i32* %18
%19 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %2
%22 = call i8* @gai_strerror(i32 %19)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %87
24: ; preds = %2
%25 = load %struct.addrinfo*, %struct.addrinfo** %4
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 4
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 2
%31 = load i32, i32* %30
%32 = call i32 @socket(i32 %27, i32 %29, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.8, i64 0, i64 0))
br label %87
36: ; preds = %24
%37 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%38 = load i32, i32* @SOL_SOCKET
%39 = load i32, i32* @SO_REUSEADDR
%40 = call i64 @setsockopt(i32 %32, i32 %38, i32 %39, i32* %5, i32 4)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.7, i64 0, i64 0))
br label %85
44: ; preds = %36
%45 = load %struct.addrinfo*, %struct.addrinfo** %4
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i64 0, i32 1
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i64 0, i32 0
%49 = load i32, i32* %48
%50 = call i64 @bind(i32 %32, i32 %47, i32 %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
br label %85
54: ; preds = %44
%55 = call i32 @listen(i32 %32, i32 5)
%56 = bitcast %struct.sockaddr_storage* %6 to i8*
%57 = bitcast i32* %7 to i8*
%58 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%59 = call i32 @accept(i32 %32, %struct.sockaddr* %58, i32* %7)
%60 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%61 = icmp sgt i32 %0, 0
br i1 %61, label %62, label %81
62: ; preds = %54
%63 = icmp eq i32 %1, 0
br label %64
64: ; preds = %62, %76
%65 = phi i32 [ 0, %62 ], [ %77, %76 ]
%66 = phi i32 [ 0, %62 ], [ %79, %76 ]
%67 = call i8* @malloc(i32 %1)
br i1 %63, label %76, label %68
68: ; preds = %64, %68
%69 = phi i32 [ %74, %68 ], [ %1, %64 ]
%70 = phi i32 [ %73, %68 ], [ 0, %64 ]
%71 = call i64 @recv(i32 %59, i8* %67, i32 %69, i32 0)
%72 = trunc i64 %71 to i32
%73 = add i32 %70, %72
%74 = sub nsw i32 %1, %73
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %68
76: ; preds = %68, %64
%77 = add nuw nsw i32 %65, 1
store i32 %77, i32* %8
%78 = call i32 @free(i8* %67)
%79 = add nuw nsw i32 %66, 1
%80 = icmp eq i32 %79, %0
br i1 %80, label %81, label %64
81: ; preds = %76, %54
%82 = call i64 @send(i32 %59, i32* %8, i32 undef, i32 0)
%83 = load %struct.addrinfo*, %struct.addrinfo** %4
%84 = call i32 @freeaddrinfo(%struct.addrinfo* %83)
br label %85
85: ; preds = %81, %52, %42
%86 = phi i32 [ -1, %42 ], [ -1, %52 ], [ 0, %81 ]
br label %87
87: ; preds = %85, %34, %21
%88 = phi i32 [ -1, %21 ], [ -1, %34 ], [ %86, %85 ]
ret i32 %88
}