#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void gen_http_headers(char *buf, int status, char *content_type) {
  switch (status) {
  case 200:
    assert(content_type != NULL);
    sprintf(buf, "HTTP/1.0 200 OK\r\nContent-Type: %s\r\n\r\n", content_type);
    break;
  case 204:
    assert(content_type == NULL);
    sprintf(buf, "HTTP/1.0 204 No Content\r\n\r\n", content_type);
    break;
  case 501:
    assert(content_type == NULL);
    strcat(buf, "HTTP/1.0 501 Not Implemented\r\nAllow: GET\r\n\r\n");
    break;
  default:
    assert(content_type == NULL);
    strcat(buf, "HTTP/1.0 500 Internal Server Error\r\n\r\n");
    break;
  }
}


x86 assembly (clang, -O0):
<gen_http_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xc8,%eax
je     117f <gen_http_headers+0x4f>
jmp    1159 <gen_http_headers+0x29>
mov    -0x1c(%rbp),%eax
sub    $0xcc,%eax
je     11aa <gen_http_headers+0x7a>
jmp    116c <gen_http_headers+0x3c>
mov    -0x1c(%rbp),%eax
sub    $0x1f5,%eax
je     11d5 <gen_http_headers+0xa5>
jmp    11fc <gen_http_headers+0xcc>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe60(%rip),%rsi
call   1050 <sprintf@plt>
jmp    121e <gen_http_headers+0xee>
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1050 <sprintf@plt>
jmp    121e <gen_http_headers+0xee>
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1040 <strcat@plt>
jmp    121e <gen_http_headers+0xee>
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1040 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_http_headers>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
xor    %edi,%edi
cmp    $0x1f5,%esi
je     1169 <gen_http_headers+0x39>
cmp    $0xcc,%esi
je     117e <gen_http_headers+0x4e>
cmp    $0xc8,%esi
jne    11a3 <gen_http_headers+0x73>
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
lea    0xe99(%rip),%rsi
jmp    1191 <gen_http_headers+0x61>
test   %rbx,%rbx
sete   %dil
call   1030 <assert@plt>
lea    0xec6(%rip),%rsi
jmp    11b6 <gen_http_headers+0x86>
test   %rbx,%rbx
sete   %dil
call   1030 <assert@plt>
lea    0xe95(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <sprintf@plt>
test   %rbx,%rbx
sete   %dil
call   1030 <assert@plt>
lea    0xeb9(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strcat@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"HTTP/1.0 200 OK\0D\0AContent-Type: %s\0D\0A\0D\0A\00"
@.str.1 = [28 x i8] c"HTTP/1.0 204 No Content\0D\0A\0D\0A\00"
@.str.2 = [45 x i8] c"HTTP/1.0 501 Not Implemented\0D\0AAllow: GET\0D\0A\0D\0A\00"
@.str.3 = [39 x i8] c"HTTP/1.0 500 Internal Server Error\0D\0A\0D\0A\00"
define void @gen_http_headers(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i32, i32* %5
switch i32 %7, label %31 [
i32 200, label %8
i32 204, label %16
i32 501, label %24
]
8: ; preds = %3
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %38
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %4
%22 = load i8*, i8** %6
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %38
24: ; preds = %3
%25 = load i8*, i8** %6
%26 = icmp eq i8* %25, null
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %38
31: ; preds = %3
%32 = load i8*, i8** %6
%33 = icmp eq i8* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i8*, i8** %4
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %31, %24, %16, %8
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"HTTP/1.0 200 OK\0D\0AContent-Type: %s\0D\0A\0D\0A\00"
@.str.1 = [28 x i8] c"HTTP/1.0 204 No Content\0D\0A\0D\0A\00"
@.str.2 = [45 x i8] c"HTTP/1.0 501 Not Implemented\0D\0AAllow: GET\0D\0A\0D\0A\00"
@.str.3 = [39 x i8] c"HTTP/1.0 500 Internal Server Error\0D\0A\0D\0A\00"
define void @gen_http_headers(i8* %0, i32 %1, i8* %2) {
switch i32 %1, label %19 [
i32 200, label %4
i32 204, label %9
i32 501, label %14
]
4: ; preds = %3
%5 = icmp ne i8* %2, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %24
9: ; preds = %3
%10 = icmp eq i8* %2, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %24
14: ; preds = %3
%15 = icmp eq i8* %2, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %24
19: ; preds = %3
%20 = icmp eq i8* %2, null
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %19, %14, %9, %4
ret void
}