#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 */
scalar_t__ ccnl_ccnb_consume(int, int, unsigned char **, int *,
                             unsigned char **, int *);
scalar_t__ ccnl_ccnb_dehead(unsigned char **, int *, int *, int *);
int ccnl_ccnb_hunt_for_end(unsigned char **buf, int *len,
                           unsigned char **valptr, int *vallen) {
  int typ, num;
  while (ccnl_ccnb_dehead(buf, len, &num, &typ) == 0) {
    if (num == 0 && typ == 0)
      return 0;
    if (ccnl_ccnb_consume(typ, num, buf, len, valptr, vallen) < 0)
      return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<ccnl_ccnb_hunt_for_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <ccnl_ccnb_dehead@plt>
cmp    $0x0,%rax
jne    11ad <ccnl_ccnb_hunt_for_end+0x8d>
cmpl   $0x0,-0x30(%rbp)
jne    1177 <ccnl_ccnb_hunt_for_end+0x57>
cmpl   $0x0,-0x2c(%rbp)
jne    1177 <ccnl_ccnb_hunt_for_end+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <ccnl_ccnb_hunt_for_end+0x94>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1030 <ccnl_ccnb_consume@plt>
cmp    $0x0,%rax
jge    11a8 <ccnl_ccnb_hunt_for_end+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <ccnl_ccnb_hunt_for_end+0x94>
jmp    1138 <ccnl_ccnb_hunt_for_end+0x18>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_ccnb_hunt_for_end>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x4(%rsp),%rbp
mov    $0xffffffff,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rsp,%rdx
mov    %rbp,%rcx
call   1040 <ccnl_ccnb_dehead@plt>
test   %rax,%rax
jne    118e <ccnl_ccnb_hunt_for_end+0x6e>
mov    (%rsp),%esi
mov    0x4(%rsp),%edi
mov    %esi,%eax
or     %edi,%eax
je     118b <ccnl_ccnb_hunt_for_end+0x6b>
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1030 <ccnl_ccnb_consume@plt>
test   %rax,%rax
jns    1150 <ccnl_ccnb_hunt_for_end+0x30>
jmp    118e <ccnl_ccnb_hunt_for_end+0x6e>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ccnl_ccnb_hunt_for_end(i8** %0, i32* %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
br label %9
9: ; preds = %18, %4
%10 = call i64 @ccnl_ccnb_dehead(i8** %0, i32* %1, i32* %6, i32* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = call i64 @ccnl_ccnb_consume(i32 %15, i32 %13, i8** %0, i32* %1, i8** %2, i32* %3)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %9, %18, %12
%22 = phi i32 [ 0, %12 ], [ -1, %18 ], [ -1, %9 ]
ret i32 %22
}