#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*/ free(char *);
char *get_http_header_str(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
char *http_header_string(int code, char *value) {
  char *name, *repr;
  int len;
  if (code < 0 || code > 16 || value == NULL) {
    return NULL;
  }
  name = get_http_header_str(code);
  if (name == NULL) {
    free(name);
    return NULL;
  }
  len = strlen(name) + 2 + strlen(value) + 2;
  repr = (char *)malloc(sizeof(char) * (len + 1));
  if (repr == NULL) {
    perror("malloc");
    free(name);
    return NULL;
  }
  snprintf(repr, len + 1, "%s: %s\r\n", name, value);
  free(name);
  return repr;
}


x86 assembly (clang, -O0):
<http_header_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     118e <http_header_string+0x2e>
cmpl   $0x10,-0xc(%rbp)
jg     118e <http_header_string+0x2e>
cmpq   $0x0,-0x18(%rbp)
jne    119b <http_header_string+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    1260 <http_header_string+0x100>
mov    -0xc(%rbp),%edi
call   1080 <get_http_header_str@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c8 <http_header_string+0x68>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1260 <http_header_string+0x100>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1231 <http_header_string+0xd1>
lea    0xdea(%rip),%rdi
call   1070 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1260 <http_header_string+0x100>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdbd(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_header_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x10,%edi
ja     11cf <http_header_string+0x6f>
mov    %rsi,%r15
test   %rsi,%rsi
je     11cf <http_header_string+0x6f>
call   1080 <get_http_header_str@plt>
test   %rax,%rax
je     11c6 <http_header_string+0x66>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x5,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11dd <http_header_string+0x7d>
mov    %rax,%rbx
lea    0xe56(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <snprintf@plt>
mov    %r14,%rdi
jmp    11ca <http_header_string+0x6a>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1c(%rip),%rdi
call   1070 <perror@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    11cf <http_header_string+0x6f>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [9 x i8] c"%s: %s\0D\0A\00"
define i8* @http_header_string(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 16
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %2
store i8* null, i8** %3
br label %57
18: ; preds = %14
%19 = load i32, i32* %4
%20 = call i8* @get_http_header_str(i32 %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
store i8* null, i8** %3
br label %57
26: ; preds = %18
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
%29 = add nsw i32 %28, 2
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %29, %31
%33 = add nsw i32 %32, 2
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = mul i64 1, %36
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %26
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%45 = load i8*, i8** %6
%46 = call i32 @free(i8* %45)
store i8* null, i8** %3
br label %57
47: ; preds = %26
%48 = load i8*, i8** %7
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
%51 = load i8*, i8** %6
%52 = load i8*, i8** %5
%53 = call i32 @snprintf(i8* %48, i32 %50, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %52)
%54 = load i8*, i8** %6
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %7
store i8* %56, i8** %3
br label %57
57: ; preds = %47, %43, %23, %17
%58 = load i8*, i8** %3
ret i8* %58
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [9 x i8] c"%s: %s\0D\0A\00"
define i8* @http_header_string(i32 %0, i8* %1) {
%3 = icmp ugt i32 %0, 16
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %25, label %6
6: ; preds = %2
%7 = tail call i8* @get_http_header_str(i32 %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @free(i8* null)
br label %25
11: ; preds = %6
%12 = tail call i32 @strlen(i8* %7)
%13 = tail call i32 @strlen(i8* %1)
%14 = add i32 %12, 5
%15 = add i32 %14, %13
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @free(i8* %7)
br label %25
22: ; preds = %11
%23 = tail call i32 @snprintf(i8* %17, i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %1)
%24 = tail call i32 @free(i8* %7)
br label %25
25: ; preds = %2, %22, %19, %9
%26 = phi i8* [ null, %9 ], [ null, %19 ], [ %17, %22 ], [ null, %2 ]
ret i8* %26
}