#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 *bc_strdup_printf(char *, int, char const *, int, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
size_t write(int, char *, size_t);
void error(int socket, int status_code, const char *error) {
  char *str = bc_strdup_printf("HTTP/1.0 %d %s\r\n"
                               "Content-Type: text/html\r\n"
                               "Content-Length: %zu\r\n"
                               "Connection: close\r\n"
                               "\r\n"
                               "<h1>%s</h1>\n",
                               status_code, error, strlen(error) + 10, error);
  size_t str_len = strlen(str);
  if (str_len != write(socket, str, str_len)) {
    fprintf(stderr, "warning: Failed to write full response header!\n");
  }
  free(str);
}


x86 assembly (clang, -O0):
<error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
add    $0xa,%ecx
mov    -0x10(%rbp),%r8
lea    0xe70(%rip),%rdi
call   1070 <bc_strdup_printf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <write@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     11e5 <error+0x95>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rdx,%rdi
call   1050 <strlen@plt>
lea    0xa(%rax),%ecx
lea    0xe92(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %rbx,%r8
call   1070 <bc_strdup_printf@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <write@plt>
cmp    %rbp,%rax
je     11b1 <error+0x61>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [96 x i8] c"HTTP/1.0 %d %s\0D\0AContent-Type: text/html\0D\0AContent-Length: %zu\0D\0AConnection: close\0D\0A\0D\0A<h1>%s</h1>\0A\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"warning: Failed to write full response header!\0A\00"
define void @error(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 10
%14 = load i8*, i8** %6
%15 = call i8* @bc_strdup_printf(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %10, i32 %13, i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
store i64 %18, i64* %8
%19 = load i64, i64* %8
%20 = load i32, i32* %4
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = call i64 @write(i32 %20, i8* %21, i64 %22)
%24 = icmp ne i64 %19, %23
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %3
%29 = load i8*, i8** %7
%30 = call i32 @free(i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [96 x i8] c"HTTP/1.0 %d %s\0D\0AContent-Type: text/html\0D\0AContent-Length: %zu\0D\0AConnection: close\0D\0A\0D\0A<h1>%s</h1>\0A\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"warning: Failed to write full response header!\0A\00"
define void @error(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = add nsw i32 %4, 10
%6 = tail call i8* @bc_strdup_printf(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %2, i32 %5, i8* %2)
%7 = tail call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = tail call i64 @write(i32 %0, i8* %6, i64 %8)
%10 = icmp eq i64 %9, %8
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %3
%15 = tail call i32 @free(i8* %6)
ret void
}