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


x86 assembly (clang, -O0):
<ccnl_ndntlv_prependNonNegInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-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    1165 <ccnl_ndntlv_prependNonNegInt+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <ccnl_ndntlv_prependNonNegInt+0x80>
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    1194 <ccnl_ndntlv_prependNonNegInt+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <ccnl_ndntlv_prependNonNegInt+0x80>
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_prependNonNegInt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %edi,%r15d
mov    (%rdx),%r12d
mov    %esi,%edi
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1030 <ccnl_ndntlv_prependNonNegIntVal@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     116a <ccnl_ndntlv_prependNonNegInt+0x4a>
mov    %r12d,%esi
sub    (%rbx),%esi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <ccnl_ndntlv_prependTL@plt>
test   %rax,%rax
js     116a <ccnl_ndntlv_prependNonNegInt+0x4a>
sub    (%rbx),%r12d
mov    %r12d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ccnl_ndntlv_prependNonNegInt(i32 %0, i32 %1, i32* %2, i8* %3) {
%5 = load i32, i32* %2
%6 = tail call i64 @ccnl_ndntlv_prependNonNegIntVal(i32 %1, i32* %2, i8* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %4
%9 = load i32, i32* %2
%10 = sub nsw i32 %5, %9
%11 = tail call i64 @ccnl_ndntlv_prependTL(i32 %0, i32 %10, i32* %2, i8* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i32, i32* %2
%15 = sub nsw i32 %5, %14
br label %16
16: ; preds = %8, %4, %13
%17 = phi i32 [ %15, %13 ], [ -1, %4 ], [ -1, %8 ]
ret i32 %17
}