#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 /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int ASNDerGetLength(unsigned char *pbLengthData, long nBoundaryLength,
                    long *pnLength, long *pnNumLengthBytes) {
  int nReturn = -2;
  int nNumLengthBytes = 0;
  if (*pbLengthData & 0x80) {
    nNumLengthBytes = *pbLengthData & 0x7f;
    if (nNumLengthBytes <= nBoundaryLength - 1) {
      if (nNumLengthBytes >= 1 && nNumLengthBytes <= 4) {
        *pnLength = 0L;
        pbLengthData++;
        memcpy(((unsigned char *)pnLength) + (4 - nNumLengthBytes),
               pbLengthData, nNumLengthBytes);
        *pnNumLengthBytes = nNumLengthBytes + 1;
        nReturn = 0;
      }
    }
  } else {
    *pnLength = *pbLengthData & 0x7f;
    *pnNumLengthBytes = 1;
    nReturn = 0;
  };
  return nReturn;
}


x86 assembly (clang, -O0):
<ASNDerGetLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xfffffffe,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     11d6 <ASNDerGetLength+0xc6>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jg     11d1 <ASNDerGetLength+0xc1>
cmpl   $0x1,-0x28(%rbp)
jl     11cc <ASNDerGetLength+0xbc>
cmpl   $0x4,-0x28(%rbp)
jg     11cc <ASNDerGetLength+0xbc>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4,%eax
sub    -0x28(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
jmp    11d1 <ASNDerGetLength+0xc1>
jmp    11fc <ASNDerGetLength+0xec>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x1,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASNDerGetLength>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
movzbl (%rdi),%eax
mov    %eax,%ebx
and    $0x7f,%ebx
test   $0x80,%al
jne    112d <ASNDerGetLength+0x1d>
mov    %rbx,(%rdx)
mov    $0x1,%ebx
jmp    1164 <ASNDerGetLength+0x54>
mov    $0xfffffffe,%eax
cmp    %rsi,%rbx
jge    1169 <ASNDerGetLength+0x59>
lea    -0x1(%rbx),%esi
cmp    $0x3,%esi
ja     1169 <ASNDerGetLength+0x59>
mov    %rdi,%rcx
movq   $0x0,(%rdx)
add    $0x1,%rcx
mov    $0x4,%edi
sub    %ebx,%edi
add    %rdx,%rdi
mov    %rcx,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    $0x1,%ebx
mov    %rbx,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @ASNDerGetLength(i8* %0, i64 %1, i64* %2, i64* nocapture writeonly %3) {
%5 = load i8, i8* %0
%6 = zext i8 %5 to i32
%7 = and i32 %6, 128
%8 = icmp eq i32 %7, 0
%9 = and i32 %6, 127
%10 = zext i32 %9 to i64
br i1 %8, label %25, label %11
11: ; preds = %4
%12 = icmp slt i64 %10, %1
%13 = add nsw i32 %9, -1
%14 = icmp ult i32 %13, 4
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %16, label %28
16: ; preds = %11
store i64 0, i64* %2
%17 = getelementptr inbounds i8, i8* %0, i64 1
%18 = bitcast i64* %2 to i8*
%19 = sub nuw nsw i32 4, %9
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = tail call i32 @memcpy(i8* %21, i8* %17, i32 %9)
%23 = add nuw nsw i32 %9, 1
%24 = zext i32 %23 to i64
br label %26
25: ; preds = %4
store i64 %10, i64* %2
br label %26
26: ; preds = %25, %16
%27 = phi i64 [ %24, %16 ], [ 1, %25 ]
store i64 %27, i64* %3
br label %28
28: ; preds = %26, %11
%29 = phi i32 [ -2, %11 ], [ 0, %26 ]
ret i32 %29
}