#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);
int strlen(char *);
int http_header_size(int code, char *value) {
  char *name;
  int len = 0;
  if (code < 0 || code > 16 || value == NULL) {
    return -1;
  }
  if ((name = get_http_header_str(code)) == NULL) {
    free(name);
    return -1;
  }
  len = strlen(name) + 2 + strlen(value) + 2;
  free(name);
  return len;
}


x86 assembly (clang, -O0):
<http_header_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1165 <http_header_size+0x35>
cmpl   $0x10,-0x8(%rbp)
jg     1165 <http_header_size+0x35>
cmpq   $0x0,-0x10(%rbp)
jne    1171 <http_header_size+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <http_header_size+0xa0>
mov    -0x8(%rbp),%edi
call   1050 <get_http_header_str@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119c <http_header_size+0x6c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <http_header_size+0xa0>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_header_size>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebp
cmp    $0x10,%edi
ja     1176 <http_header_size+0x46>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1176 <http_header_size+0x46>
call   1050 <get_http_header_str@plt>
test   %rax,%rax
je     116f <http_header_size+0x3f>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
add    $0x4,%ebp
mov    %r14,%rdi
jmp    1171 <http_header_size+0x41>
xor    %edi,%edi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @http_header_size(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 16
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13, %10, %2
store i32 -1, i32* %3
br label %35
17: ; preds = %13
%18 = load i32, i32* %4
%19 = call i8* @get_http_header_str(i32 %18)
store i8* %19, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
store i32 -1, i32* %3
br label %35
24: ; preds = %17
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 2
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %27, %29
%31 = add nsw i32 %30, 2
store i32 %31, i32* %7
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* %7
store i32 %34, i32* %3
br label %35
35: ; preds = %24, %21, %16
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @http_header_size(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 %17, 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 %17
11: ; preds = %6
%12 = tail call i32 @strlen(i8* %7)
%13 = tail call i32 @strlen(i8* %1)
%14 = add i32 %12, 4
%15 = add i32 %14, %13
%16 = tail call i32 @free(i8* %7)
br label %17
17: ; preds = %2, %11, %9
%18 = phi i32 [ -1, %9 ], [ %15, %11 ], [ -1, %2 ]
ret i32 %18
}