#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 socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int pid_t;
typedef int /*<<< orphan*/ peeraddr;
typedef int /*<<< orphan*/ on;
typedef int /*<<< orphan*/ connaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SOMAXCONN;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_recv(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ get_localip(char *);
scalar_t__ getpeername(int, struct sockaddr *, int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int listenfd;
  if ((listenfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    do {
      perror("socket");
      exit(EXIT_FAILURE);
    } while (0);
  }
  struct sockaddr_in servaddr;
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(5188);
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  int on = 1;
  if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) {
    do {
      perror("setsockopt");
      exit(EXIT_FAILURE);
    } while (0);
  }
  if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    do {
      perror("bind");
      exit(EXIT_FAILURE);
    } while (0);
  }
  if (listen(listenfd, SOMAXCONN) < 0) {
    do {
      perror("listen");
      exit(EXIT_FAILURE);
    } while (0);
  }
  struct sockaddr_in peeraddr;
  socklen_t peerlen = sizeof(peeraddr);
  int conn;
  pid_t pid;
  while (1) {
    if ((conn = accept(listenfd, (struct sockaddr *)&peeraddr, &peerlen)) < 0) {
      do {
        perror("accept");
        exit(EXIT_FAILURE);
      } while (0);
    }
    printf("ip = %s, port = %d\n", inet_ntoa(peeraddr.sin_addr),
           ntohs(peeraddr.sin_port));
    struct sockaddr_in connaddr;
    socklen_t connlen = sizeof(connaddr);
    if ((getpeername(conn, (struct sockaddr *)&connaddr, &connlen)) < 0) {
      do {
        perror("getpeername");
        exit(EXIT_FAILURE);
      } while (0);
    }
    printf("conn ip = %s, port = %d\n", inet_ntoa(connaddr.sin_addr),
           ntohs(connaddr.sin_port));
    char ip[16] = {0};
    if ((get_localip(ip)) < 0) {
      do {
        perror("get_localip");
        exit(EXIT_FAILURE);
      } while (0);
    }
    printf("localip: %s\n", ip);
    pid = fork();
    if (pid == -1) {
      do {
        perror("fork");
        exit(EXIT_FAILURE);
      } while (0);
    } else if (pid == 0) {
      close(listenfd);
      do_recv(conn);
      exit(EXIT_SUCCESS);
    } else {
      close(conn);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    127a <main+0x5a>
jmp    1260 <main+0x40>
lea    0xd99(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1444,%edi
call   1060 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
mov    0x2cca(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1308 <main+0xe8>
jmp    12ee <main+0xce>
lea    0xd12(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    1342 <main+0x122>
jmp    1328 <main+0x108>
lea    0xce3(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2c74(%rip),%rax
mov    (%rax),%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    137c <main+0x15c>
jmp    1362 <main+0x142>
lea    0xcae(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
movl   $0xc,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    13be <main+0x19e>
jmp    13a4 <main+0x184>
lea    0xc73(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x24(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%edi
call   10d0 <ntohs@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    0xc57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xc,-0x44(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1050 <getpeername@plt>
cmp    $0x0,%rax
jge    1426 <main+0x206>
jmp    140c <main+0x1ec>
lea    0xc12(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x3c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x70(%rbp)
mov    -0x40(%rbp),%edi
call   10d0 <ntohs@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
lea    0xbea(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
lea    -0x60(%rbp),%rdi
call   10c0 <get_localip@plt>
cmp    $0x0,%rax
jge    1490 <main+0x270>
jmp    1476 <main+0x256>
lea    0xbcd(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2b1f(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    -0x60(%rbp),%rsi
lea    0xbbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    14d5 <main+0x2b5>
jmp    14bb <main+0x29b>
lea    0xba1(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2ada(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
cmpl   $0x0,-0x34(%rbp)
jne    14fd <main+0x2dd>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
mov    -0x30(%rbp),%edi
call   1100 <do_recv@plt>
mov    0x2aaa(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x30(%rbp),%edi
call   10a0 <close@plt>
jmp    150a <main+0x2ea>
jmp    1383 <main+0x163>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
test   %eax,%eax
jns    125e <main+0x3e>
lea    0xdb7(%rip),%rdi
jmp    133e <main+0x11e>
mov    %eax,%r12d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x1444,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x14(%rsp)
movl   $0x1,0xc(%rsp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
mov    0x2ce1(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    12da <main+0xba>
lea    0xd3f(%rip),%rdi
jmp    133e <main+0x11e>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    12fa <main+0xda>
lea    0xd2a(%rip),%rdi
jmp    133e <main+0x11e>
mov    0x2cbf(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   10b0 <listen@plt>
test   %rax,%rax
jns    1319 <main+0xf9>
lea    0xd10(%rip),%rdi
jmp    133e <main+0x11e>
movl   $0xc,0x4(%rsp)
lea    0x20(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
call   1110 <accept@plt>
test   %eax,%eax
jns    1351 <main+0x131>
lea    0xcf0(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    %eax,%ebp
lea    0x40(%rsp),%r14
lea    0x4(%rsp),%r13
nopl   (%rax)
mov    0x24(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r15
mov    0x20(%rsp),%edi
call   10d0 <ntohs@plt>
lea    0xcca(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
movl   $0xc,0x8(%rsp)
mov    %ebp,%edi
lea    0x30(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <getpeername@plt>
test   %rax,%rax
js     142e <main+0x20e>
mov    0x34(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x30(%rsp),%edi
call   10d0 <ntohs@plt>
lea    0xc7b(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
mov    %r14,%rdi
call   10c0 <get_localip@plt>
test   %rax,%rax
js     143a <main+0x21a>
lea    0xc78(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1130 <fork@plt>
test   %eax,%eax
je     1446 <main+0x226>
cmp    $0xffffffff,%eax
je     1463 <main+0x243>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r12d,%edi
lea    0x20(%rsp),%rsi
mov    %r13,%rdx
call   1110 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1360 <main+0x140>
jmp    1337 <main+0x117>
lea    0xc00(%rip),%rdi
jmp    133e <main+0x11e>
lea    0xc19(%rip),%rdi
jmp    133e <main+0x11e>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   1100 <do_recv@plt>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    0xc09(%rip),%rdi
jmp    133e <main+0x11e>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@.str.2 = [5 x i8] c"bind\00"
@SOMAXCONN = global i32 0
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [20 x i8] c"ip = %s, port = %d\0A\00"
@.str.6 = [12 x i8] c"getpeername\00"
@.str.7 = [25 x i8] c"conn ip = %s, port = %d\0A\00"
@.str.8 = [12 x i8] c"get_localip\00"
@.str.9 = [13 x i8] c"localip: %s\0A\00"
@.str.10 = [5 x i8] c"fork\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca [16 x i8]
store i32 0, i32* %1
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = load i32, i32* @IPPROTO_TCP
%15 = call i32 @socket(i32 %12, i32 %13, i32 %14)
store i32 %15, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %0
br label %18
18: ; preds = %17
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; No predecessors!
br label %23
23: ; preds = %22, %0
%24 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @htons(i32 5188)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
store i32 1, i32* %4
%33 = load i32, i32* %2
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_REUSEADDR
%36 = call i64 @setsockopt(i32 %33, i32 %34, i32 %35, i32* %4, i32 4)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %23
br label %39
39: ; preds = %38
%40 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; No predecessors!
br label %44
44: ; preds = %43, %23
%45 = load i32, i32* %2
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%47 = call i64 @bind(i32 %45, %struct.sockaddr* %46, i32 12)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %44
br label %50
50: ; preds = %49
%51 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; No predecessors!
br label %55
55: ; preds = %54, %44
%56 = load i32, i32* %2
%57 = load i32, i32* @SOMAXCONN
%58 = call i64 @listen(i32 %56, i32 %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %55
br label %61
61: ; preds = %60
%62 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; No predecessors!
br label %66
66: ; preds = %65, %55
store i32 12, i32* %6
br label %67
67: ; preds = %66, %142
%68 = load i32, i32* %2
%69 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%70 = call i32 @accept(i32 %68, %struct.sockaddr* %69, i32* %6)
store i32 %70, i32* %7
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %67
br label %73
73: ; preds = %72
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; No predecessors!
br label %78
78: ; preds = %77, %67
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%80 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i8* @inet_ntoa(i32 %81)
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 @ntohs(i32 %84)
%86 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %82, i32 %85)
store i32 12, i32* %10
%87 = load i32, i32* %7
%88 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%89 = call i64 @getpeername(i32 %87, %struct.sockaddr* %88, i32* %10)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %97
91: ; preds = %78
br label %92
92: ; preds = %91
%93 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%94 = load i32, i32* @EXIT_FAILURE
%95 = call i32 @exit(i32 %94)
unreachable
96: ; No predecessors!
br label %97
97: ; preds = %96, %78
%98 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%99 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %98, i32 0, i32 0
%100 = load i32, i32* %99
%101 = call i8* @inet_ntoa(i32 %100)
%102 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%103 = load i32, i32* %102
%104 = call i32 @ntohs(i32 %103)
%105 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %101, i32 %104)
%106 = bitcast [16 x i8]* %11 to i8*
%107 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%108 = call i64 @get_localip(i8* %107)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %116
110: ; preds = %97
br label %111
111: ; preds = %110
%112 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%113 = load i32, i32* @EXIT_FAILURE
%114 = call i32 @exit(i32 %113)
unreachable
115: ; No predecessors!
br label %116
116: ; preds = %115, %97
%117 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%118 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* %117)
%119 = call i32 (...) @fork()
store i32 %119, i32* %8
%120 = load i32, i32* %8
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %128
122: ; preds = %116
br label %123
123: ; preds = %122
%124 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; No predecessors!
br label %142
128: ; preds = %116
%129 = load i32, i32* %8
%130 = icmp eq i32 %129, 0
br i1 %130, label %131, label %138
131: ; preds = %128
%132 = load i32, i32* %2
%133 = call i32 @close(i32 %132)
%134 = load i32, i32* %7
%135 = call i32 @do_recv(i32 %134)
%136 = load i32, i32* @EXIT_SUCCESS
%137 = call i32 @exit(i32 %136)
unreachable
138: ; preds = %128
%139 = load i32, i32* %7
%140 = call i32 @close(i32 %139)
br label %141
141: ; preds = %138
br label %142
142: ; preds = %141, %127
br label %67
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@.str.2 = [5 x i8] c"bind\00"
@SOMAXCONN = global i32 0
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [20 x i8] c"ip = %s, port = %d\0A\00"
@.str.6 = [12 x i8] c"getpeername\00"
@.str.7 = [25 x i8] c"conn ip = %s, port = %d\0A\00"
@.str.8 = [12 x i8] c"get_localip\00"
@.str.9 = [13 x i8] c"localip: %s\0A\00"
@.str.10 = [5 x i8] c"fork\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca [16 x i8]
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = load i32, i32* @IPPROTO_TCP
%11 = tail call i32 @socket(i32 %8, i32 %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = bitcast %struct.sockaddr_in* %1 to i8*
%19 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 5188)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_REUSEADDR
%30 = call i64 @setsockopt(i32 %11, i32 %28, i32 %29, i32* %2, i32 4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %17
%33 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %17
%37 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%38 = call i64 @bind(i32 %11, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %36
%45 = load i32, i32* @SOMAXCONN
%46 = call i64 @listen(i32 %11, i32 %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %44
%53 = bitcast %struct.sockaddr_in* %3 to i8*
%54 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%55 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%56 = call i32 @accept(i32 %11, %struct.sockaddr* %55, i32* %4)
%57 = icmp slt i32 %56, 0
br i1 %57, label %67, label %58
58: ; preds = %52
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%61 = bitcast %struct.sockaddr_in* %5 to i8*
%62 = bitcast i32* %6 to i8*
%63 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
br label %71
67: ; preds = %108, %52
%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
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %58, %108
%72 = phi i32 [ %56, %58 ], [ %110, %108 ]
%73 = load i32, i32* %59
%74 = call i8* @inet_ntoa(i32 %73)
%75 = load i32, i32* %60
%76 = call i32 @ntohs(i32 %75)
%77 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %74, i32 %76)
store i32 12, i32* %6
%78 = call i64 @getpeername(i32 %72, %struct.sockaddr* %63, i32* %6)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %71
%81 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %71
%85 = load i32, i32* %64
%86 = call i8* @inet_ntoa(i32 %85)
%87 = load i32, i32* %65
%88 = call i32 @ntohs(i32 %87)
%89 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %86, i32 %88)
%90 = call i64 @get_localip(i8* %66)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %84
%93 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%94 = load i32, i32* @EXIT_FAILURE
%95 = call i32 @exit(i32 %94)
unreachable
96: ; preds = %84
%97 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* %66)
%98 = call i32 (...) @fork()
switch i32 %98, label %108 [
i32 -1, label %99
i32 0, label %103
]
99: ; preds = %96
%100 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %96
%104 = call i32 @close(i32 %11)
%105 = call i32 @do_recv(i32 %72)
%106 = load i32, i32* @EXIT_SUCCESS
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %96
%109 = call i32 @close(i32 %72)
%110 = call i32 @accept(i32 %11, %struct.sockaddr* %55, i32* %4)
%111 = icmp slt i32 %110, 0
br i1 %111, label %67, label %71
}