#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 *);
char *malloc(int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int strlen(char *);
void send_response_ok(int sockethandle, char *contenttype, int contentlength) {
  char *headertemplate = "HTTP/1.1 200 OK\r\nContent-Type: "
                         "%s\r\nContent-Length: %d\r\nConnection: close\r\n";
  char *header = malloc(strlen(headertemplate) + strlen(contenttype) + 1);
  sprintf(header, headertemplate, contenttype, contentlength);
  send(sockethandle, header, strlen(header), 0);
  send(sockethandle, "\r\n", 2, 0);
  free(header);
}


x86 assembly (clang, -O0):
<send_response_ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%edi
lea    0xe70(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response_ok>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%r12d
lea    0xe98(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xe91(%rip),%rsi
mov    %r12d,%edi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [75 x i8] c"HTTP/1.1 200 OK\0D\0AContent-Type: %s\0D\0AContent-Length: %d\0D\0AConnection: close\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @send_response_ok(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %7
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 1
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = call i32 @sprintf(i8* %16, i8* %17, i8* %18, i32 %19)
%21 = load i32, i32* %4
%22 = load i8*, i8** %8
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @send(i32 %21, i8* %22, i32 %24, i32 0)
%26 = load i32, i32* %4
%27 = call i32 @send(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 0)
%28 = load i8*, i8** %8
%29 = call i32 @free(i8* %28)
ret void
}

LLVM IR (-O2):
@.str = [75 x i8] c"HTTP/1.1 200 OK\0D\0AContent-Type: %s\0D\0AContent-Length: %d\0D\0AConnection: close\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @send_response_ok(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 1
%7 = add i32 %6, %5
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2)
%10 = tail call i32 @strlen(i8* %8)
%11 = tail call i32 @send(i32 %0, i8* %8, i32 %10, i32 0)
%12 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 0)
%13 = tail call i32 @free(i8* %8)
ret void
}