#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 */
int ccnl_ccnb_mkHeader(unsigned char *, int, int);
scalar_t__ ccnl_ccnb_mkName(struct ccnl_prefix_s *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, void *, int);
int ccnl_ccnb_fillInterest(struct ccnl_prefix_s *name, int *nonce,
                           unsigned char *out, int outlen) {
  (void)outlen;
  int len = 0;
  len = ccnl_ccnb_mkHeader(out, 26, 2);
  len += ccnl_ccnb_mkName(name, out + len);
  if (nonce) {
    len += ccnl_ccnb_mkHeader(out + len, 41, 2);
    len += ccnl_ccnb_mkHeader(out + len, sizeof(unsigned int), 5);
    memcpy(out + len, (void *)nonce, sizeof(unsigned int));
    len += sizeof(unsigned int);
  }
  out[len++] = 0;
  return len;
}


x86 assembly (clang, -O0):
<ccnl_ccnb_fillInterest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1a,%esi
mov    $0x2,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
call   1050 <ccnl_ccnb_mkName@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f4 <ccnl_ccnb_fillInterest+0xc4>
mov    -0x18(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    $0x29,%esi
mov    $0x2,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movslq -0x20(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x20(%rbp)
mov    -0x18(%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_fillInterest>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,%rdi
mov    $0x1a,%esi
mov    $0x2,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
movslq %eax,%rbx
lea    (%r15,%rbx,1),%rsi
mov    %r12,%rdi
call   1050 <ccnl_ccnb_mkName@plt>
add    %eax,%ebx
test   %r14,%r14
je     11b7 <ccnl_ccnb_fillInterest+0x87>
movslq %ebx,%rbx
lea    (%r15,%rbx,1),%rdi
mov    $0x29,%esi
mov    $0x2,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
add    %eax,%ebx
movslq %ebx,%rbx
lea    (%r15,%rbx,1),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1040 <ccnl_ccnb_mkHeader@plt>
mov    %eax,%r12d
lea    (%rbx,%r12,1),%eax
movslq %eax,%rdi
add    %r15,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
add    %r12d,%ebx
add    $0x4,%ebx
movslq %ebx,%rax
add    $0x1,%ebx
movb   $0x0,(%r15,%rax,1)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ccnl_prefix_s = type { i32 }
define i32 @ccnl_ccnb_fillInterest(%struct.ccnl_prefix_s* %0, i32* %1, i8* %2, i32 %3) {
%5 = tail call i32 @ccnl_ccnb_mkHeader(i8* %2, i32 26, i32 2)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = tail call i64 @ccnl_ccnb_mkName(%struct.ccnl_prefix_s* %0, i8* %7)
%9 = trunc i64 %8 to i32
%10 = add i32 %5, %9
%11 = icmp eq i32* %1, null
br i1 %11, label %26, label %12
12: ; preds = %4
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %13
%15 = tail call i32 @ccnl_ccnb_mkHeader(i8* %14, i32 41, i32 2)
%16 = add nsw i32 %15, %10
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %2, i64 %17
%19 = tail call i32 @ccnl_ccnb_mkHeader(i8* %18, i32 4, i32 5)
%20 = add nsw i32 %16, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %2, i64 %21
%23 = bitcast i32* %1 to i8*
%24 = tail call i32 @memcpy(i8* %22, i8* %23, i32 4)
%25 = add i32 %20, 4
br label %26
26: ; preds = %12, %4
%27 = phi i32 [ %25, %12 ], [ %10, %4 ]
%28 = add nsw i32 %27, 1
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %2, i64 %29
store i8 0, i8* %30
ret i32 %28
}