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


x86 assembly (clang, -O0):
<send_response_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xee6(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe8c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    %rax,%rdx
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response_msg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
lea    0x52(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xeaa(%rip),%rbp
mov    $0x2,%edx
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    $0x2,%edx
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

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