#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 */
struct ccnl_prefix_s {
  int dummy;
};

/* Variables and functions */
scalar_t__ ccnl_cistlv_prependFixedHdr(int, int, int, unsigned char, int *,
                                       unsigned char *);
int ccnl_cistlv_prependInterest(struct ccnl_prefix_s *, int *, unsigned char *);
int ccnl_cistlv_prependChunkInterestWithHdr(struct ccnl_prefix_s *name,
                                            int *offset, unsigned char *buf) {
  int len, oldoffset;
  unsigned char hoplimit = 64;
  oldoffset = *offset;
  len = ccnl_cistlv_prependInterest(name, offset, buf);
  if (len >= ((1 << 16) - 8))
    return -1;
  if (ccnl_cistlv_prependFixedHdr(1, 1, len, hoplimit, offset, buf) < 0)
    return -1;
  return oldoffset - *offset;
}


x86 assembly (clang, -O0):
<ccnl_cistlv_prependChunkInterestWithHdr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movb   $0x40,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <ccnl_cistlv_prependInterest@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xfff8,-0x24(%rbp)
jl     116e <ccnl_cistlv_prependChunkInterestWithHdr+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <ccnl_cistlv_prependChunkInterestWithHdr+0x8d>
mov    -0x24(%rbp),%edx
mov    -0x29(%rbp),%al
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    $0x1,%esi
mov    %esi,%edi
movzbl %al,%ecx
call   1040 <ccnl_cistlv_prependFixedHdr@plt>
cmp    $0x0,%rax
jge    11a1 <ccnl_cistlv_prependChunkInterestWithHdr+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <ccnl_cistlv_prependChunkInterestWithHdr+0x8d>
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_cistlv_prependChunkInterestWithHdr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    (%rsi),%r15d
call   1030 <ccnl_cistlv_prependInterest@plt>
mov    $0xffffffff,%r14d
cmp    $0xfff7,%eax
jg     1169 <ccnl_cistlv_prependChunkInterestWithHdr+0x49>
mov    $0x1,%edi
mov    $0x1,%esi
mov    %eax,%edx
mov    $0x40,%ecx
mov    %rbx,%r8
mov    %rbp,%r9
call   1040 <ccnl_cistlv_prependFixedHdr@plt>
test   %rax,%rax
js     1169 <ccnl_cistlv_prependChunkInterestWithHdr+0x49>
sub    (%rbx),%r15d
mov    %r15d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ccnl_prefix_s = type { i32 }
define i32 @ccnl_cistlv_prependChunkInterestWithHdr(%struct.ccnl_prefix_s* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.ccnl_prefix_s*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store %struct.ccnl_prefix_s* %0, %struct.ccnl_prefix_s** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8 64, i8* %10
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
store i32 %12, i32* %9
%13 = load %struct.ccnl_prefix_s*, %struct.ccnl_prefix_s** %5
%14 = load i32*, i32** %6
%15 = load i8*, i8** %7
%16 = call i32 @ccnl_cistlv_prependInterest(%struct.ccnl_prefix_s* %13, i32* %14, i8* %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp sge i32 %17, 65528
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 -1, i32* %4
br label %33
20: ; preds = %3
%21 = load i32, i32* %8
%22 = load i8, i8* %10
%23 = load i32*, i32** %6
%24 = load i8*, i8** %7
%25 = call i64 @ccnl_cistlv_prependFixedHdr(i32 1, i32 1, i32 %21, i8 zeroext %22, i32* %23, i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 -1, i32* %4
br label %33
28: ; preds = %20
%29 = load i32, i32* %9
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = sub nsw i32 %29, %31
store i32 %32, i32* %4
br label %33
33: ; preds = %28, %27, %19
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.ccnl_prefix_s = type { i32 }
define i32 @ccnl_cistlv_prependChunkInterestWithHdr(%struct.ccnl_prefix_s* %0, i32* %1, i8* %2) {
%4 = load i32, i32* %1
%5 = tail call i32 @ccnl_cistlv_prependInterest(%struct.ccnl_prefix_s* %0, i32* %1, i8* %2)
%6 = icmp sgt i32 %5, 65527
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = tail call i64 @ccnl_cistlv_prependFixedHdr(i32 1, i32 1, i32 %5, i8 zeroext 64, i32* %1, i8* %2)
%9 = icmp slt i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* %1
%12 = sub nsw i32 %4, %11
br label %13
13: ; preds = %7, %3, %10
%14 = phi i32 [ %12, %10 ], [ -1, %3 ], [ -1, %7 ]
ret i32 %14
}