#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;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr_in *, int *);
scalar_t__ bind(int, struct sockaddr_in *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(void) {
  char *reply = "HTTP/1.1 200 OK\n"
                "Date: Thu, 19 Feb 2009 12:27:04 GMT\n"
                "Server: Apache/2.2.3\n"
                "Last-Modified: Wed, 18 Jun 2003 16:05:58 GMT\n"
                "ETag: \"56d-9989200-1132c580\"\n"
                "Content-Type: text/html\n"
                "Content-Length: 15\n"
                "Accept-Ranges: bytes\n"
                "Connection: close\n"
                "\n"
                "sdfkjsdnbfkjbsf";
  int sd = socket(PF_INET, SOCK_STREAM, 0);
  struct sockaddr_in addr;
  bzero(&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(8081);
  addr.sin_addr.s_addr = INADDR_ANY;
  if (bind(sd, &addr, sizeof(addr)) != 0) {
    printf("bind error\n");
  }
  if (listen(sd, 16) != 0) {
    printf("listen error\n");
  }
  for (;;) {
    socklen_t size = sizeof(addr);
    int client = accept(sd, &addr, &size);
    if (client > 0) {
      printf("client connected\n");
      send(client, reply, strlen(reply), 0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1f91,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
je     1220 <main+0x90>
lea    0xedb(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x10,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
je     1243 <main+0xb3>
lea    0xec4(%rip),%rdi
call   1060 <printf@plt>
jmp    1248 <main+0xb8>
movl   $0xc,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    129f <main+0x10f>
lea    0xe9d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
jmp    1248 <main+0xb8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r13d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x1f91,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
je     1215 <main+0x85>
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
mov    %r13d,%edi
mov    $0x10,%esi
call   1070 <listen@plt>
test   %rax,%rax
je     1233 <main+0xa3>
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
lea    0xeb2(%rip),%r12
lea    0xdb5(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movl   $0xc,0x4(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10a0 <accept@plt>
test   %eax,%eax
jle    1250 <main+0xc0>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    1250 <main+0xc0>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [246 x i8] c"HTTP/1.1 200 OK\0ADate: Thu, 19 Feb 2009 12:27:04 GMT\0AServer: Apache/2.2.3\0ALast-Modified: Wed, 18 Jun 2003 16:05:58 GMT\0AETag: \2256d-9989200-1132c580\22\0AContent-Type: text/html\0AContent-Length: 15\0AAccept-Ranges: bytes\0AConnection: close\0A\0Asdfkjsdnbfkjbsf\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [12 x i8] c"bind error\0A\00"
@.str.2 = [14 x i8] c"listen error\0A\00"
@.str.3 = [18 x i8] c"client connected\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([246 x i8], [246 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @htons(i32 8081)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i32, i32* %3
%19 = call i64 @bind(i32 %18, %struct.sockaddr_in* %4, i32 12)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %0
%24 = load i32, i32* %3
%25 = call i64 @listen(i32 %24, i32 16)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
br label %30
30: ; preds = %42, %29
store i32 12, i32* %5
%31 = load i32, i32* %3
%32 = call i32 @accept(i32 %31, %struct.sockaddr_in* %4, i32* %5)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %6
%38 = load i8*, i8** %2
%39 = load i8*, i8** %2
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @send(i32 %37, i8* %38, i32 %40, i32 0)
br label %42
42: ; preds = %35, %30
br label %30
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [246 x i8] c"HTTP/1.1 200 OK\0ADate: Thu, 19 Feb 2009 12:27:04 GMT\0AServer: Apache/2.2.3\0ALast-Modified: Wed, 18 Jun 2003 16:05:58 GMT\0AETag: \2256d-9989200-1132c580\22\0AContent-Type: text/html\0AContent-Length: 15\0AAccept-Ranges: bytes\0AConnection: close\0A\0Asdfkjsdnbfkjbsf\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@str = [17 x i8] c"client connected\00"
@str.4 = [13 x i8] c"listen error\00"
@str.5 = [11 x i8] c"bind error\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @htons(i32 8081)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %12, i32* %13
%14 = call i64 @bind(i32 %5, %struct.sockaddr_in* %1, i32 12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = call i64 @listen(i32 %5, i32 16)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = bitcast i32* %2 to i8*
br label %25
25: ; preds = %32, %23
store i32 12, i32* %2
%26 = call i32 @accept(i32 %5, %struct.sockaddr_in* %1, i32* %2)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%30 = call i32 @strlen(i8* getelementptr inbounds ([246 x i8], [246 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @send(i32 %26, i8* getelementptr inbounds ([246 x i8], [246 x i8]* @.str, i64 0, i64 0), i32 %30, i32 0)
br label %32
32: ; preds = %28, %25
br label %25
}