#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 */

/* Type definitions */
struct sockaddr_in {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ createHTMLCode(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ perror;
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
void serverTCP(int s, struct sockaddr_in clientaddr_in) {
  int len;
  char buffer[65536], sendBuffer[65536];
  len = recv(s, buffer, 65536, 0);
  if (len == -1)
    perror;
  if (len == 0)
    return;
  memset(buffer, '\0', sizeof(buffer));
  createHTMLCode(buffer);
  sprintf(sendBuffer,
          "HTTP/1.1 200 OK\nServer: RPmonitor\nContent-Type: text/html; "
          "charset=utf-8\nConnection: close\nContent-Length: %d\n\n\n\n%s",
          (int)strlen(buffer), buffer);
  if (send(s, sendBuffer, strlen(sendBuffer), 0) != strlen(sendBuffer))
    fprintf(stderr, "Error when sending the html code");
}


x86 assembly (clang, -O0):
<serverTCP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20030,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11a4 <serverTCP+0x34>
cmpl   $0x0,-0x10(%rbp)
jne    11b3 <serverTCP+0x43>
jmp    127d <serverTCP+0x10d>
lea    -0x10010(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1060 <memset@plt>
lea    -0x10010(%rbp),%rdi
call   1090 <createHTMLCode@plt>
lea    -0x20010(%rbp),%rax
mov    %rax,-0x20030(%rbp)
lea    -0x10010(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20030(%rbp),%rdi
mov    %eax,%edx
lea    -0x10010(%rbp),%rcx
lea    0xdfd(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20024(%rbp)
lea    -0x20010(%rbp),%rax
mov    %rax,-0x20020(%rbp)
lea    -0x20010(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20024(%rbp),%edi
mov    -0x20020(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x20018(%rbp)
lea    -0x20010(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20018(%rbp),%rax
cmp    %rcx,%rax
je     127d <serverTCP+0x10d>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
call   1070 <fprintf@plt>
add    $0x20030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serverTCP>:
push   %r15
push   %r14
push   %rbx
sub    $0x20000,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     120b <serverTCP+0x9b>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
call   1090 <createHTMLCode@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe46(%rip),%rsi
lea    0x10000(%rsp),%r15
mov    %r15,%rdi
mov    %eax,%edx
mov    %r14,%rcx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
je     120b <serverTCP+0x9b>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1070 <fprintf@plt>
add    $0x20000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@perror = global i32 0
@.str = [116 x i8] c"HTTP/1.1 200 OK\0AServer: RPmonitor\0AContent-Type: text/html; charset=utf-8\0AConnection: close\0AContent-Length: %d\0A\0A\0A\0A%s\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Error when sending the html code\00"
define void @serverTCP(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca [65536 x i8]
%7 = alloca [65536 x i8]
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %1, i32* %8
store i32 %0, i32* %4
%9 = load i32, i32* %4
%10 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%11 = call i32 @recv(i32 %9, i8* %10, i32 65536, i32 0)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @perror
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
br label %42
20: ; preds = %16
%21 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i8 signext 0, i32 65536)
%23 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%24 = call i32 @createHTMLCode(i8* %23)
%25 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%27 = call i64 @strlen(i8* %26)
%28 = trunc i64 %27 to i32
%29 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%30 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str, i64 0, i64 0), i32 %28, i8* %29)
%31 = load i32, i32* %4
%32 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%34 = call i64 @strlen(i8* %33)
%35 = call i64 @send(i32 %31, i8* %32, i64 %34, i32 0)
%36 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%37 = call i64 @strlen(i8* %36)
%38 = icmp ne i64 %35, %37
br i1 %38, label %39, label %42
39: ; preds = %20
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %19, %39, %20
ret void
}

LLVM IR (-O2):
@perror = global i32 0
@.str = [116 x i8] c"HTTP/1.1 200 OK\0AServer: RPmonitor\0AContent-Type: text/html; charset=utf-8\0AConnection: close\0AContent-Length: %d\0A\0A\0A\0A%s\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Error when sending the html code\00"
define void @serverTCP(i32 %0, i32 %1) {
%3 = alloca [65536 x i8]
%4 = alloca [65536 x i8]
%5 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%7 = call i32 @recv(i32 %0, i8* %5, i32 65536, i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %2
%10 = call i32 @memset(i8* %5, i8 signext 0, i32 65536)
%11 = call i32 @createHTMLCode(i8* %5)
%12 = call i64 @strlen(i8* %5)
%13 = trunc i64 %12 to i32
%14 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([116 x i8], [116 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %5)
%15 = call i64 @strlen(i8* %6)
%16 = call i64 @send(i32 %0, i8* %6, i64 %15, i32 0)
%17 = call i64 @strlen(i8* %6)
%18 = icmp eq i64 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %9
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %9, %19, %2
ret void
}