#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 */
scalar_t__ ccnl_ccnb_mkHeader(unsigned char *, int, int);
scalar_t__ ccnl_ccnb_mkStrBlob(unsigned char *, int, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int split_string(char *, char, char *);
int add_ccnl_name(unsigned char *out, char *ccn_path) {
  char comp[256];
  int len = 0, len2 = 0;
  int h;
  memset(comp, 0, 256);
  len += ccnl_ccnb_mkHeader(out + len, 14, 2);
  while ((h = split_string(ccn_path + len2, '/', comp))) {
    len2 += h;
    len += ccnl_ccnb_mkStrBlob(out + len, 15, 2, comp);
    memset(comp, 0, 256);
  }
  out[len++] = 0;
  return len;
}


x86 assembly (clang, -O0):
<add_ccnl_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x114(%rbp)
movl   $0x0,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
movslq -0x114(%rbp),%rax
add    %rax,%rdi
mov    $0xe,%esi
mov    $0x2,%edx
call   1060 <ccnl_ccnb_mkHeader@plt>
mov    %rax,%rcx
movslq -0x114(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x114(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x118(%rbp),%rax
add    %rax,%rdi
lea    -0x110(%rbp),%rdx
mov    $0x2f,%esi
call   1030 <split_string@plt>
mov    %eax,-0x11c(%rbp)
cmp    $0x0,%eax
je     1239 <add_ccnl_name+0xf9>
mov    -0x11c(%rbp),%eax
add    -0x118(%rbp),%eax
mov    %eax,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x114(%rbp),%rax
add    %rax,%rdi
lea    -0x110(%rbp),%rcx
mov    $0xf,%esi
mov    $0x2,%edx
call   1050 <ccnl_ccnb_mkStrBlob@plt>
mov    %rax,%rcx
movslq -0x114(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
jmp    11aa <add_ccnl_name+0x6a>
mov    -0x8(%rbp),%rax
mov    -0x114(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x114(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x114(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_ccnl_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%r12
xor    %r13d,%r13d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0xe,%esi
mov    $0x2,%edx
call   1060 <ccnl_ccnb_mkHeader@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x2f,%esi
mov    %r12,%rdx
call   1030 <split_string@plt>
test   %eax,%eax
je     11e8 <add_ccnl_name+0xa8>
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
add    %eax,%r13d
movslq %ebx,%rbp
lea    (%r14,%rbp,1),%rdi
mov    $0xf,%esi
mov    $0x2,%edx
mov    %r12,%rcx
call   1050 <ccnl_ccnb_mkStrBlob@plt>
mov    %rax,%rbx
add    %rbp,%rbx
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
movslq %r13d,%rdi
add    %r15,%rdi
mov    $0x2f,%esi
mov    %r12,%rdx
call   1030 <split_string@plt>
test   %eax,%eax
jne    11a0 <add_ccnl_name+0x60>
movslq %ebx,%rax
add    $0x1,%ebx
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @add_ccnl_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %7
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 256)
%11 = load i8*, i8** %3
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = call i64 @ccnl_ccnb_mkHeader(i8* %14, i32 14, i32 2)
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = add nsw i64 %17, %15
%19 = trunc i64 %18 to i32
store i32 %19, i32* %6
br label %20
20: ; preds = %28, %2
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%26 = call i32 @split_string(i8* %24, i8 signext 47, i8* %25)
store i32 %26, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %20
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = add nsw i32 %30, %29
store i32 %31, i32* %7
%32 = load i8*, i8** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%37 = call i64 @ccnl_ccnb_mkStrBlob(i8* %35, i32 15, i32 2, i8* %36)
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = add nsw i64 %39, %37
%41 = trunc i64 %40 to i32
store i32 %41, i32* %6
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%43 = call i32 @memset(i8* %42, i32 0, i32 256)
br label %20
44: ; preds = %20
%45 = load i8*, i8** %3
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8 0, i8* %49
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
define i32 @add_ccnl_name(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 256)
%6 = call i64 @ccnl_ccnb_mkHeader(i8* %0, i32 14, i32 2)
%7 = call i32 @split_string(i8* %1, i8 signext 47, i8* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %2, %9
%10 = phi i32 [ %22, %9 ], [ %7, %2 ]
%11 = phi i64 [ %18, %9 ], [ %6, %2 ]
%12 = phi i32 [ %13, %9 ], [ 0, %2 ]
%13 = add nsw i32 %10, %12
%14 = shl i64 %11, 32
%15 = ashr exact i64 %14, 32
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = call i64 @ccnl_ccnb_mkStrBlob(i8* %16, i32 15, i32 2, i8* %4)
%18 = add nsw i64 %17, %15
%19 = call i32 @memset(i8* %4, i32 0, i32 256)
%20 = sext i32 %13 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = call i32 @split_string(i8* %21, i8 signext 47, i8* %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %9
24: ; preds = %9, %2
%25 = phi i64 [ %6, %2 ], [ %18, %9 ]
%26 = trunc i64 %25 to i32
%27 = add nsw i32 %26, 1
%28 = shl i64 %25, 32
%29 = ashr exact i64 %28, 32
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 0, i8* %30
ret i32 %27
}