#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 {
  struct sockaddr *ai_addr;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ hints;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
char *sockaddr2str(struct sockaddr *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main() {
  int ret;
  int srv_sock, cli_sock;
  struct addrinfo hints, *ai_list;
  struct sockaddr_storage cli_addr;
  socklen_t cli_addr_len = sizeof(cli_addr);
  char *addrstr;
  char mens[100];
  int received;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  ret = getaddrinfo(NULL, "6060", &hints, &ai_list);
  do {
    if (ret != 0) {
      perror("getaddrinfo");
      ret = EXIT_FAILURE;
      goto error;
    }
  } while (0);
  srv_sock =
      socket(ai_list->ai_family, ai_list->ai_socktype, ai_list->ai_protocol);
  do {
    if (srv_sock == -1) {
      perror("socket");
      ret = EXIT_FAILURE;
      goto error_free;
    }
  } while (0);
  ret = bind(srv_sock, ai_list->ai_addr, ai_list->ai_addrlen);
  do {
    if (ret == -1) {
      perror("bind");
      ret = EXIT_FAILURE;
      goto error_free;
    }
  } while (0);
  ret = listen(srv_sock, 0);
  do {
    if (ret == -1) {
      perror("listen");
      ret = EXIT_FAILURE;
      goto close_srv;
    }
  } while (0);
  addrstr = sockaddr2str(ai_list->ai_addr);
  printf("Running server on %s:%s\n", addrstr, "6060");
  free(addrstr);
  cli_sock = accept(srv_sock, (struct sockaddr *)&cli_addr, &cli_addr_len);
  do {
    if (cli_sock == -1) {
      perror("accept");
      ret = EXIT_FAILURE;
      goto close_cli;
    }
  } while (0);
  addrstr = sockaddr2str((struct sockaddr *)&cli_addr);
  printf("Client %s is connected\n", addrstr);
  free(addrstr);
  do {
    received = recv(cli_sock, mens, 100, 0);
    do {
      if (received == -1) {
        perror("recv");
        ret = EXIT_FAILURE;
        goto close_cli;
      }
    } while (0);
    printf("%s", mens);
  } while (received != 0 && strcmp(mens, "exit\n") != 0);
  ret = EXIT_SUCCESS;
close_cli:
  close(cli_sock);
close_srv:
  close(srv_sock);
error_free:
  freeaddrinfo(ai_list);
error:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x44(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc8(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     126f <main+0x8f>
lea    0xdac(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    149c <main+0x2bc>
jmp    1274 <main+0x94>
mov    -0x38(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    12b8 <main+0xd8>
lea    0xd6f(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1493 <main+0x2b3>
jmp    12bd <main+0xdd>
mov    -0xc(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   10b0 <bind@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12fd <main+0x11d>
lea    0xd31(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1493 <main+0x2b3>
jmp    1302 <main+0x122>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   10a0 <listen@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1336 <main+0x156>
lea    0xcfd(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    148b <main+0x2ab>
jmp    133b <main+0x15b>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1090 <sockaddr2str@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
lea    0xcce(%rip),%rdi
lea    0xca3(%rip),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    13a7 <main+0x1c7>
lea    0xcac(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1483 <main+0x2a3>
jmp    13ac <main+0x1cc>
lea    -0x40(%rbp),%rdi
call   1090 <sockaddr2str@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
lea    0xc80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0xc4(%rbp)
cmpl   $0xffffffff,-0xc4(%rbp)
jne    141a <main+0x23a>
lea    0xc58(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1483 <main+0x2a3>
jmp    141f <main+0x23f>
lea    -0xc0(%rbp),%rsi
lea    0xc34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,-0xc4(%rbp)
mov    %al,-0xc5(%rbp)
je     1469 <main+0x289>
lea    -0xc0(%rbp),%rdi
lea    0xc0d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xc5(%rbp)
mov    -0xc5(%rbp),%al
test   $0x1,%al
jne    13d4 <main+0x1f4>
mov    0x2b42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    -0x8(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
lea    0xdc5(%rip),%rsi
mov    %rsp,%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
jne    13a4 <main+0x1c4>
mov    (%rsp),%rax
mov    0x14(%rax),%edi
mov    0xc(%rax),%edx
mov    0x10(%rax),%esi
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     13bb <main+0x1db>
mov    %eax,%r15d
mov    (%rsp),%rax
mov    (%rax),%rsi
mov    0x8(%rax),%edx
mov    %r15d,%edi
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     13c4 <main+0x1e4>
mov    %r15d,%edi
xor    %esi,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     13db <main+0x1fb>
mov    (%rsp),%rax
mov    (%rax),%rdi
call   1090 <sockaddr2str@plt>
mov    %rax,%rbx
lea    0xd72(%rip),%rdi
lea    0xd47(%rip),%rdx
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
call   10d0 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     13f2 <main+0x212>
lea    0x8(%rsp),%rdi
call   1090 <sockaddr2str@plt>
mov    %rax,%rbx
lea    0xd48(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x30(%rsp),%rbx
lea    0xd47(%rip),%r12
lea    0xd43(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     13fb <main+0x21b>
mov    %eax,%r14d
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
je     136f <main+0x18f>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1330 <main+0x150>
mov    0x2c4a(%rip),%rax
mov    (%rax),%ebx
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    (%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc5a(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c11(%rip),%rax
mov    (%rax),%ebx
jmp    1390 <main+0x1b0>
lea    0xc4f(%rip),%rdi
jmp    13cb <main+0x1eb>
lea    0xc4d(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%ebx
jmp    1387 <main+0x1a7>
lea    0xc3b(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bda(%rip),%rax
mov    (%rax),%ebx
jmp    137f <main+0x19f>
lea    0xc44(%rip),%rdi
jmp    1402 <main+0x222>
lea    0xc5a(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bba(%rip),%rax
jmp    1376 <main+0x196>

LLVM IR (-O0):
%struct.addrinfo = type { %struct.sockaddr*, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"6060\00"
@.str.1 = [12 x i8] c"getaddrinfo\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [25 x i8] c"Running server on %s:%s\0A\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [24 x i8] c"Client %s is connected\0A\00"
@.str.8 = [5 x i8] c"recv\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [6 x i8] c"exit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.sockaddr_storage
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [100 x i8]
%11 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %8
%12 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 32)
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 4
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 3
store i32 %15, i32* %16
%17 = load i32, i32* @AI_PASSIVE
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 5
store i32 %17, i32* %18
%19 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %5, %struct.addrinfo** %6)
store i32 %19, i32* %2
br label %20
20: ; preds = %0
%21 = load i32, i32* %2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %2
br label %131
26: ; preds = %20
br label %27
27: ; preds = %26
%28 = load %struct.addrinfo*, %struct.addrinfo** %6
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i32 0, i32 4
%30 = load i32, i32* %29
%31 = load %struct.addrinfo*, %struct.addrinfo** %6
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 3
%33 = load i32, i32* %32
%34 = load %struct.addrinfo*, %struct.addrinfo** %6
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i32 @socket(i32 %30, i32 %33, i32 %36)
store i32 %37, i32* %3
br label %38
38: ; preds = %27
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %2
br label %128
44: ; preds = %38
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = load %struct.addrinfo*, %struct.addrinfo** %6
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 0
%49 = load %struct.sockaddr*, %struct.sockaddr** %48
%50 = load %struct.addrinfo*, %struct.addrinfo** %6
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = call i32 @bind(i32 %46, %struct.sockaddr* %49, i32 %52)
store i32 %53, i32* %2
br label %54
54: ; preds = %45
%55 = load i32, i32* %2
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
store i32 %59, i32* %2
br label %128
60: ; preds = %54
br label %61
61: ; preds = %60
%62 = load i32, i32* %3
%63 = call i32 @listen(i32 %62, i32 0)
store i32 %63, i32* %2
br label %64
64: ; preds = %61
%65 = load i32, i32* %2
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
store i32 %69, i32* %2
br label %125
70: ; preds = %64
br label %71
71: ; preds = %70
%72 = load %struct.addrinfo*, %struct.addrinfo** %6
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 0
%74 = load %struct.sockaddr*, %struct.sockaddr** %73
%75 = call i8* @sockaddr2str(%struct.sockaddr* %74)
store i8* %75, i8** %9
%76 = load i8*, i8** %9
%77 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %76, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%78 = load i8*, i8** %9
%79 = call i32 @free(i8* %78)
%80 = load i32, i32* %3
%81 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%82 = call i32 @accept(i32 %80, %struct.sockaddr* %81, i32* %8)
store i32 %82, i32* %4
br label %83
83: ; preds = %71
%84 = load i32, i32* %4
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%88 = load i32, i32* @EXIT_FAILURE
store i32 %88, i32* %2
br label %122
89: ; preds = %83
br label %90
90: ; preds = %89
%91 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%92 = call i8* @sockaddr2str(%struct.sockaddr* %91)
store i8* %92, i8** %9
%93 = load i8*, i8** %9
%94 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %93)
%95 = load i8*, i8** %9
%96 = call i32 @free(i8* %95)
br label %97
97: ; preds = %118, %90
%98 = load i32, i32* %4
%99 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%100 = call i32 @recv(i32 %98, i8* %99, i32 100, i32 0)
store i32 %100, i32* %11
br label %101
101: ; preds = %97
%102 = load i32, i32* %11
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %107
104: ; preds = %101
%105 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%106 = load i32, i32* @EXIT_FAILURE
store i32 %106, i32* %2
br label %122
107: ; preds = %101
br label %108
108: ; preds = %107
%109 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%110 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %109)
br label %111
111: ; preds = %108
%112 = load i32, i32* %11
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %118
114: ; preds = %111
%115 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%116 = call i64 @strcmp(i8* %115, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%117 = icmp ne i64 %116, 0
br label %118
118: ; preds = %114, %111
%119 = phi i1 [ false, %111 ], [ %117, %114 ]
br i1 %119, label %97, label %120
120: ; preds = %118
%121 = load i32, i32* @EXIT_SUCCESS
store i32 %121, i32* %2
br label %122
122: ; preds = %120, %104, %86
%123 = load i32, i32* %4
%124 = call i32 @close(i32 %123)
br label %125
125: ; preds = %122, %67
%126 = load i32, i32* %3
%127 = call i32 @close(i32 %126)
br label %128
128: ; preds = %125, %57, %41
%129 = load %struct.addrinfo*, %struct.addrinfo** %6
%130 = call i32 @freeaddrinfo(%struct.addrinfo* %129)
br label %131
131: ; preds = %128, %23
%132 = load i32, i32* %2
ret i32 %132
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.sockaddr*, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"6060\00"
@.str.1 = [12 x i8] c"getaddrinfo\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [25 x i8] c"Running server on %s:%s\0A\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [24 x i8] c"Client %s is connected\0A\00"
@.str.8 = [5 x i8] c"recv\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [6 x i8] c"exit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = bitcast %struct.addrinfo* %1 to i8*
%7 = bitcast %struct.addrinfo** %2 to i8*
%8 = bitcast %struct.sockaddr_storage* %3 to i8*
%9 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 32)
%12 = load i32, i32* @AF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 4
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_STREAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 3
store i32 %14, i32* %15
%16 = load i32, i32* @AI_PASSIVE
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 5
store i32 %16, i32* %17
%18 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
br label %90
23: ; preds = %0
%24 = load %struct.addrinfo*, %struct.addrinfo** %2
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 3
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 2
%30 = load i32, i32* %29
%31 = call i32 @socket(i32 %26, i32 %28, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %23
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
br label %86
36: ; preds = %23
%37 = load %struct.addrinfo*, %struct.addrinfo** %2
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 0
%39 = load %struct.sockaddr*, %struct.sockaddr** %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 1
%41 = load i32, i32* %40
%42 = call i32 @bind(i32 %31, %struct.sockaddr* %39, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
br label %86
47: ; preds = %36
%48 = call i32 @listen(i32 %31, i32 0)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
br label %83
53: ; preds = %47
%54 = load %struct.addrinfo*, %struct.addrinfo** %2
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i64 0, i32 0
%56 = load %struct.sockaddr*, %struct.sockaddr** %55
%57 = call i8* @sockaddr2str(%struct.sockaddr* %56)
%58 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%59 = call i32 @free(i8* %57)
%60 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%61 = call i32 @accept(i32 %31, %struct.sockaddr* %60, i32* %4)
%62 = icmp eq i32 %61, -1
br i1 %62, label %76, label %63
63: ; preds = %53
%64 = call i8* @sockaddr2str(%struct.sockaddr* %60)
%65 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %64)
%66 = call i32 @free(i8* %64)
br label %67
67: ; preds = %73, %63
%68 = call i32 @recv(i32 %61, i8* %10, i32 100, i32 0)
%69 = icmp eq i32 %68, -1
br i1 %69, label %76, label %70
70: ; preds = %67
%71 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %10)
%72 = icmp eq i32 %68, 0
br i1 %72, label %79, label %73
73: ; preds = %70
%74 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %79, label %67
76: ; preds = %67, %53
%77 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), %53 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), %67 ]
%78 = call i32 @perror(i8* %77)
br label %79
79: ; preds = %73, %70, %76
%80 = phi i32* [ @EXIT_FAILURE, %76 ], [ @EXIT_SUCCESS, %70 ], [ @EXIT_SUCCESS, %73 ]
%81 = load i32, i32* %80
%82 = call i32 @close(i32 %61)
br label %83
83: ; preds = %79, %50
%84 = phi i32 [ %52, %50 ], [ %81, %79 ]
%85 = call i32 @close(i32 %31)
br label %86
86: ; preds = %83, %44, %33
%87 = phi i32 [ %35, %33 ], [ %46, %44 ], [ %84, %83 ]
%88 = load %struct.addrinfo*, %struct.addrinfo** %2
%89 = call i32 @freeaddrinfo(%struct.addrinfo* %88)
br label %90
90: ; preds = %86, %20
%91 = phi i32 [ %22, %20 ], [ %87, %86 ]
ret i32 %91
}