#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_ccntlv_prependBlob(int, unsigned char *, int, int *,
                                   unsigned char *);
scalar_t__ ccnl_ccntlv_prependName(struct ccnl_prefix_s *, int *,
                                   unsigned char *, unsigned int *);
scalar_t__ ccnl_ccntlv_prependTL(int, int, int *, unsigned char *);
int ccnl_ccntlv_prependContent(struct ccnl_prefix_s *name,
                               unsigned char *payload, int paylen,
                               unsigned int *lastchunknum, int *contentpos,
                               int *offset, unsigned char *buf) {
  int tloffset = *offset;
  if (contentpos)
    *contentpos = *offset - paylen;
  if (ccnl_ccntlv_prependBlob(0x0001, payload, paylen, offset, buf) < 0)
    return -1;
  if (ccnl_ccntlv_prependName(name, offset, buf, lastchunknum))
    return -1;
  if (ccnl_ccntlv_prependTL(0x0002, tloffset - *offset, offset, buf) < 0)
    return -1;
  return tloffset - *offset;
}


x86 assembly (clang, -O0):
<ccnl_ccntlv_prependContent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1176 <ccnl_ccntlv_prependContent+0x46>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
sub    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    0x10(%rbp),%r8
mov    $0x1,%edi
call   1030 <ccnl_ccntlv_prependBlob@plt>
cmp    $0x0,%rax
jge    11a5 <ccnl_ccntlv_prependContent+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <ccnl_ccntlv_prependContent+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <ccnl_ccntlv_prependName@plt>
cmp    $0x0,%rax
je     11d0 <ccnl_ccntlv_prependContent+0xa0>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <ccnl_ccntlv_prependContent+0xdd>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rax
sub    (%rax),%esi
mov    -0x38(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    $0x2,%edi
call   1040 <ccnl_ccntlv_prependTL@plt>
cmp    $0x0,%rax
jge    1201 <ccnl_ccntlv_prependContent+0xd1>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <ccnl_ccntlv_prependContent+0xdd>
mov    -0x3c(%rbp),%eax
mov    -0x38(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_ccntlv_prependContent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %rcx,%r15
mov    %rdi,%r12
mov    0x40(%rsp),%r14
mov    (%r9),%r13d
test   %r8,%r8
je     1159 <ccnl_ccntlv_prependContent+0x29>
mov    %r13d,%eax
sub    %edx,%eax
mov    %eax,(%r8)
mov    $0x1,%edi
mov    %rbx,%rcx
mov    %r14,%r8
call   1030 <ccnl_ccntlv_prependBlob@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     11a9 <ccnl_ccntlv_prependContent+0x79>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <ccnl_ccntlv_prependName@plt>
test   %rax,%rax
jne    11a9 <ccnl_ccntlv_prependContent+0x79>
mov    %r13d,%esi
sub    (%rbx),%esi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <ccnl_ccntlv_prependTL@plt>
test   %rax,%rax
js     11a9 <ccnl_ccntlv_prependContent+0x79>
sub    (%rbx),%r13d
mov    %r13d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ccnl_prefix_s = type { i32 }
define i32 @ccnl_ccntlv_prependContent(%struct.ccnl_prefix_s* %0, i8* %1, i32 %2, i32* %3, i32* %4, i32* %5, i8* %6) {
%8 = alloca i32
%9 = alloca %struct.ccnl_prefix_s*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i32
store %struct.ccnl_prefix_s* %0, %struct.ccnl_prefix_s** %9
store i8* %1, i8** %10
store i32 %2, i32* %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i8* %6, i8** %15
%17 = load i32*, i32** %14
%18 = load i32, i32* %17
store i32 %18, i32* %16
%19 = load i32*, i32** %13
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %7
%22 = load i32*, i32** %14
%23 = load i32, i32* %22
%24 = load i32, i32* %11
%25 = sub nsw i32 %23, %24
%26 = load i32*, i32** %13
store i32 %25, i32* %26
br label %27
27: ; preds = %21, %7
%28 = load i8*, i8** %10
%29 = load i32, i32* %11
%30 = load i32*, i32** %14
%31 = load i8*, i8** %15
%32 = call i64 @ccnl_ccntlv_prependBlob(i32 1, i8* %28, i32 %29, i32* %30, i8* %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 -1, i32* %8
br label %58
35: ; preds = %27
%36 = load %struct.ccnl_prefix_s*, %struct.ccnl_prefix_s** %9
%37 = load i32*, i32** %14
%38 = load i8*, i8** %15
%39 = load i32*, i32** %12
%40 = call i64 @ccnl_ccntlv_prependName(%struct.ccnl_prefix_s* %36, i32* %37, i8* %38, i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %35
store i32 -1, i32* %8
br label %58
43: ; preds = %35
%44 = load i32, i32* %16
%45 = load i32*, i32** %14
%46 = load i32, i32* %45
%47 = sub nsw i32 %44, %46
%48 = load i32*, i32** %14
%49 = load i8*, i8** %15
%50 = call i64 @ccnl_ccntlv_prependTL(i32 2, i32 %47, i32* %48, i8* %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %43
store i32 -1, i32* %8
br label %58
53: ; preds = %43
%54 = load i32, i32* %16
%55 = load i32*, i32** %14
%56 = load i32, i32* %55
%57 = sub nsw i32 %54, %56
store i32 %57, i32* %8
br label %58
58: ; preds = %53, %52, %42, %34
%59 = load i32, i32* %8
ret i32 %59
}

LLVM IR (-O2):
%struct.ccnl_prefix_s = type { i32 }
define i32 @ccnl_ccntlv_prependContent(%struct.ccnl_prefix_s* %0, i8* %1, i32 %2, i32* %3, i32* writeonly %4, i32* %5, i8* %6) {
%8 = load i32, i32* %5
%9 = icmp eq i32* %4, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = sub nsw i32 %8, %2
store i32 %11, i32* %4
br label %12
12: ; preds = %10, %7
%13 = tail call i64 @ccnl_ccntlv_prependBlob(i32 1, i8* %1, i32 %2, i32* %5, i8* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = tail call i64 @ccnl_ccntlv_prependName(%struct.ccnl_prefix_s* %0, i32* %5, i8* %6, i32* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sub nsw i32 %8, %19
%21 = tail call i64 @ccnl_ccntlv_prependTL(i32 2, i32 %20, i32* %5, i8* %6)
%22 = icmp slt i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i32, i32* %5
%25 = sub nsw i32 %8, %24
br label %26
26: ; preds = %18, %15, %12, %23
%27 = phi i32 [ %25, %23 ], [ -1, %12 ], [ -1, %15 ], [ -1, %18 ]
ret i32 %27
}