#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 */
typedef int u_short;
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_name;
typedef int /*<<< orphan*/ client_name;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int server_sockfd = -1;
  int client_sockfd = -1;
  u_short port = 9001;
  struct sockaddr_in client_name;
  struct sockaddr_in server_name;
  socklen_t client_name_len = sizeof(client_name);
  char buf[1024];
  char recv_buf[1024];
  char hello_str[] = "Hello world!";
  int hello_len = 0;
  server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (server_sockfd == -1) {
    perror("socket");
    exit(-1);
  }
  memset(&server_name, 0, sizeof(server_name));
  server_name.sin_family = AF_INET;
  server_name.sin_port = htons(9001);
  server_name.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(server_sockfd, (struct sockaddr *)&server_name,
           sizeof(server_name)) < 0) {
    perror("bind");
    exit(-1);
  }
  if (listen(server_sockfd, 5) < 0) {
    perror("listen");
    exit(-1);
  }
  printf("http server running on port %d\n", port);
  while (1) {
    if ((client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_name,
                                &client_name_len)) < 0) {
      perror("accept");
      exit(-1);
    }
    printf("accept a client\n");
    hello_len = recv(client_sockfd, recv_buf, 1024, 0);
    printf("receive %d\n", hello_len);
    sprintf(buf, "HTTP/1.0 200 OK\r\n");
    write(client_sockfd, buf, strlen(buf));
    strcpy(buf, "Server: hoohackhttpd/0.1.0\r\n");
    write(client_sockfd, buf, strlen(buf));
    sprintf(buf, "Content-Type: text/html\r\n");
    write(client_sockfd, buf, strlen(buf));
    strcpy(buf, "\r\n");
    write(client_sockfd, buf, strlen(buf));
    sprintf(buf, "Hello World\r\n");
    write(client_sockfd, buf, strlen(buf));
    printf("%s\n", buf);
    close(client_sockfd);
  }
  close(server_sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x2329,-0x10(%rbp)
movl   $0xc,-0x34(%rbp)
mov    0xdcb(%rip),%rax
mov    %rax,-0x84d(%rbp)
mov    0xdc6(%rip),%eax
mov    %eax,-0x845(%rbp)
mov    0xdbe(%rip),%al
mov    %al,-0x841(%rbp)
movl   $0x0,-0x854(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    129a <main+0x9a>
lea    0xd82(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x2329,%edi
call   1070 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    1305 <main+0x105>
lea    0xd1e(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
cmp    $0x0,%rax
jge    1332 <main+0x132>
lea    0xcf6(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%esi
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1375 <main+0x175>
lea    0xcda(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x840(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x854(%rbp)
mov    -0x854(%rbp),%esi
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x440(%rbp),%rdi
lea    0xca3(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8a4(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x8a0(%rbp)
lea    -0x440(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x8a4(%rbp),%edi
mov    -0x8a0(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    -0x440(%rbp),%rdi
lea    0xc6b(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x894(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x890(%rbp)
lea    -0x440(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x894(%rbp),%edi
mov    -0x890(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    -0x440(%rbp),%rdi
lea    0xc3e(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x884(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x880(%rbp)
lea    -0x440(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x884(%rbp),%edi
mov    -0x880(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    -0x440(%rbp),%rdi
lea    0xbf1(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x874(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x870(%rbp)
lea    -0x440(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x874(%rbp),%edi
mov    -0x870(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    -0x440(%rbp),%rdi
lea    0xbc4(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x864(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x860(%rbp)
lea    -0x440(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x864(%rbp),%edi
mov    -0x860(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    -0x440(%rbp),%rsi
lea    0xb88(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xc(%rbp),%edi
call   10b0 <close@plt>
jmp    1343 <main+0x143>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2dc8(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
jne    1244 <main+0x44>
lea    0xdc1(%rip),%rdi
jmp    1431 <main+0x231>
mov    %eax,%r13d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x2329,%edi
call   1080 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    12a3 <main+0xa3>
lea    0xd69(%rip),%rdi
jmp    1431 <main+0x231>
mov    %r13d,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
test   %rax,%rax
jns    12c1 <main+0xc1>
lea    0xd50(%rip),%rdi
jmp    1431 <main+0x231>
lea    0xd4b(%rip),%rdi
mov    $0x2329,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   1100 <accept@plt>
test   %eax,%eax
js     142a <main+0x22a>
mov    %eax,%ebp
lea    0x30(%rsp),%rbx
movabs $0xa0d646c726f57,%r15
lea    0x20(%rsp),%r12
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
lea    0xd86(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
lea    0x430(%rsp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xd01(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
movups 0xcfd(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movw   $0xa,0x40(%rsp)
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %rbx,%rdi
lea    0xce5(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
movups 0xce2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xce0(%rip),%xmm0
movups %xmm0,0x3a(%rsp)
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %rbx,%rdi
lea    0xcb0(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
movabs $0x6f57206f6c6c6548,%rax
20 57 6f
mov    %rax,0x30(%rsp)
mov    %r15,0x36(%rsp)
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
call   10c0 <close@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1100 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1310 <main+0x110>
lea    0xc02(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.hello_str = [13 x i8] c"Hello world!\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [32 x i8] c"http server running on port %d\0A\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [17 x i8] c"accept a client\0A\00"
@.str.6 = [12 x i8] c"receive %d\0A\00"
@.str.7 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.8 = [29 x i8] c"Server: hoohackhttpd/0.1.0\0D\0A\00"
@.str.9 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.10 = [3 x i8] c"\0D\0A\00"
@.str.11 = [14 x i8] c"Hello World\0D\0A\00"
@.str.12 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [13 x i8]
%11 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 -1, i32* %3
store i32 9001, i32* %4
store i32 12, i32* %7
%12 = bitcast [13 x i8]* %10 to i8*
store i32 0, i32* %11
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %0
%22 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 9001)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = call i32 @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* %2
%32 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%33 = call i64 @bind(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %21
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %21
%39 = load i32, i32* %2
%40 = call i64 @listen(i32 %39, i32 5)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %38
%46 = load i32, i32* %4
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45, %56
%49 = load i32, i32* %2
%50 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%51 = call i32 @accept(i32 %49, %struct.sockaddr* %50, i32* %7)
store i32 %51, i32* %3
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %48
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%58 = load i32, i32* %3
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%60 = call i32 @recv(i32 %58, i8* %59, i32 1024, i32 0)
store i32 %60, i32* %11
%61 = load i32, i32* %11
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%64 = call i32 @sprintf(i8* %63, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%65 = load i32, i32* %3
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%68 = call i32 @strlen(i8* %67)
%69 = call i32 @write(i32 %65, i8* %66, i32 %68)
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%71 = call i32 @strcpy(i8* %70, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%72 = load i32, i32* %3
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = call i32 @write(i32 %72, i8* %73, i32 %75)
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%78 = call i32 @sprintf(i8* %77, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%79 = load i32, i32* %3
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%82 = call i32 @strlen(i8* %81)
%83 = call i32 @write(i32 %79, i8* %80, i32 %82)
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%85 = call i32 @strcpy(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%86 = load i32, i32* %3
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%89 = call i32 @strlen(i8* %88)
%90 = call i32 @write(i32 %86, i8* %87, i32 %89)
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%92 = call i32 @sprintf(i8* %91, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%93 = load i32, i32* %3
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%96 = call i32 @strlen(i8* %95)
%97 = call i32 @write(i32 %93, i8* %94, i32 %96)
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %98)
%100 = load i32, i32* %3
%101 = call i32 @close(i32 %100)
br label %48
}

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
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [32 x i8] c"http server running on port %d\0A\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.6 = [12 x i8] c"receive %d\0A\00"
@.str.7 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.8 = [29 x i8] c"Server: hoohackhttpd/0.1.0\0D\0A\00"
@.str.9 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.10 = [3 x i8] c"\0D\0A\00"
@.str.11 = [14 x i8] c"Hello World\0D\0A\00"
@str = [16 x i8] c"accept a client\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %0
%19 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 9001)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
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* %2, i64 0, i32 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%28 = call i64 @bind(i32 %13, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %18
%34 = call i64 @listen(i32 %13, i32 5)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %33
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 9001)
%41 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%42 = call i32 @accept(i32 %13, %struct.sockaddr* %41, i32* %3)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %47, %39
%45 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %39, %47
%48 = phi i32 [ %66, %47 ], [ %42, %39 ]
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%50 = call i32 @recv(i32 %48, i8* %10, i32 1024, i32 0)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = call i32 @strlen(i8* %9)
%53 = call i32 @write(i32 %48, i8* %9, i32 %52)
%54 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%55 = call i32 @strlen(i8* %9)
%56 = call i32 @write(i32 %48, i8* %9, i32 %55)
%57 = call i32 @strlen(i8* %9)
%58 = call i32 @write(i32 %48, i8* %9, i32 %57)
%59 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%60 = call i32 @strlen(i8* %9)
%61 = call i32 @write(i32 %48, i8* %9, i32 %60)
%62 = call i32 @strlen(i8* %9)
%63 = call i32 @write(i32 %48, i8* %9, i32 %62)
%64 = call i32 @puts(i8* %9)
%65 = call i32 @close(i32 %48)
%66 = call i32 @accept(i32 %13, %struct.sockaddr* %41, i32* %3)
%67 = icmp slt i32 %66, 0
br i1 %67, label %44, label %47
}