#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 *safe_malloc(int);
int /*<<< orphan*/ server_error(int, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void client_404(int sock) {
  char *buf = safe_malloc(256);
  strcpy(buf, "HTTP/1.1 404 Not Found\r\n");
  strcat(buf, "<HTML><HEAD><TITLE>HTTP ERROR 404</TITLE></HEAD><BODY>");
  strcat(buf, "404 Not Found.  Your request could not be completed due to");
  strcat(buf, " encountering HTTP error number 404.</BODY></HTML>");
  strcat(buf, "\r\n");
  if ((write(sock, buf, strlen(buf)) < 0)) {
    free(buf);
    server_error(sock, "writing 404 to client");
  }
  free(buf);
}


x86 assembly (clang, -O0):
<client_404>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x100,%edi
call   1050 <safe_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xec7(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1060 <write@plt>
cmp    $0x0,%rax
jge    1220 <client_404+0xb0>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
lea    0xea3(%rip),%rsi
call   1080 <server_error@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_404>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x100,%edi
call   1050 <safe_malloc@plt>
mov    %rax,%rbx
lea    0xe77(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xed5(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
test   %rax,%rax
jns    11fc <client_404+0x8c>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xec9(%rip),%rsi
mov    %ebp,%edi
call   1080 <server_error@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"HTTP/1.1 404 Not Found\0D\0A\00"
@.str.1 = [55 x i8] c"<HTML><HEAD><TITLE>HTTP ERROR 404</TITLE></HEAD><BODY>\00"
@.str.2 = [59 x i8] c"404 Not Found. Your request could not be completed due to\00"
@.str.3 = [51 x i8] c" encountering HTTP error number 404.</BODY></HTML>\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@.str.5 = [22 x i8] c"writing 404 to client\00"
define void @client_404(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @safe_malloc(i32 256)
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%11 = load i8*, i8** %3
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%13 = load i8*, i8** %3
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = load i8*, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = call i64 @write(i32 %15, i8* %16, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %1
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %2
%25 = call i32 @server_error(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %21, %1
%27 = load i8*, i8** %3
%28 = call i32 @free(i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"HTTP/1.1 404 Not Found\0D\0A\00"
@.str.1 = [55 x i8] c"<HTML><HEAD><TITLE>HTTP ERROR 404</TITLE></HEAD><BODY>\00"
@.str.2 = [59 x i8] c"404 Not Found. Your request could not be completed due to\00"
@.str.3 = [51 x i8] c" encountering HTTP error number 404.</BODY></HTML>\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@.str.5 = [22 x i8] c"writing 404 to client\00"
define void @client_404(i32 %0) {
%2 = tail call i8* @safe_malloc(i32 256)
%3 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 @strlen(i8* %2)
%9 = tail call i64 @write(i32 %0, i8* %2, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = tail call i32 @free(i8* %2)
%13 = tail call i32 @server_error(i32 %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %11, %1
%15 = tail call i32 @free(i8* %2)
ret void
}