#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_lookup_name(struct hpack_decoder *, scalar_t__);
char *hpack_lookup_value(struct hpack_decoder *, scalar_t__);
int hpack_decode_hdr_indexed(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(7, datap, lengthp);
  if (idx < 0)
    return -1;
  char *name = hpack_lookup_name(dec, idx);
  if (name == NULL)
    return -1;
  char *value = hpack_lookup_value(dec, idx);
  if (value == NULL) {
    free(name);
    return -1;
  }
  *namep = name;
  *valuep = value;
  return 0;
}


x86 assembly (clang, -O0):
<hpack_decode_hdr_indexed>:
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    $0x7,%edi
call   1050 <hpack_decode_int@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    1189 <hpack_decode_hdr_indexed+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <hpack_decode_hdr_indexed+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <hpack_lookup_name@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11b1 <hpack_decode_hdr_indexed+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <hpack_decode_hdr_indexed+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <hpack_lookup_value@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11e2 <hpack_decode_hdr_indexed+0xa2>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <hpack_decode_hdr_indexed+0xbf>
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_indexed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdi,%rbx
mov    $0x7,%edi
call   1050 <hpack_decode_int@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
js     11a2 <hpack_decode_hdr_indexed+0x62>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <hpack_lookup_name@plt>
test   %rax,%rax
je     11a2 <hpack_decode_hdr_indexed+0x62>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <hpack_lookup_value@plt>
test   %rax,%rax
je     119a <hpack_decode_hdr_indexed+0x5a>
mov    %r13,(%r15)
mov    %rax,(%r14)
xor    %r12d,%r12d
jmp    11a2 <hpack_decode_hdr_indexed+0x62>
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_indexed(%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 7, 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 %42
21: ; preds = %5
%22 = load %struct.hpack_decoder*, %struct.hpack_decoder** %7
%23 = load i64, i64* %12
%24 = call i8* @hpack_lookup_name(%struct.hpack_decoder* %22, i64 %23)
store i8* %24, i8** %13
%25 = load i8*, i8** %13
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 -1, i32* %6
br label %42
28: ; preds = %21
%29 = load %struct.hpack_decoder*, %struct.hpack_decoder** %7
%30 = load i64, i64* %12
%31 = call i8* @hpack_lookup_value(%struct.hpack_decoder* %29, i64 %30)
store i8* %31, i8** %14
%32 = load i8*, i8** %14
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i8*, i8** %13
%36 = call i32 @free(i8* %35)
store i32 -1, i32* %6
br label %42
37: ; preds = %28
%38 = load i8*, i8** %13
%39 = load i8**, i8*** %10
store i8* %38, i8** %39
%40 = load i8*, i8** %14
%41 = load i8**, i8*** %11
store i8* %40, i8** %41
store i32 0, i32* %6
br label %42
42: ; preds = %37, %34, %27, %20
%43 = load i32, i32* %6
ret i32 %43
}

LLVM IR (-O2):
%struct.hpack_decoder = type { i32 }
define i32 @hpack_decode_hdr_indexed(%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 7, i32** %1, i64* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = tail call i8* @hpack_lookup_name(%struct.hpack_decoder* %0, i64 %6)
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = tail call i8* @hpack_lookup_value(%struct.hpack_decoder* %0, i64 %6)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @free(i8* %9)
br label %17
16: ; preds = %11
store i8* %9, i8** %3
store i8* %12, i8** %4
br label %17
17: ; preds = %8, %16, %14, %5
%18 = phi i32 [ -1, %5 ], [ -1, %8 ], [ -1, %14 ], [ 0, %16 ]
ret i32 %18
}