#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*/ fail();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *get_header(int, int);
char *get_request(int);
int /*<<< orphan*/ headers_compact();
int /*<<< orphan*/ headers_has_request();
scalar_t__ headers_has_version();
scalar_t__ print_header(char *, char *);
int /*<<< orphan*/ stderr;
void test_headers() {
  headers_compact();
  if (!headers_has_request()) {
    fprintf(stderr, "  "
                    "Failed to parse request line\n");
    fail();
  }
  print_header("Method", get_request(0));
  print_header("Path", get_request(1));
  if (headers_has_version()) {
    print_header("Version", get_request(2));
  }
  int i = 0;
  while (print_header(get_header(i, 0), get_header(i, 1))) {
    i++;
  }
}


x86 assembly (clang, -O0):
<test_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <headers_compact@plt>
mov    $0x0,%al
call   1070 <headers_has_request@plt>
cmp    $0x0,%eax
jne    11bb <test_headers+0x3b>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1040 <fail@plt>
xor    %edi,%edi
call   1030 <get_request@plt>
mov    %rax,%rsi
lea    0xe54(%rip),%rdi
call   10a0 <print_header@plt>
mov    $0x1,%edi
call   1030 <get_request@plt>
mov    %rax,%rsi
lea    0xe42(%rip),%rdi
call   10a0 <print_header@plt>
mov    $0x0,%al
call   1090 <headers_has_version@plt>
cmp    $0x0,%rax
je     1214 <test_headers+0x94>
mov    $0x2,%edi
call   1030 <get_request@plt>
mov    %rax,%rsi
lea    0xe1d(%rip),%rdi
call   10a0 <print_header@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1060 <get_header@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1060 <get_header@plt>
mov    -0x10(%rbp),%rdi
mov    %rax,%rsi
call   10a0 <print_header@plt>
cmp    $0x0,%rax
je     125a <test_headers+0xda>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    121b <test_headers+0x9b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_headers>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <headers_compact@plt>
xor    %eax,%eax
call   1070 <headers_has_request@plt>
test   %eax,%eax
jne    11b2 <test_headers+0x32>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1080 <fprintf@plt>
xor    %eax,%eax
call   1040 <fail@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <get_request@plt>
lea    0xe5e(%rip),%rdi
mov    %rax,%rsi
call   10a0 <print_header@plt>
mov    $0x1,%edi
call   1030 <get_request@plt>
lea    0xe4c(%rip),%rdi
mov    %rax,%rsi
call   10a0 <print_header@plt>
xor    %eax,%eax
call   1090 <headers_has_version@plt>
test   %rax,%rax
je     1210 <test_headers+0x90>
mov    $0x2,%edi
call   1030 <get_request@plt>
lea    0xe2c(%rip),%rdi
mov    %rax,%rsi
call   10a0 <print_header@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <get_header@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <get_header@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   10a0 <print_header@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1210 <test_headers+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c" Failed to parse request line\0A\00"
@.str.1 = [7 x i8] c"Method\00"
@.str.2 = [5 x i8] c"Path\00"
@.str.3 = [8 x i8] c"Version\00"
define void @test_headers() {
%1 = alloca i32
%2 = call i32 (...) @headers_compact()
%3 = call i32 (...) @headers_has_request()
%4 = icmp ne i32 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @fail()
br label %9
9: ; preds = %5, %0
%10 = call i8* @get_request(i32 0)
%11 = call i64 @print_header(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i8* @get_request(i32 1)
%13 = call i64 @print_header(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = call i64 (...) @headers_has_version()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = call i8* @get_request(i32 2)
%18 = call i64 @print_header(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %9
store i32 0, i32* %1
br label %20
20: ; preds = %27, %19
%21 = load i32, i32* %1
%22 = call i8* @get_header(i32 %21, i32 0)
%23 = load i32, i32* %1
%24 = call i8* @get_header(i32 %23, i32 1)
%25 = call i64 @print_header(i8* %22, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i32, i32* %1
%29 = add nsw i32 %28, 1
store i32 %29, i32* %1
br label %20
30: ; preds = %20
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c" Failed to parse request line\0A\00"
@.str.1 = [7 x i8] c"Method\00"
@.str.2 = [5 x i8] c"Path\00"
@.str.3 = [8 x i8] c"Version\00"
define void @test_headers() {
%1 = tail call i32 (...) @headers_compact()
%2 = tail call i32 (...) @headers_has_request()
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @fail()
br label %8
8: ; preds = %4, %0
%9 = tail call i8* @get_request(i32 0)
%10 = tail call i64 @print_header(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i8* @get_request(i32 1)
%12 = tail call i64 @print_header(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = tail call i64 (...) @headers_has_version()
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = tail call i8* @get_request(i32 2)
%17 = tail call i64 @print_header(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %8
br label %19
19: ; preds = %18, %19
%20 = phi i32 [ %25, %19 ], [ 0, %18 ]
%21 = tail call i8* @get_header(i32 %20, i32 0)
%22 = tail call i8* @get_header(i32 %20, i32 1)
%23 = tail call i64 @print_header(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
%25 = add nuw nsw i32 %20, 1
br i1 %24, label %26, label %19
26: ; preds = %19
ret void
}