#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sendAll(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
void sendError(int errorCode, int dest, char *buffer) {
  memset(buffer, 0, sizeof(buffer));
  switch (errorCode) {
  case 400:
    strcat(buffer, "HTTP/1.0 400 - Bad Request\r\n\r\n");
    break;
  case 404:
    strcat(buffer, "HTTP/1.0 404 - File Not Found\r\n\r\n");
    break;
  case 413:
    strcat(buffer, "HTTP/1.0 413 - Request Entity Too Large!\r\n\r\n");
    break;
  case 501:
    strcat(buffer, "HTTP/1.0 501 - Not Implemented\r\n\r\n");
    break;
  default:
    fprintf(stderr, "Unknown error code %d!\n", errorCode);
  }
  sendAll(dest, buffer, strlen(buffer));
}


x86 assembly (clang, -O0):
<sendError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x190,%eax
je     11c1 <sendError+0x71>
jmp    1188 <sendError+0x38>
mov    -0x14(%rbp),%eax
sub    $0x194,%eax
je     11d6 <sendError+0x86>
jmp    119b <sendError+0x4b>
mov    -0x14(%rbp),%eax
sub    $0x19d,%eax
je     11eb <sendError+0x9b>
jmp    11ae <sendError+0x5e>
mov    -0x14(%rbp),%eax
sub    $0x1f5,%eax
je     1200 <sendError+0xb0>
jmp    1215 <sendError+0xc5>
mov    -0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1070 <strcat@plt>
jmp    122d <sendError+0xdd>
mov    -0x10(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1070 <strcat@plt>
jmp    122d <sendError+0xdd>
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1070 <strcat@plt>
jmp    122d <sendError+0xdd>
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1070 <strcat@plt>
jmp    122d <sendError+0xdd>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1060 <sendAll@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendError>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rdx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
cmp    $0x19c,%ebp
jg     118c <sendError+0x3c>
cmp    $0x190,%ebp
je     11be <sendError+0x6e>
cmp    $0x194,%ebp
jne    11a5 <sendError+0x55>
lea    0xe95(%rip),%rsi
jmp    11ce <sendError+0x7e>
cmp    $0x19d,%ebp
je     11c7 <sendError+0x77>
cmp    $0x1f5,%ebp
jne    11a5 <sendError+0x55>
lea    0xecb(%rip),%rsi
jmp    11ce <sendError+0x7e>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xedc(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
jmp    11d6 <sendError+0x86>
lea    0xe3b(%rip),%rsi
jmp    11ce <sendError+0x7e>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <sendAll@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"HTTP/1.0 400 - Bad Request\0D\0A\0D\0A\00"
@.str.1 = [34 x i8] c"HTTP/1.0 404 - File Not Found\0D\0A\0D\0A\00"
@.str.2 = [45 x i8] c"HTTP/1.0 413 - Request Entity Too Large!\0D\0A\0D\0A\00"
@.str.3 = [35 x i8] c"HTTP/1.0 501 - Not Implemented\0D\0A\0D\0A\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Unknown error code %d!\0A\00"
define void @sendError(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i8*, i8** %6
%8 = call i32 @memset(i8* %7, i32 0, i32 8)
%9 = load i32, i32* %4
switch i32 %9, label %22 [
i32 400, label %10
i32 404, label %13
i32 413, label %16
i32 501, label %19
]
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %26
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %26
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %26
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %26
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = load i32, i32* %4
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %19, %16, %13, %10
%27 = load i32, i32* %5
%28 = load i8*, i8** %6
%29 = load i8*, i8** %6
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @sendAll(i32 %27, i8* %28, i32 %30)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"HTTP/1.0 400 - Bad Request\0D\0A\0D\0A\00"
@.str.1 = [34 x i8] c"HTTP/1.0 404 - File Not Found\0D\0A\0D\0A\00"
@.str.2 = [45 x i8] c"HTTP/1.0 413 - Request Entity Too Large!\0D\0A\0D\0A\00"
@.str.3 = [35 x i8] c"HTTP/1.0 501 - Not Implemented\0D\0A\0D\0A\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Unknown error code %d!\0A\00"
define void @sendError(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @memset(i8* %2, i32 0, i32 8)
switch i32 %0, label %13 [
i32 400, label %5
i32 404, label %7
i32 413, label %9
i32 501, label %11
]
5: ; preds = %3
%6 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %16
7: ; preds = %3
%8 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %3
%10 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %16
11: ; preds = %3
%12 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %16
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %16
16: ; preds = %13, %11, %9, %7, %5
%17 = tail call i32 @strlen(i8* %2)
%18 = tail call i32 @sendAll(i32 %1, i8* %2, i32 %17)
ret void
}