#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 */
int ccnl_ccnb_mkHeader(unsigned char *, int, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int ccnl_ccnb_mkComponent(unsigned char *val, int vallen, unsigned char *out) {
  int len;
  len = ccnl_ccnb_mkHeader(out, 15, 2);
  len += ccnl_ccnb_mkHeader(out + len, vallen, 5);
  memcpy(out + len, val, vallen);
  len += vallen;
  out[len++] = 0;
  return len;
}


x86 assembly (clang, -O0):
<ccnl_ccnb_mkComponent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xf,%esi
mov    $0x2,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
mov    $0x5,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_ccnb_mkComponent>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%r15
mov    %rdx,%rdi
mov    $0xf,%esi
mov    $0x2,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%rdi
mov    %r12d,%esi
mov    $0x5,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
add    %eax,%ebx
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <memcpy@plt>
mov    %ebx,%ecx
add    %r12d,%ecx
lea    (%r12,%rbx,1),%eax
add    $0x1,%eax
movslq %ecx,%rcx
movb   $0x0,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @ccnl_ccnb_mkComponent(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @ccnl_ccnb_mkHeader(i8* %8, i32 15, i32 2)
store i32 %9, i32* %7
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i32, i32* %5
%15 = call i32 @ccnl_ccnb_mkHeader(i8* %13, i32 %14, i32 5)
%16 = load i32, i32* %7
%17 = add nsw i32 %16, %15
store i32 %17, i32* %7
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = call i32 @memcpy(i8* %21, i8* %22, i32 %23)
%25 = load i32, i32* %5
%26 = load i32, i32* %7
%27 = add nsw i32 %26, %25
store i32 %27, i32* %7
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %7
ret i32 %33
}

LLVM IR (-O2):
define i32 @ccnl_ccnb_mkComponent(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @ccnl_ccnb_mkHeader(i8* %2, i32 15, i32 2)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %2, i64 %5
%7 = tail call i32 @ccnl_ccnb_mkHeader(i8* %6, i32 %1, i32 5)
%8 = add nsw i32 %7, %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = tail call i32 @memcpy(i8* %10, i8* %0, i32 %1)
%12 = add nsw i32 %8, %1
%13 = add nsw i32 %12, 1
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
store i8 0, i8* %15
ret i32 %13
}