#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*/ res_data;

/* Variables and functions */
int send_response(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *);
scalar_t__ strlen(char *);
int send_error_response(int fd, int errID) {
  int ret = 0;
  char res_data[1024] = {0};
  switch (errID) {
  case -404:
    snprintf(res_data, sizeof(res_data), "404 Not Found");
    break;
  case -400:
    snprintf(res_data, sizeof(res_data), "400 Bad Request");
    break;
  case -500:
    snprintf(res_data, sizeof(res_data), "500 Internal Server Error");
    break;
  case -501:
    snprintf(res_data, sizeof(res_data), "501 Not Implemented");
    break;
  default:
    snprintf(res_data, sizeof(res_data), "400 Bad Request");
    break;
  }
  ret = send_response(fd, res_data, strlen(res_data) + 1, 0);
  return ret;
}


x86 assembly (clang, -O0):
<send_error_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x414(%rbp)
sub    $0xfffffe0b,%eax
je     121d <send_error_response+0xdd>
jmp    1184 <send_error_response+0x44>
mov    -0x414(%rbp),%eax
sub    $0xfffffe0c,%eax
je     1200 <send_error_response+0xc0>
jmp    119a <send_error_response+0x5a>
mov    -0x414(%rbp),%eax
sub    $0xfffffe6c,%eax
je     11c6 <send_error_response+0x86>
jmp    11b0 <send_error_response+0x70>
mov    -0x414(%rbp),%eax
sub    $0xfffffe70,%eax
je     11e3 <send_error_response+0xa3>
jmp    123a <send_error_response+0xfa>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
lea    0xe27(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1252 <send_error_response+0x112>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
lea    0xe18(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1252 <send_error_response+0x112>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
lea    0xe0b(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1252 <send_error_response+0x112>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
lea    0xe08(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1252 <send_error_response+0x112>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
lea    0xdc1(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x424(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x424(%rbp),%edi
mov    -0x420(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1030 <send_response@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_error_response>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
cmp    $0xfffffe6b,%ebp
jg     117d <send_error_response+0x3d>
cmp    $0xfffffe0b,%ebp
je     1194 <send_error_response+0x54>
cmp    $0xfffffe0c,%ebp
jne    118b <send_error_response+0x4b>
lea    0xea3(%rip),%rdx
jmp    11a4 <send_error_response+0x64>
cmp    $0xfffffe6c,%ebp
je     119d <send_error_response+0x5d>
cmp    $0xfffffe70,%ebp
lea    0xe7c(%rip),%rdx
jmp    11a4 <send_error_response+0x64>
lea    0xe9d(%rip),%rdx
jmp    11a4 <send_error_response+0x64>
lea    0xe5c(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1030 <send_response@plt>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"404 Not Found\00"
@.str.1 = [16 x i8] c"400 Bad Request\00"
@.str.2 = [26 x i8] c"500 Internal Server Error\00"
@.str.3 = [20 x i8] c"501 Not Implemented\00"
define i32 @send_error_response(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = bitcast [1024 x i8]* %6 to i8*
%8 = load i32, i32* %4
switch i32 %8, label %21 [
i32 -404, label %9
i32 -400, label %12
i32 -500, label %15
i32 -501, label %18
]
9: ; preds = %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %24
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = call i32 @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %24
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = call i32 @snprintf(i8* %16, i32 1024, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %24
18: ; preds = %2
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i32 @snprintf(i8* %19, i32 1024, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %24
21: ; preds = %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @snprintf(i8* %22, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %18, %15, %12, %9
%25 = load i32, i32* %3
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @send_response(i32 %25, i8* %26, i64 %29, i32 0)
store i32 %30, i32* %5
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@.str = [14 x i8] c"404 Not Found\00"
@.str.1 = [16 x i8] c"400 Bad Request\00"
@.str.2 = [26 x i8] c"500 Internal Server Error\00"
@.str.3 = [20 x i8] c"501 Not Implemented\00"
define i32 @send_error_response(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
switch i32 %1, label %8 [
i32 -404, label %9
i32 -400, label %5
i32 -500, label %6
i32 -501, label %7
]
5: ; preds = %2
br label %9
6: ; preds = %2
br label %9
7: ; preds = %2
br label %9
8: ; preds = %2
br label %9
9: ; preds = %2, %8, %7, %6, %5
%10 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = call i32 @snprintf(i8* %4, i32 1024, i8* %10)
%12 = call i64 @strlen(i8* %4)
%13 = add nsw i64 %12, 1
%14 = call i32 @send_response(i32 %0, i8* %4, i64 %13, i32 0)
ret i32 %14
}