#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_ccntlv_prependTL(unsigned short, unsigned short, int *,
                                 unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned short);
int ccnl_ccntlv_prependBlob(unsigned short type, unsigned char *blob,
                            unsigned short len, int *offset,
                            unsigned char *buf) {
  if (*offset < (len + 4))
    return -1;
  *offset -= len;
  memcpy(buf + *offset, blob, len);
  if (ccnl_ccntlv_prependTL(type, len, offset, buf) < 0)
    return -1;
  return len + 4;
}


x86 assembly (clang, -O0):
<ccnl_ccntlv_prependBlob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %di,%dx
mov    %dx,-0x6(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
movzwl -0x12(%rbp),%ecx
add    $0x4,%ecx
cmp    %ecx,%eax
jge    1163 <ccnl_ccntlv_prependBlob+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <ccnl_ccntlv_prependBlob+0xaa>
movzwl -0x12(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x12(%rbp),%ax
movzwl %ax,%edx
call   1030 <memcpy@plt>
mov    -0x6(%rbp),%si
mov    -0x12(%rbp),%ax
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
movzwl %si,%edi
movzwl %ax,%esi
call   1040 <ccnl_ccntlv_prependTL@plt>
cmp    $0x0,%rax
jge    11c0 <ccnl_ccntlv_prependBlob+0xa0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <ccnl_ccntlv_prependBlob+0xaa>
movzwl -0x12(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_ccntlv_prependBlob>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    (%rcx),%ecx
lea    0x4(%rdx),%ebp
mov    $0xffffffff,%eax
cmp    %ebp,%ecx
jl     1174 <ccnl_ccntlv_prependBlob+0x54>
mov    %r8,%r14
mov    %edi,%r15d
sub    %edx,%ecx
mov    %ecx,(%rbx)
movslq %ecx,%rdi
add    %r8,%rdi
movzwl %dx,%r12d
mov    %r12d,%edx
call   1030 <memcpy@plt>
movzwl %r15w,%edi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <ccnl_ccntlv_prependTL@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovs  %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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