#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 */
void *htons(unsigned int);
int ccnl_cistlv_prependTL(unsigned int type, unsigned short len, int *offset,
                          unsigned char *buf) {
  unsigned short *ip;
  if (*offset < 4)
    return -1;
  ip = (unsigned short *)(buf + *offset - 2);
  *ip-- = htons(len);
  *ip = htons(type);
  *offset -= 4;
  return 4;
}


x86 assembly (clang, -O0):
<ccnl_cistlv_prependTL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %edi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x4,(%rax)
jge    1143 <ccnl_cistlv_prependTL+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <ccnl_cistlv_prependTL+0x8b>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x28(%rbp)
movzwl -0xa(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0xfffffffffffffffe,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
mov    -0x8(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %cx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    $0x4,%ecx
mov    %ecx,(%rax)
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_cistlv_prependTL>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdx),%ebp
mov    $0xffffffff,%eax
cmp    $0x4,%ebp
jl     1150 <ccnl_cistlv_prependTL+0x40>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%r15d
movzwl %si,%edi
call   1030 <htons@plt>
mov    %ax,-0x2(%r14,%rbp,1)
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %ax,-0x4(%r14,%rbp,1)
addl   $0xfffffffc,(%rbx)
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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