#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 ASNDerWriteLength(unsigned char *, long);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, long);
int ASNDerWriteToken(unsigned char *pbData, unsigned char ucType,
                     unsigned char *pbTokenValue, long nLength) {
  int nTotalBytesWrittenOut = 0L;
  int nNumLengthBytesWritten = 0L;
  *pbData = ucType;
  nTotalBytesWrittenOut++;
  pbData++;
  nNumLengthBytesWritten = ASNDerWriteLength(pbData, nLength);
  nTotalBytesWrittenOut += nNumLengthBytesWritten;
  pbData += nNumLengthBytesWritten;
  if (NULL != pbTokenValue) {
    memcpy(pbData, pbTokenValue, nLength);
    nTotalBytesWrittenOut += nLength;
  }
  return nTotalBytesWrittenOut;
}


x86 assembly (clang, -O0):
<ASNDerWriteToken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <ASNDerWriteLength@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     11bb <ASNDerWriteToken+0x9b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASNDerWriteToken>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %sil,(%rdi)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %rcx,%rsi
call   1040 <ASNDerWriteLength@plt>
lea    0x1(%rax),%ebp
test   %r14,%r14
je     1160 <ASNDerWriteToken+0x40>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <memcpy@plt>
add    %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ASNDerWriteToken(i8* %0, i8 zeroext %1, i8* %2, i64 %3) {
store i8 %1, i8* %0
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = tail call i32 @ASNDerWriteLength(i8* %5, i64 %3)
%7 = add nsw i32 %6, 1
%8 = icmp eq i8* %2, null
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds i8, i8* %5, i64 %10
%12 = tail call i32 @memcpy(i8* %11, i8* %2, i64 %3)
%13 = trunc i64 %3 to i32
%14 = add i32 %7, %13
br label %15
15: ; preds = %9, %4
%16 = phi i32 [ %14, %9 ], [ %7, %4 ]
ret i32 %16
}