#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*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void send_error(int fd, int which, char *message) {
  char buffer[1024] = {0};
  if (which == 401) {
    sprintf(buffer,
            "HTTP/1.0 401 Unauthorized\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: uRobot/0.9\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: uRobot/0.9\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: uRobot/0.9\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: uRobot/0.9\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 {
    sprintf(buffer,
            "HTTP/1.0 501 Not Implemented\r\n"
            "Content-type: text/plain\r\n"
            "Connection: close\r\n"
            "Server: uRobot/0.9\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",
            message);
  }
  write(fd, buffer, strlen(buffer));
}


x86 assembly (clang, -O0):
<send_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
cmpl   $0x191,-0x8(%rbp)
jne    1191 <send_error+0x51>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe79(%rip),%rsi
call   1060 <sprintf@plt>
jmp    1232 <send_error+0xf2>
cmpl   $0x194,-0x8(%rbp)
jne    11ba <send_error+0x7a>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xf8c(%rip),%rsi
call   1060 <sprintf@plt>
jmp    122d <send_error+0xed>
cmpl   $0x1f4,-0x8(%rbp)
jne    11e3 <send_error+0xa3>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x1065(%rip),%rsi
call   1060 <sprintf@plt>
jmp    1228 <send_error+0xe8>
cmpl   $0x190,-0x8(%rbp)
jne    120c <send_error+0xcc>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x1156(%rip),%rsi
call   1060 <sprintf@plt>
jmp    1223 <send_error+0xe3>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x123e(%rip),%rsi
call   1060 <sprintf@plt>
jmp    1228 <send_error+0xe8>
jmp    122d <send_error+0xed>
jmp    1232 <send_error+0xf2>
mov    -0x4(%rbp),%eax
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x41c(%rbp),%edi
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_error>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmp    $0x193,%ebp
jg     1183 <send_error+0x43>
cmp    $0x190,%ebp
je     11a5 <send_error+0x65>
cmp    $0x191,%ebp
jne    119c <send_error+0x5c>
lea    0xe7f(%rip),%rsi
jmp    11b5 <send_error+0x75>
cmp    $0x1f4,%ebp
je     11ae <send_error+0x6e>
cmp    $0x194,%ebp
jne    119c <send_error+0x5c>
lea    0xfa2(%rip),%rsi
jmp    11b5 <send_error+0x75>
lea    0x12b9(%rip),%rsi
jmp    11b5 <send_error+0x75>
lea    0x11ac(%rip),%rsi
jmp    11b5 <send_error+0x75>
lea    0x1089(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [316 x i8] c"HTTP/1.0 401 Unauthorized\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [258 x i8] c"HTTP/1.0 404 Not Found\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [282 x i8] c"HTTP/1.0 500 Internal Server Error\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [260 x i8] c"HTTP/1.0 400 Bad Request\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [270 x i8] c"HTTP/1.0 501 Not Implemented\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 [1024 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = bitcast [1024 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 [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %6
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([316 x i8], [316 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %43
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 [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([258 x i8], [258 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %42
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 [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([282 x i8], [282 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %41
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 [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([260 x i8], [260 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %40
36: ; preds = %29
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = load i8*, i8** %6
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([270 x i8], [270 x i8]* @.str.4, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %32
br label %41
41: ; preds = %40, %25
br label %42
42: ; preds = %41, %18
br label %43
43: ; preds = %42, %11
%44 = load i32, i32* %4
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @write(i32 %44, i8* %45, i32 %47)
ret void
}

LLVM IR (-O2):
@.str = [316 x i8] c"HTTP/1.0 401 Unauthorized\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [258 x i8] c"HTTP/1.0 404 Not Found\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [282 x i8] c"HTTP/1.0 500 Internal Server Error\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [260 x i8] c"HTTP/1.0 400 Bad Request\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 = [270 x i8] c"HTTP/1.0 501 Not Implemented\0D\0AContent-type: text/plain\0D\0AConnection: close\0D\0AServer: uRobot/0.9\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 [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
switch i32 %1, label %9 [
i32 401, label %10
i32 404, label %6
i32 500, label %7
i32 400, label %8
]
6: ; preds = %3
br label %10
7: ; preds = %3
br label %10
8: ; preds = %3
br label %10
9: ; preds = %3
br label %10
10: ; preds = %3, %6, %8, %9, %7
%11 = phi i8* [ getelementptr inbounds ([258 x i8], [258 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([260 x i8], [260 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([270 x i8], [270 x i8]* @.str.4, i64 0, i64 0), %9 ], [ getelementptr inbounds ([282 x i8], [282 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([316 x i8], [316 x i8]* @.str, i64 0, i64 0), %3 ]
%12 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) %11, i8* %2)
%13 = call i32 @strlen(i8* %5)
%14 = call i32 @write(i32 %0, i8* %5, i32 %13)
ret void
}