#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*/ server;
typedef int /*<<< orphan*/ client;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ printf(char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  char hello_buf[128];
  int port = 10001;
  int server_fd, client_fd, err;
  struct sockaddr_in server, client;
  char buf[1024];
  server_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (server_fd < 0) {
    fprintf(stderr, "Could not create socket\n");
    fflush(stderr);
    exit(1);
  };
  server.sin_family = AF_INET;
  server.sin_port = htons(port);
  server.sin_addr.s_addr = htonl(INADDR_ANY);
  int opt_val = 1;
  setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt_val, sizeof opt_val);
  err = bind(server_fd, (struct sockaddr *)&server, sizeof(server));
  if (err < 0) {
    fprintf(stderr, "Could not bind socket\n");
    fflush(stderr);
    exit(1);
  };
  err = listen(server_fd, 128);
  if (err < 0) {
    fprintf(stderr, "Could not listen on socket\n");
    fflush(stderr);
    exit(1);
  };
  printf("Server is listening on %d\n", port);
  while (1) {
    socklen_t client_len = sizeof(client);
    client_fd = accept(server_fd, (struct sockaddr *)&client, &client_len);
    if (client_fd < 0) {
      fprintf(stderr, "Could not establish new connection\n");
      fflush(stderr);
      exit(1);
    };
    while (1) {
      int read = recv(client_fd, buf, 1024, 0);
      if (!read)
        break;
      if (read < 0) {
        fprintf(stderr, "Client read failed\n");
        fflush(stderr);
        exit(1);
      };
      if (strncmp(buf, "My name is ", 11) == 0) {
        bzero(hello_buf, 128);
        strcpy(hello_buf, "Hello ");
        strcat(hello_buf, buf + 11);
        err = send(client_fd, hello_buf, strlen(hello_buf), 0);
      } else
        err = send(client_fd, buf, read, 0);
      if (err < 0) {
        fprintf(stderr, "Client write failed\n");
        fflush(stderr);
        exit(1);
      };
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2711,-0x94(%rbp)
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x98(%rbp)
jge    129c <main+0x7c>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    -0x94(%rbp),%edi
call   1080 <htons@plt>
mov    %eax,-0xac(%rbp)
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   10b0 <htonl@plt>
mov    %eax,-0xb0(%rbp)
movl   $0x1,-0x4c4(%rbp)
mov    -0x98(%rbp),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
mov    0x2cc8(%rip),%rax
mov    (%rax),%edx
lea    -0x4c4(%rbp),%rcx
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
mov    -0x98(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
mov    %eax,-0xa0(%rbp)
cmpl   $0x0,-0xa0(%rbp)
jge    135b <main+0x13b>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x98(%rbp),%edi
mov    $0x80,%esi
call   10e0 <listen@plt>
mov    %eax,-0xa0(%rbp)
cmpl   $0x0,-0xa0(%rbp)
jge    13ab <main+0x18b>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
lea    0xca2(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x94(%rbp),%esi
lea    0xc94(%rip),%rdi
call   10a0 <printf@plt>
movl   $0xc,-0x4c8(%rbp)
mov    -0x98(%rbp),%edi
lea    -0xc0(%rbp),%rsi
lea    -0x4c8(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
jge    1420 <main+0x200>
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
lea    0xc64(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2bb9(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    1425 <main+0x205>
mov    -0x9c(%rbp),%edi
lea    -0x4c0(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x4cc(%rbp)
cmpl   $0x0,-0x4cc(%rbp)
jne    1456 <main+0x236>
jmp    1593 <main+0x373>
cmpl   $0x0,-0x4cc(%rbp)
jge    1490 <main+0x270>
mov    0x2b5e(%rip),%rax
mov    (%rax),%edi
lea    0xc18(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    -0x4c0(%rbp),%rdi
lea    0xc01(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1534 <main+0x314>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1100 <bzero@plt>
lea    -0x90(%rbp),%rdi
lea    0xbda(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    -0x4c0(%rbp),%rsi
add    $0xb,%rsi
call   1120 <strcat@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4dc(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x4d8(%rbp)
lea    -0x90(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x4dc(%rbp),%edi
mov    -0x4d8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,-0xa0(%rbp)
jmp    1554 <main+0x334>
mov    -0x9c(%rbp),%edi
lea    -0x4c0(%rbp),%rsi
mov    -0x4cc(%rbp),%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,-0xa0(%rbp)
cmpl   $0x0,-0xa0(%rbp)
jge    158e <main+0x36e>
mov    0x2a60(%rip),%rax
mov    (%rax),%edi
lea    0xb41(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2a4b(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    1425 <main+0x205>
jmp    13bd <main+0x19d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4b8,%rsp
mov    0x2da8(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
test   %eax,%eax
jns    1263 <main+0x43>
mov    0x2d73(%rip),%rbx
mov    (%rbx),%edi
lea    0xda2(%rip),%rsi
jmp    144f <main+0x22f>
mov    %eax,%r15d
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x2711,%edi
call   1080 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   10b0 <htonl@plt>
mov    %eax,0x10(%rsp)
movl   $0x1,0xc(%rsp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2d14(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10f0 <bind@plt>
test   %eax,%eax
jns    12e4 <main+0xc4>
mov    0x2cf2(%rip),%rbx
mov    (%rbx),%edi
lea    0xd3a(%rip),%rsi
jmp    144f <main+0x22f>
mov    %r15d,%edi
mov    $0x80,%esi
call   10e0 <listen@plt>
test   %eax,%eax
jns    130a <main+0xea>
mov    0x2ccc(%rip),%rbx
mov    (%rbx),%edi
lea    0xd2b(%rip),%rsi
jmp    144f <main+0x22f>
lea    0xd3b(%rip),%rdi
mov    $0x2711,%esi
call   10a0 <printf@plt>
movl   $0xc,0x4(%rsp)
lea    0x20(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r15d,%edi
call   1110 <accept@plt>
test   %eax,%eax
jns    134e <main+0x12e>
mov    0x2c88(%rip),%rbx
mov    (%rbx),%edi
lea    0xd1e(%rip),%rsi
jmp    144f <main+0x22f>
mov    %eax,%ebx
lea    0xb0(%rsp),%rbp
lea    0xd40(%rip),%r12
lea    0x30(%rsp),%r13
lea    0xd40(%rip),%r14
mov    %r15d,0x8(%rsp)
jmp    1397 <main+0x177>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
test   %eax,%eax
js     142d <main+0x20d>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1403 <main+0x1e3>
js     143f <main+0x21f>
mov    %eax,%r15d
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1380 <main+0x160>
mov    %r13,%rdi
mov    $0x80,%esi
call   1100 <bzero@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    %r13,%rdi
lea    0xbb(%rsp),%rsi
call   1120 <strcat@plt>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
jmp    1388 <main+0x168>
movl   $0xc,0x4(%rsp)
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1110 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1397 <main+0x177>
jmp    1339 <main+0x119>
mov    0x2b94(%rip),%rbx
mov    (%rbx),%edi
lea    0xc75(%rip),%rsi
jmp    144f <main+0x22f>
mov    0x2b82(%rip),%rbx
mov    (%rbx),%edi
lea    0xc3c(%rip),%rsi
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

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
@stderr = global i32 0
@.str = [25 x i8] c"Could not create socket\0A\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [23 x i8] c"Could not bind socket\0A\00"
@.str.2 = [28 x i8] c"Could not listen on socket\0A\00"
@.str.3 = [27 x i8] c"Server is listening on %d\0A\00"
@.str.4 = [36 x i8] c"Could not establish new connection\0A\00"
@.str.5 = [20 x i8] c"Client read failed\0A\00"
@.str.6 = [12 x i8] c"My name is \00"
@.str.7 = [7 x i8] c"Hello \00"
@.str.8 = [21 x i8] c"Client write failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca [1024 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10001, i32* %7
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 @fflush(i32 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* %7
%32 = call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_ANY
%35 = call i32 @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
store i32 1, i32* %14
%38 = load i32, i32* %8
%39 = load i32, i32* @SOL_SOCKET
%40 = load i32, i32* @SO_REUSEADDR
%41 = call i32 @setsockopt(i32 %38, i32 %39, i32 %40, i32* %14, i32 4)
%42 = load i32, i32* %8
%43 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%44 = call i32 @bind(i32 %42, %struct.sockaddr* %43, i32 12)
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %28
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32, i32* @stderr
%51 = call i32 @fflush(i32 %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %28
%54 = load i32, i32* %8
%55 = call i32 @listen(i32 %54, i32 128)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* @stderr
%62 = call i32 @fflush(i32 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %53
%65 = load i32, i32* %7
%66 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %129
store i32 12, i32* %15
%68 = load i32, i32* %8
%69 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%70 = call i32 @accept(i32 %68, %struct.sockaddr* %69, i32* %15)
store i32 %70, i32* %9
%71 = load i32, i32* %9
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %67
%74 = load i32, i32* @stderr
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32, i32* @stderr
%77 = call i32 @fflush(i32 %76)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %67
br label %80
80: ; preds = %79, %128
%81 = load i32, i32* %9
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%83 = call i32 @recv(i32 %81, i8* %82, i32 1024, i32 0)
store i32 %83, i32* %16
%84 = load i32, i32* %16
%85 = icmp ne i32 %84, 0
br i1 %85, label %87, label %86
86: ; preds = %80
br label %129
87: ; preds = %80
%88 = load i32, i32* %16
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %96
90: ; preds = %87
%91 = load i32, i32* @stderr
%92 = call i32 @fprintf(i32 %91, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%93 = load i32, i32* @stderr
%94 = call i32 @fflush(i32 %93)
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %87
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%98 = call i64 @strncmp(i8* %97, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 11)
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %114
100: ; preds = %96
%101 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%102 = call i32 @bzero(i8* %101, i32 128)
%103 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%104 = call i32 @strcpy(i8* %103, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%105 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%107 = getelementptr inbounds i8, i8* %106, i64 11
%108 = call i32 @strcat(i8* %105, i8* %107)
%109 = load i32, i32* %9
%110 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%111 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%112 = call i32 @strlen(i8* %111)
%113 = call i32 @send(i32 %109, i8* %110, i32 %112, i32 0)
store i32 %113, i32* %10
br label %119
114: ; preds = %96
%115 = load i32, i32* %9
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%117 = load i32, i32* %16
%118 = call i32 @send(i32 %115, i8* %116, i32 %117, i32 0)
store i32 %118, i32* %10
br label %119
119: ; preds = %114, %100
%120 = load i32, i32* %10
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %128
122: ; preds = %119
%123 = load i32, i32* @stderr
%124 = call i32 @fprintf(i32 %123, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%125 = load i32, i32* @stderr
%126 = call i32 @fflush(i32 %125)
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %119
br label %80
129: ; preds = %86
br label %67
}

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
@stderr = global i32 0
@.str = [25 x i8] c"Could not create socket\0A\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [23 x i8] c"Could not bind socket\0A\00"
@.str.2 = [28 x i8] c"Could not listen on socket\0A\00"
@.str.3 = [27 x i8] c"Server is listening on %d\0A\00"
@.str.4 = [36 x i8] c"Could not establish new connection\0A\00"
@.str.5 = [20 x i8] c"Client read failed\0A\00"
@.str.6 = [12 x i8] c"My name is \00"
@.str.7 = [7 x i8] c"Hello \00"
@.str.8 = [21 x i8] c"Client write failed\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = tail call i32 @fflush(i32 %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %24, i32* %25
%26 = tail call i32 @htons(i32 10001)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = tail call i32 @htonl(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %29, i32* %30
%31 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%32 = load i32, i32* @SOL_SOCKET
%33 = load i32, i32* @SO_REUSEADDR
%34 = call i32 @setsockopt(i32 %15, i32 %32, i32 %33, i32* %7, i32 4)
%35 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%36 = call i32 @bind(i32 %15, %struct.sockaddr* %35, i32 12)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %23
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 @fflush(i32 %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %23
%45 = call i32 @listen(i32 %15, i32 128)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* @stderr
%51 = call i32 @fflush(i32 %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 10001)
%55 = bitcast i32* %8 to i8*
%56 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
store i32 12, i32* %8
%57 = call i32 @accept(i32 %15, %struct.sockaddr* %56, i32* %8)
%58 = icmp slt i32 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %53
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 11
br label %61
61: ; preds = %59, %100
%62 = phi i32 [ %57, %59 ], [ %101, %100 ]
br label %69
63: ; preds = %100, %53
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* @stderr
%67 = call i32 @fflush(i32 %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %61, %91
%70 = call i32 @recv(i32 %62, i8* %12, i32 1024, i32 0)
%71 = icmp eq i32 %70, 0
br i1 %71, label %100, label %72
72: ; preds = %69
%73 = icmp slt i32 %70, 0
br i1 %73, label %74, label %80
74: ; preds = %72
%75 = load i32, i32* @stderr
%76 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32, i32* @stderr
%78 = call i32 @fflush(i32 %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %72
%81 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 11)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %89
83: ; preds = %80
%84 = call i32 @bzero(i8* %9, i32 128)
%85 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%86 = call i32 @strcat(i8* %9, i8* %60)
%87 = call i32 @strlen(i8* %9)
%88 = call i32 @send(i32 %62, i8* %9, i32 %87, i32 0)
br label %91
89: ; preds = %80
%90 = call i32 @send(i32 %62, i8* %12, i32 %70, i32 0)
br label %91
91: ; preds = %89, %83
%92 = phi i32 [ %88, %83 ], [ %90, %89 ]
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %69
94: ; preds = %91
%95 = load i32, i32* @stderr
%96 = call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%97 = load i32, i32* @stderr
%98 = call i32 @fflush(i32 %97)
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %69
store i32 12, i32* %8
%101 = call i32 @accept(i32 %15, %struct.sockaddr* %56, i32* %8)
%102 = icmp slt i32 %101, 0
br i1 %102, label %63, label %61
}