#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*/ fsync(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void send_error(int fd, int which, char *message) {
  char buffer[2048] = {0};
  if (which == 401) {
    sprintf(buffer,
            "HTTP/1.0 401 Unauthorized\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: MJPG-Streamer/0.2\r\n"
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, "
            "post-check=0, max-age=0\r\n"
            "Pragma: no-cache\r\n"
            "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
            "WWW-Authenticate: Basic realm=\"MJPG-Streamer\"\r\n"
            "\r\n"
            "401: Not Authenticated!\r\n"
            "%s",
            message);
  } else if (which == 404) {
    sprintf(buffer,
            "HTTP/1.0 404 Not Found\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: MJPG-Streamer/0.2\r\n"
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, "
            "post-check=0, max-age=0\r\n"
            "Pragma: no-cache\r\n"
            "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
            "\r\n"
            "404: Not Found!\r\n"
            "%s",
            message);
  } else if (which == 500) {
    sprintf(buffer,
            "HTTP/1.0 500 Internal Server Error\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: MJPG-Streamer/0.2\r\n"
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, "
            "post-check=0, max-age=0\r\n"
            "Pragma: no-cache\r\n"
            "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
            "\r\n"
            "500: Internal Server Error!\r\n"
            "%s",
            message);
  } else if (which == 400) {
    sprintf(buffer,
            "HTTP/1.0 400 Bad Request\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: MJPG-Streamer/0.2\r\n"
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, "
            "post-check=0, max-age=0\r\n"
            "Pragma: no-cache\r\n"
            "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
            "\r\n"
            "400: Not Found!\r\n"
            "%s",
            message);
  } else if (which == 601) {
    sprintf(buffer,
            "HTTP/1.0 601 Remote Authen Fail\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: MJPG-Streamer/0.2\r\n"
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, "
            "post-check=0, max-age=0\r\n"
            "Pragma: no-cache\r\n"
            "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
            "\r\n"
            "601: Remote Authen Fail!\r\n"
            "%s",
            message);
  } else {
    sprintf(buffer,
            "HTTP/1.0 %d Error\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: MJPG-Streamer/0.2\r\n"
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, "
            "post-check=0, max-age=0\r\n"
            "Pragma: no-cache\r\n"
            "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
            "\r\n"
            "501: Not Implemented!\r\n"
            "%s",
            which, message);
  }
  write(fd, buffer, strlen(buffer));
  fsync(fd);
}


