#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 */
char *getStatusCodeName(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ writeBasicResponse(int, int, char *, char *, int);
void writeError(int socket, int statusCode) {
  printf("Sending a HTTP %d error response.\n", statusCode);
  char responseBody[(1024 * 2) + 2];
  char *statusCodeName = getStatusCodeName(statusCode);
  sprintf(responseBody,
          "<!DOCTYPE html>\n<html lang=\"en\">\n<head><title>Error - "
          "%s</title></head>\n<body><h1>Error %d</h1><p>%s</p></body>\n</html>",
          statusCodeName, statusCode, statusCodeName);
  writeBasicResponse(socket, statusCode, responseBody, "text/html",
                     (int)strlen(responseBody));
}


x86 assembly (clang, -O0):
<writeError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe95(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <getStatusCodeName@plt>
mov    %rax,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0x818(%rbp),%r8
lea    0xe85(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x828(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x824(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x820(%rbp)
lea    -0x810(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x828(%rbp),%edi
mov    -0x824(%rbp),%esi
mov    -0x820(%rbp),%rdx
mov    %eax,%r8d
lea    0xeaf(%rip),%rcx
call   1040 <writeBasicResponse@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeError>:
push   %rbp
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
lea    0xe99(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <getStatusCodeName@plt>
lea    0xea9(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rax,%rdx
mov    %ebx,%ecx
mov    %rax,%r8
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0xeff(%rip),%rcx
mov    %r14d,%edi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %eax,%r8d
call   1040 <writeBasicResponse@plt>
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Sending a HTTP %d error response.\0A\00"
@.str.1 = [120 x i8] c"<!DOCTYPE html>\0A<html lang=\22en\22>\0A<head><title>Error - %s</title></head>\0A<body><h1>Error %d</h1><p>%s</p></body>\0A</html>\00"
@.str.2 = [10 x i8] c"text/html\00"
define void @writeError(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2050 x i8]
%6 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %4
%10 = call i8* @getStatusCodeName(i32 %9)
store i8* %10, i8** %6
%11 = getelementptr inbounds [2050 x i8], [2050 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = load i32, i32* %4
%14 = load i8*, i8** %6
%15 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %13, i8* %14)
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = getelementptr inbounds [2050 x i8], [2050 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [2050 x i8], [2050 x i8]* %5, i64 0, i64 0
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
%22 = call i32 @writeBasicResponse(i32 %16, i32 %17, i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"Sending a HTTP %d error response.\0A\00"
@.str.1 = [120 x i8] c"<!DOCTYPE html>\0A<html lang=\22en\22>\0A<head><title>Error - %s</title></head>\0A<body><h1>Error %d</h1><p>%s</p></body>\0A</html>\00"
@.str.2 = [10 x i8] c"text/html\00"
define void @writeError(i32 %0, i32 %1) {
%3 = alloca [2050 x i8]
%4 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = getelementptr inbounds [2050 x i8], [2050 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @getStatusCodeName(i32 %1)
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([120 x i8], [120 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %1, i8* %6)
%8 = call i64 @strlen(i8* %5)
%9 = trunc i64 %8 to i32
%10 = call i32 @writeBasicResponse(i32 %0, i32 %1, i8* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %9)
ret void
}