#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_addBlob(unsigned char *, char *, unsigned int);
int ccnl_ccnb_mkHeader(unsigned char *, int, int);
scalar_t__ ccnl_ccnb_mkStrBlob(unsigned char *, int, int, char *);
int /*<<< orphan*/ sign(char *, unsigned char *, unsigned int, unsigned char *,
                        unsigned int *);
int add_signature(unsigned char *out, char *private_key_path,
                  unsigned char *file, unsigned int fsize) {
  int len;
  unsigned char sig[2048];
  unsigned int sig_len;
  len = ccnl_ccnb_mkHeader(out, 37, 2);
  len += ccnl_ccnb_mkStrBlob(out + len, 14, 2, "SHA256");
  len += ccnl_ccnb_mkStrBlob(out + len, 53, 2, "");
  if (!sign(private_key_path, (unsigned char *)file, fsize,
            (unsigned char *)sig, &sig_len))
    return 0;
  sig[sig_len] = 0;
  len += ccnl_ccnb_mkHeader(out + len, 54, 2);
  len += ccnl_ccnb_addBlob(out + len, (char *)sig, sig_len);
  out[len++] = 0;
  out[len++] = 0;
  return len;
}


x86 assembly (clang, -O0):
<add_signature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
mov    $0x2,%edx
call   1060 <ccnl_ccnb_mkHeader@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    $0xe,%esi
mov    $0x2,%edx
lea    0xe74(%rip),%rcx
call   1030 <ccnl_ccnb_mkStrBlob@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    $0x35,%esi
mov    $0x2,%edx
lea    0xe4c(%rip),%rcx
call   1030 <ccnl_ccnb_mkStrBlob@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x830(%rbp),%rcx
lea    -0x834(%rbp),%r8
call   1050 <sign@plt>
cmp    $0x0,%eax
jne    11ff <add_signature+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    1289 <add_signature+0x149>
mov    -0x834(%rbp),%eax
movb   $0x0,-0x830(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    $0x36,%esi
mov    $0x2,%edx
call   1060 <ccnl_ccnb_mkHeader@plt>
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
lea    -0x830(%rbp),%rsi
mov    -0x834(%rbp),%edx
call   1040 <ccnl_ccnb_addBlob@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_signature>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    $0x25,%esi
mov    $0x2,%edx
call   1060 <ccnl_ccnb_mkHeader@plt>
movslq %eax,%rbp
lea    (%rbx,%rbp,1),%rdi
lea    0xe86(%rip),%rcx
mov    $0xe,%esi
mov    $0x2,%edx
call   1030 <ccnl_ccnb_mkStrBlob@plt>
add    %eax,%ebp
movslq %ebp,%rdi
add    %rbx,%rdi
lea    0xe6e(%rip),%rcx
mov    $0x35,%esi
mov    $0x2,%edx
call   1030 <ccnl_ccnb_mkStrBlob@plt>
mov    %rax,%r13
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <sign@plt>
test   %eax,%eax
je     1212 <add_signature+0xd2>
add    %r13d,%ebp
mov    0xc(%rsp),%eax
movb   $0x0,0x10(%rsp,%rax,1)
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%rdi
mov    $0x36,%esi
mov    $0x2,%edx
call   1060 <ccnl_ccnb_mkHeader@plt>
add    %eax,%ebp
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%rdi
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rsi
call   1040 <ccnl_ccnb_addBlob@plt>
lea    (%rax,%rbp,1),%ecx
movslq %ecx,%rcx
movw   $0x0,(%rbx,%rcx,1)
add    %ebp,%eax
add    $0x2,%eax
jmp    1214 <add_signature+0xd4>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"SHA256\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @add_signature(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2048 x i8]
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %6
%14 = call i32 @ccnl_ccnb_mkHeader(i8* %13, i32 37, i32 2)
store i32 %14, i32* %10
%15 = load i8*, i8** %6
%16 = load i32, i32* %10
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = call i64 @ccnl_ccnb_mkStrBlob(i8* %18, i32 14, i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %10
%24 = load i8*, i8** %6
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = call i64 @ccnl_ccnb_mkStrBlob(i8* %27, i32 53, i32 2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %10
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%37 = call i32 @sign(i8* %33, i8* %34, i32 %35, i8* %36, i32* %12)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %4
store i32 0, i32* %5
br label %73
40: ; preds = %4
%41 = load i32, i32* %12
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %6
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = call i32 @ccnl_ccnb_mkHeader(i8* %47, i32 54, i32 2)
%49 = load i32, i32* %10
%50 = add nsw i32 %49, %48
store i32 %50, i32* %10
%51 = load i8*, i8** %6
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%56 = load i32, i32* %12
%57 = call i64 @ccnl_ccnb_addBlob(i8* %54, i8* %55, i32 %56)
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %10
%62 = load i8*, i8** %6
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %6
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
%70 = sext i32 %68 to i64
%71 = getelementptr inbounds i8, i8* %67, i64 %70
store i8 0, i8* %71
%72 = load i32, i32* %10
store i32 %72, i32* %5
br label %73
73: ; preds = %40, %39
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@.str = [7 x i8] c"SHA256\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @add_signature(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [2048 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%8 = bitcast i32* %6 to i8*
%9 = tail call i32 @ccnl_ccnb_mkHeader(i8* %0, i32 37, i32 2)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = tail call i64 @ccnl_ccnb_mkStrBlob(i8* %11, i32 14, i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = trunc i64 %12 to i32
%14 = add i32 %9, %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i64 @ccnl_ccnb_mkStrBlob(i8* %16, i32 53, i32 2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%18 = trunc i64 %17 to i32
%19 = add i32 %14, %18
%20 = call i32 @sign(i8* %1, i8* %2, i32 %3, i8* %7, i32* %6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %42, label %22
22: ; preds = %4
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %24
store i8 0, i8* %25
%26 = sext i32 %19 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = call i32 @ccnl_ccnb_mkHeader(i8* %27, i32 54, i32 2)
%29 = add nsw i32 %28, %19
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = load i32, i32* %6
%33 = call i64 @ccnl_ccnb_addBlob(i8* %31, i8* %7, i32 %32)
%34 = trunc i64 %33 to i32
%35 = add i32 %29, %34
%36 = add nsw i32 %35, 1
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %0, i64 %37
store i8 0, i8* %38
%39 = add nsw i32 %35, 2
%40 = sext i32 %36 to i64
%41 = getelementptr inbounds i8, i8* %0, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %4, %22
%43 = phi i32 [ %39, %22 ], [ 0, %4 ]
ret i32 %43
}