x86 assembly (clang, -O0):
<send_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
cmpl   $0x191,-0x8(%rbp)
jne    11a3 <send_error+0x53>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    127f <send_error+0x12f>
cmpl   $0x194,-0x8(%rbp)
jne    11ce <send_error+0x7e>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xf81(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    127a <send_error+0x12a>
cmpl   $0x1f4,-0x8(%rbp)
jne    11f9 <send_error+0xa9>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x105f(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1275 <send_error+0x125>
cmpl   $0x190,-0x8(%rbp)
jne    1224 <send_error+0xd4>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x1155(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1270 <send_error+0x120>
cmpl   $0x259,-0x8(%rbp)
jne    124f <send_error+0xff>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x1235(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    126b <send_error+0x11b>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0x132f(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1270 <send_error+0x120>
jmp    1275 <send_error+0x125>
jmp    127a <send_error+0x12a>
jmp    127f <send_error+0x12f>
mov    -0x4(%rbp),%eax
mov    %eax,-0x81c(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x81c(%rbp),%edi
mov    -0x818(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1060 <fsync@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_error>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x800,%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmp    $0x193,%ebp
jle    119a <send_error+0x4a>
cmp    $0x194,%ebp
je     11b3 <send_error+0x63>
cmp    $0x1f4,%ebp
je     11bc <send_error+0x6c>
cmp    $0x259,%ebp
jne    1203 <send_error+0xb3>
lea    0x12e0(%rip),%rsi
jmp    11cc <send_error+0x7c>
cmp    $0x190,%ebp
je     11c5 <send_error+0x75>
cmp    $0x191,%ebp
jne    1203 <send_error+0xb3>
lea    0xe4f(%rip),%rsi
jmp    11cc <send_error+0x7c>
lea    0xf89(%rip),%rsi
jmp    11cc <send_error+0x7c>
lea    0x1089(%rip),%rsi
jmp    11cc <send_error+0x7c>
lea    0x11a1(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <fsync@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x1389(%rip),%rsi
mov    %rsp,%rdi
mov    %ebp,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    11d9 <send_error+0x89>

LLVM IR (-O0):
@.str = [323 x i8] c"HTTP/1.0 401 Unauthorized\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0AWWW-Authenticate: Basic realm=\22MJPG-Streamer\22\0D\0A\0D\0A401: Not Authenticated!\0D\0A%s\00"
@.str.1 = [265 x i8] c"HTTP/1.0 404 Not Found\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A404: Not Found!\0D\0A%s\00"
@.str.2 = [289 x i8] c"HTTP/1.0 500 Internal Server Error\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A500: Internal Server Error!\0D\0A%s\00"
@.str.3 = [267 x i8] c"HTTP/1.0 400 Bad Request\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A400: Not Found!\0D\0A%s\00"
@.str.4 = [283 x i8] c"HTTP/1.0 601 Remote Authen Fail\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A601: Remote Authen Fail!\0D\0A%s\00"
@.str.5 = [266 x i8] c"HTTP/1.0 %d Error\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A501: Not Implemented!\0D\0A%s\00"
define void @send_error(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [2048 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = bitcast [2048 x i8]* %7 to i8*
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 401
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %6
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([323 x i8], [323 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %52
15: ; preds = %3
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 404
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([265 x i8], [265 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %51
22: ; preds = %15
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 500
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([289 x i8], [289 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %50
29: ; preds = %22
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 400
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([267 x i8], [267 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %49
36: ; preds = %29
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 601
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%41 = load i8*, i8** %6
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([283 x i8], [283 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %48
43: ; preds = %36
%44 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%45 = load i32, i32* %5
%46 = load i8*, i8** %6
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([266 x i8], [266 x i8]* @.str.5, i64 0, i64 0), i32 %45, i8* %46)
br label %48
48: ; preds = %43, %39
br label %49
49: ; preds = %48, %32
br label %50
50: ; preds = %49, %25
br label %51
51: ; preds = %50, %18
br label %52
52: ; preds = %51, %11
%53 = load i32, i32* %4
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @write(i32 %53, i8* %54, i32 %56)
%58 = load i32, i32* %4
%59 = call i32 @fsync(i32 %58)
ret void
}

LLVM IR (-O2):
@.str = [323 x i8] c"HTTP/1.0 401 Unauthorized\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0AWWW-Authenticate: Basic realm=\22MJPG-Streamer\22\0D\0A\0D\0A401: Not Authenticated!\0D\0A%s\00"
@.str.1 = [265 x i8] c"HTTP/1.0 404 Not Found\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A404: Not Found!\0D\0A%s\00"
@.str.2 = [289 x i8] c"HTTP/1.0 500 Internal Server Error\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A500: Internal Server Error!\0D\0A%s\00"
@.str.3 = [267 x i8] c"HTTP/1.0 400 Bad Request\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A400: Not Found!\0D\0A%s\00"
@.str.4 = [283 x i8] c"HTTP/1.0 601 Remote Authen Fail\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A601: Remote Authen Fail!\0D\0A%s\00"
@.str.5 = [266 x i8] c"HTTP/1.0 %d Error\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: MJPG-Streamer/0.2\0D\0ACache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\0D\0APragma: no-cache\0D\0AExpires: Mon, 3 Jan 2000 12:34:56 GMT\0D\0A\0D\0A501: Not Implemented!\0D\0A%s\00"
define void @send_error(i32 %0, i32 %1, i8* %2) {
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
switch i32 %1, label %16 [
i32 401, label %6
i32 404, label %8
i32 500, label %10
i32 400, label %12
i32 601, label %14
]
6: ; preds = %3
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([323 x i8], [323 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %18
8: ; preds = %3
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([265 x i8], [265 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %18
10: ; preds = %3
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([289 x i8], [289 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %18
12: ; preds = %3
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([267 x i8], [267 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %18
14: ; preds = %3
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([283 x i8], [283 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %18
16: ; preds = %3
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([266 x i8], [266 x i8]* @.str.5, i64 0, i64 0), i32 %1, i8* %2)
br label %18
18: ; preds = %8, %12, %16, %14, %10, %6
%19 = call i32 @strlen(i8* %5)
%20 = call i32 @write(i32 %0, i8* %5, i32 %19)
%21 = call i32 @fsync(i32 %0)
ret void
}