#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_ndntlv_prependNonNegIntVal(unsigned int, int *,
                                           unsigned char *);
scalar_t__ ccnl_ndntlv_prependTL(int, int, int *, unsigned char *);
int ccnl_ndntlv_prependIncludedNonNegInt(int type, unsigned int val,
                                         char marker, int *offset,
                                         unsigned char *buf) {
  int oldoffset = *offset;
  if (ccnl_ndntlv_prependNonNegIntVal(val, offset, buf) < 0)
    return -1;
  if ((*offset)-- < 1)
    return -1;
  buf[*offset] = marker;
  if (ccnl_ndntlv_prependTL(type, oldoffset - *offset, offset, buf) < 0)
    return -1;
  return oldoffset - *offset;
}


x86 assembly (clang, -O0):
<ccnl_ndntlv_prependIncludedNonNegInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <ccnl_ndntlv_prependNonNegIntVal@plt>
cmp    $0x0,%rax
jge    116a <ccnl_ndntlv_prependIncludedNonNegInt+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <ccnl_ndntlv_prependIncludedNonNegInt+0xb8>
mov    -0x18(%rbp),%rcx
mov    (%rcx),%eax
mov    %eax,%edx
add    $0xffffffff,%edx
mov    %edx,(%rcx)
cmp    $0x1,%eax
jge    118c <ccnl_ndntlv_prependIncludedNonNegInt+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <ccnl_ndntlv_prependIncludedNonNegInt+0xb8>
mov    -0xd(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rax
sub    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <ccnl_ndntlv_prependTL@plt>
cmp    $0x0,%rax
jge    11cc <ccnl_ndntlv_prependIncludedNonNegInt+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <ccnl_ndntlv_prependIncludedNonNegInt+0xb8>
mov    -0x24(%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_ndntlv_prependIncludedNonNegInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %edx,%r12d
mov    %edi,%r15d
mov    (%rcx),%r13d
mov    %esi,%edi
mov    %rcx,%rsi
mov    %r8,%rdx
call   1030 <ccnl_ndntlv_prependNonNegIntVal@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     1182 <ccnl_ndntlv_prependIncludedNonNegInt+0x62>
mov    (%rbx),%ecx
lea    -0x1(%rcx),%eax
mov    %eax,(%rbx)
test   %ecx,%ecx
jle    1182 <ccnl_ndntlv_prependIncludedNonNegInt+0x62>
mov    %eax,%eax
mov    %r12b,0x0(%rbp,%rax,1)
mov    %r13d,%esi
sub    (%rbx),%esi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <ccnl_ndntlv_prependTL@plt>
test   %rax,%rax
js     1182 <ccnl_ndntlv_prependIncludedNonNegInt+0x62>
sub    (%rbx),%r13d
mov    %r13d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ccnl_ndntlv_prependIncludedNonNegInt(i32 %0, i32 %1, i8 signext %2, i32* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i8 %2, i8* %9
store i32* %3, i32** %10
store i8* %4, i8** %11
%13 = load i32*, i32** %10
%14 = load i32, i32* %13
store i32 %14, i32* %12
%15 = load i32, i32* %8
%16 = load i32*, i32** %10
%17 = load i8*, i8** %11
%18 = call i64 @ccnl_ndntlv_prependNonNegIntVal(i32 %15, i32* %16, i8* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 -1, i32* %6
br label %49
21: ; preds = %5
%22 = load i32*, i32** %10
%23 = load i32, i32* %22
%24 = add nsw i32 %23, -1
store i32 %24, i32* %22
%25 = icmp slt i32 %23, 1
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %6
br label %49
27: ; preds = %21
%28 = load i8, i8* %9
%29 = load i8*, i8** %11
%30 = load i32*, i32** %10
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 %28, i8* %33
%34 = load i32, i32* %7
%35 = load i32, i32* %12
%36 = load i32*, i32** %10
%37 = load i32, i32* %36
%38 = sub nsw i32 %35, %37
%39 = load i32*, i32** %10
%40 = load i8*, i8** %11
%41 = call i64 @ccnl_ndntlv_prependTL(i32 %34, i32 %38, i32* %39, i8* %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %27
store i32 -1, i32* %6
br label %49
44: ; preds = %27
%45 = load i32, i32* %12
%46 = load i32*, i32** %10
%47 = load i32, i32* %46
%48 = sub nsw i32 %45, %47
store i32 %48, i32* %6
br label %49
49: ; preds = %44, %43, %26, %20
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
define i32 @ccnl_ndntlv_prependIncludedNonNegInt(i32 %0, i32 %1, i8 signext %2, i32* %3, i8* %4) {
%6 = load i32, i32* %3
%7 = tail call i64 @ccnl_ndntlv_prependNonNegIntVal(i32 %1, i32* %3, i8* %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %5
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
%12 = icmp slt i32 %10, 1
br i1 %12, label %23, label %13
13: ; preds = %9
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 %2, i8* %15
%16 = load i32, i32* %3
%17 = sub nsw i32 %6, %16
%18 = tail call i64 @ccnl_ndntlv_prependTL(i32 %0, i32 %17, i32* %3, i8* %4)
%19 = icmp slt i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = load i32, i32* %3
%22 = sub nsw i32 %6, %21
br label %23
23: ; preds = %13, %9, %5, %20
%24 = phi i32 [ %22, %20 ], [ -1, %5 ], [ -1, %9 ], [ -1, %13 ]
ret i32 %24
}