#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 *, int);
int strlen(char *);
void send_response_404(int sockethandle) {
  char *errormsg = "<body><h1>404 - Not Found</h1></body>";
  char *errortemplate =
      "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: "
      "%d\r\nConnection: close\r\n";
  char *errorheader = malloc(strlen(errormsg) + strlen(errortemplate) + 1);
  sprintf(errorheader, errortemplate, strlen(errormsg));
  send(sockethandle, errorheader, strlen(errorheader), 0);
  send(sockethandle, "\r\n", 2, 0);
  send(sockethandle, errormsg, strlen(errormsg), 0);
  send(sockethandle, "\r\n", 2, 0);
  free(errorheader);
}


x86 assembly (clang, -O0):
<send_response_404>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%edi
lea    0xe8c(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%edi
lea    0xe4f(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response_404>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xea0(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xeb5(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xec3(%rip),%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2,%edx
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 = [38 x i8] c"<body><h1>404 - Not Found</h1></body>\00"
@.str.1 = [89 x i8] c"HTTP/1.1 404 Not Found\0D\0AContent-Type: text/html\0D\0AContent-Length: %d\0D\0AConnection: close\0D\0A\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define void @send_response_404(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %2
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.1, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %7, %9
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @sprintf(i8* %13, i8* %14, i32 %16)
%18 = load i32, i32* %2
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @send(i32 %18, i8* %19, i32 %21, i32 0)
%23 = load i32, i32* %2
%24 = call i32 @send(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 0)
%25 = load i32, i32* %2
%26 = load i8*, i8** %3
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @send(i32 %25, i8* %26, i32 %28, i32 0)
%30 = load i32, i32* %2
%31 = call i32 @send(i32 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 0)
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"<body><h1>404 - Not Found</h1></body>\00"
@.str.1 = [89 x i8] c"HTTP/1.1 404 Not Found\0D\0AContent-Type: text/html\0D\0AContent-Length: %d\0D\0AConnection: close\0D\0A\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define void @send_response_404(i32 %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.1, i64 0, i64 0))
%4 = add i32 %2, 1
%5 = add i32 %4, %3
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @strlen(i8* %6)
%10 = tail call i32 @send(i32 %0, i8* %6, i32 %9, i32 0)
%11 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 0)
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %12, i32 0)
%14 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 0)
%15 = tail call i32 @free(i8* %6)
ret void
}