#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 */
unsigned int ntohs(unsigned short);
int ccnl_cistlv_dehead(unsigned char **buf, int *len, unsigned int *typ,
                       unsigned int *vallen) {
  unsigned short *ip;
  if (*len < 4)
    return -1;
  ip = (unsigned short *)*buf;
  *typ = ntohs(*ip);
  ip++;
  *vallen = ntohs(*ip);
  *len -= 4;
  *buf += 4;
  return 0;
}


x86 assembly (clang, -O0):
<ccnl_cistlv_dehead>:
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    -0x18(%rbp),%rax
cmpl   $0x4,(%rax)
jge    1141 <ccnl_cistlv_dehead+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <ccnl_cistlv_dehead+0x90>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movzwl (%rax),%edi
call   1030 <ntohs@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movzwl (%rax),%edi
call   1030 <ntohs@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    $0x4,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x4,%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_cistlv_dehead>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0xffffffff,%eax
cmpl   $0x4,(%rsi)
jl     1156 <ccnl_cistlv_dehead+0x46>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rdi),%r13
movzwl 0x0(%r13),%edi
call   1030 <ntohs@plt>
mov    %eax,(%r12)
movzwl 0x2(%r13),%edi
call   1030 <ntohs@plt>
mov    %eax,(%r14)
addl   $0xfffffffc,(%rbx)
addq   $0x4,(%r15)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @ccnl_cistlv_dehead(i8** nocapture %0, i32* nocapture %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 4
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = bitcast i8** %0 to i16**
%9 = load i16*, i16** %8
%10 = load i16, i16* %9
%11 = tail call i32 @ntohs(i16 zeroext %10)
store i32 %11, i32* %2
%12 = getelementptr inbounds i16, i16* %9, i64 1
%13 = load i16, i16* %12
%14 = tail call i32 @ntohs(i16 zeroext %13)
store i32 %14, i32* %3
%15 = load i32, i32* %1
%16 = add nsw i32 %15, -4
store i32 %16, i32* %1
%17 = load i8*, i8** %0
%18 = getelementptr inbounds i8, i8* %17, i64 4
store i8* %18, i8** %0
br label %19
19: ; preds = %4, %7
%20 = phi i32 [ 0, %7 ], [ -1, %4 ]
ret i32 %20
}