#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_mkField(unsigned char *out, unsigned int num, int typ,
                      unsigned char *data, int datalen) {
  int len;
  len = ccnl_ccnb_mkHeader(out, num, 2);
  len += ccnl_ccnb_mkHeader(out + len, datalen, typ);
  memcpy(out + len, data, datalen);
  len += datalen;
  out[len++] = 0;
  return len;
}


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

x86 assembly (clang, -O2):
<ccnl_ccnb_mkField>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rdi,%rbx
mov    $0x2,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
movslq %eax,%rbp
lea    (%rbx,%rbp,1),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
add    %eax,%ebp
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
mov    %ebp,%ecx
add    %r14d,%ecx
lea    (%r14,%rbp,1),%eax
add    $0x1,%eax
movslq %ecx,%rcx
movb   $0x0,(%rbx,%rcx,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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