#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 */
typedef int /*<<< orphan*/ uint8_t;
struct hpack_decoder {
  int dummy;
};
typedef scalar_t__ int_fast32_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ hpack_decode_int(int, int /*<<< orphan*/ const **, size_t *);
char *hpack_decode_str(int /*<<< orphan*/ const **, size_t *);
char *hpack_lookup_name(struct hpack_decoder *, scalar_t__);
int hpack_decode_hdr_noindex(struct hpack_decoder *dec,
                             const uint8_t **restrict datap,
                             size_t *restrict lengthp, char **restrict namep,
                             char **restrict valuep) {
  int_fast32_t idx = hpack_decode_int(4, datap, lengthp);
  if (idx < 0)
    return -1;
  char *name;
  if (idx != 0)
    name = hpack_lookup_name(dec, idx);
  else
    name = hpack_decode_str(datap, lengthp);
  if (name == NULL)
    return -1;
  char *value = hpack_decode_str(datap, lengthp);
  if (value == NULL) {
    free(name);
    return -1;
  }
  *namep = name;
  *valuep = value;
  return 0;
}


x86 assembly (clang, -O0):
<hpack_decode_hdr_noindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x4,%edi
call   1050 <hpack_decode_int@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    1189 <hpack_decode_hdr_noindex+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    1220 <hpack_decode_hdr_noindex+0xe0>
cmpq   $0x0,-0x38(%rbp)
je     11aa <hpack_decode_hdr_noindex+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <hpack_lookup_name@plt>
mov    %rax,-0x40(%rbp)
jmp    11bb <hpack_decode_hdr_noindex+0x7b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <hpack_decode_str@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11d2 <hpack_decode_hdr_noindex+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    1220 <hpack_decode_hdr_noindex+0xe0>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <hpack_decode_str@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1203 <hpack_decode_hdr_noindex+0xc3>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1220 <hpack_decode_hdr_noindex+0xe0>
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpack_decode_hdr_noindex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r13
mov    $0x4,%edi
call   1050 <hpack_decode_int@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
js     11b4 <hpack_decode_hdr_noindex+0x74>
je     117e <hpack_decode_hdr_noindex+0x3e>
mov    %r13,%rdi
mov    %rax,%rsi
call   1060 <hpack_lookup_name@plt>
jmp    1189 <hpack_decode_hdr_noindex+0x49>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <hpack_decode_str@plt>
mov    %rax,%r13
test   %rax,%rax
je     11b4 <hpack_decode_hdr_noindex+0x74>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <hpack_decode_str@plt>
test   %rax,%rax
je     11ac <hpack_decode_hdr_noindex+0x6c>
mov    %r13,(%r15)
mov    %rax,(%r14)
xor    %r12d,%r12d
jmp    11b4 <hpack_decode_hdr_noindex+0x74>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hpack_decoder = type { i32 }
define i32 @hpack_decode_hdr_noindex(%struct.hpack_decoder* %0, i32** noalias %1, i64* noalias %2, i8** noalias %3, i8** noalias %4) {
%6 = alloca i32
%7 = alloca %struct.hpack_decoder*
%8 = alloca i32**
%9 = alloca i64*
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
store %struct.hpack_decoder* %0, %struct.hpack_decoder** %7
store i32** %1, i32*** %8
store i64* %2, i64** %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
%15 = load i32**, i32*** %8
%16 = load i64*, i64** %9
%17 = call i64 @hpack_decode_int(i32 4, i32** %15, i64* %16)
store i64 %17, i64* %12
%18 = load i64, i64* %12
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 -1, i32* %6
br label %50
21: ; preds = %5
%22 = load i64, i64* %12
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load %struct.hpack_decoder*, %struct.hpack_decoder** %7
%26 = load i64, i64* %12
%27 = call i8* @hpack_lookup_name(%struct.hpack_decoder* %25, i64 %26)
store i8* %27, i8** %13
br label %32
28: ; preds = %21
%29 = load i32**, i32*** %8
%30 = load i64*, i64** %9
%31 = call i8* @hpack_decode_str(i32** %29, i64* %30)
store i8* %31, i8** %13
br label %32
32: ; preds = %28, %24
%33 = load i8*, i8** %13
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 -1, i32* %6
br label %50
36: ; preds = %32
%37 = load i32**, i32*** %8
%38 = load i64*, i64** %9
%39 = call i8* @hpack_decode_str(i32** %37, i64* %38)
store i8* %39, i8** %14
%40 = load i8*, i8** %14
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i8*, i8** %13
%44 = call i32 @free(i8* %43)
store i32 -1, i32* %6
br label %50
45: ; preds = %36
%46 = load i8*, i8** %13
%47 = load i8**, i8*** %10
store i8* %46, i8** %47
%48 = load i8*, i8** %14
%49 = load i8**, i8*** %11
store i8* %48, i8** %49
store i32 0, i32* %6
br label %50
50: ; preds = %45, %42, %35, %20
%51 = load i32, i32* %6
ret i32 %51
}

LLVM IR (-O2):
%struct.hpack_decoder = type { i32 }
define i32 @hpack_decode_hdr_noindex(%struct.hpack_decoder* %0, i32** noalias %1, i64* noalias %2, i8** noalias nocapture writeonly %3, i8** noalias nocapture writeonly %4) {
%6 = tail call i64 @hpack_decode_int(i32 4, i32** %1, i64* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = icmp eq i64 %6, 0
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i8* @hpack_lookup_name(%struct.hpack_decoder* %0, i64 %6)
br label %14
12: ; preds = %8
%13 = tail call i8* @hpack_decode_str(i32** %1, i64* %2)
br label %14
14: ; preds = %12, %10
%15 = phi i8* [ %11, %10 ], [ %13, %12 ]
%16 = icmp eq i8* %15, null
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = tail call i8* @hpack_decode_str(i32** %1, i64* %2)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @free(i8* %15)
br label %23
22: ; preds = %17
store i8* %15, i8** %3
store i8* %18, i8** %4
br label %23
23: ; preds = %14, %22, %20, %5
%24 = phi i32 [ -1, %5 ], [ -1, %14 ], [ -1, %20 ], [ 0, %22 ]
ret i32 %24
}