#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*/ error(char *);
char *make_http_response(char *, char *, char *);
size_t strlen(char *);
int write(int, char *, size_t);
void respond_404(int newsockfd) {
  char *status_code = "404";
  char *reason = "File not found";
  char *message = "<h1>404</h1><p>Request file not found</p>";
  char *response = make_http_response(status_code, reason, message);
  size_t length = strlen(response);
  int written = write(newsockfd, response, length);
  if (written < 0)
    error("ERROR WRITING TO CLIENT");
}


x86 assembly (clang, -O0):
<respond_404>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <make_http_response@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11b7 <respond_404+0x77>
lea    0xe8b(%rip),%rdi
call   1060 <error@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<respond_404>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeb4(%rip),%rdi
lea    0xeb1(%rip),%rsi
lea    0xeb9(%rip),%rdx
call   1030 <make_http_response@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
test   %eax,%eax
js     1182 <respond_404+0x42>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeb4(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <error@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"404\00"
@.str.1 = [15 x i8] c"File not found\00"
@.str.2 = [42 x i8] c"<h1>404</h1><p>Request file not found</p>\00"
@.str.3 = [24 x i8] c"ERROR WRITING TO CLIENT\00"
define void @respond_404(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8** %5
%9 = load i8*, i8** %3
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i8* @make_http_response(i8* %9, i8* %10, i8* %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %7
%15 = load i32, i32* %2
%16 = load i8*, i8** %6
%17 = load i64, i64* %7
%18 = call i32 @write(i32 %15, i8* %16, i64 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %1
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"404\00"
@.str.1 = [15 x i8] c"File not found\00"
@.str.2 = [42 x i8] c"<h1>404</h1><p>Request file not found</p>\00"
@.str.3 = [24 x i8] c"ERROR WRITING TO CLIENT\00"
define void @respond_404(i32 %0) {
%2 = tail call i8* @make_http_response(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%3 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%4 = tail call i32 @write(i32 %0, i8* %2, i64 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
ret void
}