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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  printf("Server starting ...\n");
  int create_socket;
  int new_socket;
  socklen_t addrlen;
  int buffer_size = 1024;
  char *buffer = malloc(buffer_size);
  struct sockaddr_in address;
  if ((create_socket = socket(AF_INET, SOCK_STREAM, 0)) > 0) {
    printf("The socket was created \n");
  }
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = INADDR_ANY;
  address.sin_port = htons(5000);
  if (bind(create_socket, (struct sockaddr *)&address, sizeof(address)) == 0) {
    printf("Binding Socket\n");
  }
  while (1) {
    if (listen(create_socket, 10) < 0) {
      perror("server: listen");
      exit(1);
    }
    if ((new_socket = accept(create_socket, (struct sockaddr *)&address,
                             &addrlen)) < 0) {
      perror("server: accept");
      exit(1);
    }
    if (new_socket > 0) {
      printf("The Client is connected ... \n");
    }
    recv(new_socket, buffer, buffer_size, 0);
    printf("%s \n", buffer);
    write(new_socket, "HTTP/1.1 200 OK\n", 16);
    write(new_socket, "Content-length: 55\n", 19);
    write(new_socket, "Content-Type: text/html\n\n", 25);
    write(new_socket, "<html><body><H1>RPi Msg: Hello world</H1></body></html>",
          55);
  }
  close(create_socket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x400,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1213 <main+0x63>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x1388,%edi
call   1050 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jne    1261 <main+0xb1>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1266 <main+0xb6>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    1293 <main+0xe3>
lea    0xdba(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    12c5 <main+0x115>
lea    0xd97(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jle    12dd <main+0x12d>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x20(%rbp),%rsi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
lea    0xd75(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xd72(%rip),%rsi
mov    $0x13,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xd72(%rip),%rsi
mov    $0x19,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xd78(%rip),%rsi
mov    $0x37,%edx
call   1040 <write@plt>
jmp    1266 <main+0xb6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x2dfa(%rip),%r14
mov    (%r14),%edi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1213 <main+0x53>
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x1388,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jne    1257 <main+0x97>
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    $0xa,%esi
call   1090 <listen@plt>
test   %rax,%rax
jns    1274 <main+0xb4>
lea    0xd91(%rip),%rdi
jmp    1342 <main+0x182>
lea    0xdb9(%rip),%r14
lea    0xdc6(%rip),%r15
lea    0xdd9(%rip),%r12
jmp    130c <main+0x14c>
xchg   %ax,%ax
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xd75(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%edi
lea    0xd66(%rip),%rsi
mov    $0x10,%edx
call   1050 <write@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x13,%edx
call   1050 <write@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x19,%edx
call   1050 <write@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x37,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    $0xa,%esi
call   1090 <listen@plt>
test   %rax,%rax
js     1268 <main+0xa8>
mov    %ebp,%edi
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   10c0 <accept@plt>
test   %eax,%eax
js     133b <main+0x17b>
mov    %eax,%r13d
je     1290 <main+0xd0>
lea    0xd7d(%rip),%rdi
call   1040 <puts@plt>
jmp    1290 <main+0xd0>
lea    0xccd(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Server starting ...\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [25 x i8] c"The socket was created \0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [16 x i8] c"Binding Socket\0A\00"
@.str.3 = [15 x i8] c"server: listen\00"
@.str.4 = [15 x i8] c"server: accept\00"
@.str.5 = [30 x i8] c"The Client is connected ... \0A\00"
@.str.6 = [5 x i8] c"%s \0A\00"
@.str.7 = [17 x i8] c"HTTP/1.1 200 OK\0A\00"
@.str.8 = [20 x i8] c"Content-length: 55\0A\00"
@.str.9 = [26 x i8] c"Content-Type: text/html\0A\0A\00"
@.str.10 = [56 x i8] c"<html><body><H1>RPi Msg: Hello world</H1></body></html>\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1024, i32* %5
%9 = load i32, i32* %5
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %6
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = call i32 @htons(i32 5000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%27 = call i64 @bind(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %17
br label %32
32: ; preds = %31, %52
%33 = load i32, i32* %2
%34 = call i64 @listen(i32 %33, i32 10)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32
%40 = load i32, i32* %2
%41 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%42 = call i32 @accept(i32 %40, %struct.sockaddr* %41, i32* %4)
store i32 %42, i32* %3
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
%48 = load i32, i32* %3
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
%53 = load i32, i32* %3
%54 = load i8*, i8** %6
%55 = load i32, i32* %5
%56 = call i32 @recv(i32 %53, i8* %54, i32 %55, i32 0)
%57 = load i8*, i8** %6
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %57)
%59 = load i32, i32* %3
%60 = call i32 @write(i32 %59, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 16)
%61 = load i32, i32* %3
%62 = call i32 @write(i32 %61, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 19)
%63 = load i32, i32* %3
%64 = call i32 @write(i32 %63, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 25)
%65 = load i32, i32* %3
%66 = call i32 @write(i32 %65, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.10, i64 0, i64 0), i32 55)
br label %32
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.3 = [15 x i8] c"server: listen\00"
@.str.4 = [15 x i8] c"server: accept\00"
@.str.6 = [5 x i8] c"%s \0A\00"
@.str.7 = [17 x i8] c"HTTP/1.1 200 OK\0A\00"
@.str.8 = [20 x i8] c"Content-length: 55\0A\00"
@.str.9 = [26 x i8] c"Content-Type: text/html\0A\0A\00"
@.str.10 = [56 x i8] c"<html><body><H1>RPi Msg: Hello world</H1></body></html>\00"
@str = [20 x i8] c"Server starting ...\00"
@str.11 = [29 x i8] c"The Client is connected ... \00"
@str.12 = [15 x i8] c"Binding Socket\00"
@str.13 = [24 x i8] c"The socket was created \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.13, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 5000)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%21 = call i64 @bind(i32 %9, %struct.sockaddr* %20, i32 12)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
br label %25
25: ; preds = %23, %13
%26 = call i64 @listen(i32 %9, i32 10)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %41, %25
%29 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25, %41
%32 = call i32 @accept(i32 %9, %struct.sockaddr* %20, i32* %1)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %31
%38 = icmp eq i32 %32, 0
br i1 %38, label %41, label %39
39: ; preds = %37
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.11, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
%42 = call i32 @recv(i32 %32, i8* %5, i32 1024, i32 0)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%44 = call i32 @write(i32 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 16)
%45 = call i32 @write(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 19)
%46 = call i32 @write(i32 %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 25)
%47 = call i32 @write(i32 %32, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.10, i64 0, i64 0), i32 55)
%48 = call i64 @listen(i32 %9, i32 10)
%49 = icmp slt i64 %48, 0
br i1 %49, label %28, label %31
}