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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write_socket(int, char *, int /*<<< orphan*/);
void ok(int client_sockfd, char *body) {
  char buffer[8096];
  sprintf(buffer, "HTTP/1.1 200 OK\r\n");
  write_socket(client_sockfd, buffer, strlen(buffer));
  sprintf(buffer, "Server: httpServer/0.1.1\r\n");
  write_socket(client_sockfd, buffer, strlen(buffer));
  sprintf(buffer, "Content-Type: text/html\r\n");
  write_socket(client_sockfd, buffer, strlen(buffer));
  sprintf(buffer, "Content-Length: %ld\r\n", strlen(body));
  write_socket(client_sockfd, buffer, strlen(buffer));
  write_socket(client_sockfd, "\r\n", strlen("\r\n"));
  write_socket(client_sockfd, body, strlen(body));
  free(body);
}


x86 assembly (clang, -O0):
<ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2010,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1fb0(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2004(%rbp)
lea    -0x1fb0(%rbp),%rax
mov    %rax,-0x2000(%rbp)
lea    -0x1fb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2004(%rbp),%edi
mov    -0x2000(%rbp),%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
lea    -0x1fb0(%rbp),%rdi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1ff4(%rbp)
lea    -0x1fb0(%rbp),%rax
mov    %rax,-0x1ff0(%rbp)
lea    -0x1fb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1ff4(%rbp),%edi
mov    -0x1ff0(%rbp),%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
lea    -0x1fb0(%rbp),%rdi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1fe4(%rbp)
lea    -0x1fb0(%rbp),%rax
mov    %rax,-0x1fe0(%rbp)
lea    -0x1fb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1fe4(%rbp),%edi
mov    -0x1fe0(%rbp),%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
lea    -0x1fb0(%rbp),%rax
mov    %rax,-0x1fd8(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1fd8(%rbp),%rdi
mov    %eax,%edx
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1fcc(%rbp)
lea    -0x1fb0(%rbp),%rax
mov    %rax,-0x1fc8(%rbp)
lea    -0x1fb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1fcc(%rbp),%edi
mov    -0x1fc8(%rbp),%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1fc0(%rbp)
lea    0xd7f(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x1fc0(%rbp),%edi
mov    %eax,%edx
lea    0xd6b(%rip),%rsi
call   1040 <write_socket@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1fbc(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1fb8(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1fbc(%rbp),%edi
mov    -0x1fb8(%rbp),%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x2010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ok>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1fa0,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movups 0xea9(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0xa,0x10(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
movups 0xe92(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xe92(%rip),%xmm0
movups %xmm0,0xb(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
movups 0xe82(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xe81(%rip),%xmm0
movups %xmm0,0xa(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
lea    0xe25(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write_socket@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x1fa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.1 = [27 x i8] c"Server: httpServer/0.1.1\0D\0A\00"
@.str.2 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.3 = [22 x i8] c"Content-Length: %ld\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @ok(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [8096 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @write_socket(i32 %8, i8* %9, i32 %11)
%13 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @write_socket(i32 %15, i8* %16, i32 %18)
%20 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write_socket(i32 %22, i8* %23, i32 %25)
%27 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %3
%32 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%33 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @write_socket(i32 %31, i8* %32, i32 %34)
%36 = load i32, i32* %3
%37 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @write_socket(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %3
%40 = load i8*, i8** %4
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
%43 = call i32 @write_socket(i32 %39, i8* %40, i32 %42)
%44 = load i8*, i8** %4
%45 = call i32 @free(i8* %44)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.1 = [27 x i8] c"Server: httpServer/0.1.1\0D\0A\00"
@.str.2 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.3 = [22 x i8] c"Content-Length: %ld\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @ok(i32 %0, i8* %1) {
%3 = alloca [8096 x i8]
%4 = getelementptr inbounds [8096 x i8], [8096 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = call i32 @write_socket(i32 %0, i8* %4, i32 %5)
%7 = call i32 @strlen(i8* %4)
%8 = call i32 @write_socket(i32 %0, i8* %4, i32 %7)
%9 = call i32 @strlen(i8* %4)
%10 = call i32 @write_socket(i32 %0, i8* %4, i32 %9)
%11 = call i32 @strlen(i8* %1)
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = call i32 @strlen(i8* %4)
%14 = call i32 @write_socket(i32 %0, i8* %4, i32 %13)
%15 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @write_socket(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%17 = call i32 @strlen(i8* %1)
%18 = call i32 @write_socket(i32 %0, i8* %1, i32 %17)
%19 = call i32 @free(i8* %1)
ret void
}