#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 asn1_get_length_der(unsigned char const *, int, int *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int asn1_get_bit_der(const unsigned char *der, int der_len, int *ret_len,
                     unsigned char *str, int str_size, int *bit_len) {
  int len_len, len_byte;
  if (der_len <= 0)
    return 6;
  len_byte = asn1_get_length_der(der, der_len, &len_len) - 1;
  if (len_byte < 0)
    return 4;
  *ret_len = len_byte + len_len + 1;
  *bit_len = len_byte * 8 - der[len_len];
  if (str_size >= len_byte)
    memcpy(str, der + len_len + 1, len_byte);
  else {
    return 12;
  }
  return 0;
}


x86 assembly (clang, -O0):
<asn1_get_bit_der>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1155 <asn1_get_bit_der+0x35>
movl   $0x6,-0x4(%rbp)
jmp    11e9 <asn1_get_bit_der+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x3c(%rbp),%rdx
call   1040 <asn1_get_length_der@plt>
sub    $0x1,%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1181 <asn1_get_bit_der+0x61>
movl   $0x4,-0x4(%rbp)
jmp    11e9 <asn1_get_bit_der+0xc9>
mov    -0x40(%rbp),%ecx
add    -0x3c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%ecx
shl    $0x3,%ecx
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rdx
movzbl (%rax,%rdx,1),%eax
sub    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jl     11d6 <asn1_get_bit_der+0xb6>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x40(%rbp),%edx
call   1030 <memcpy@plt>
jmp    11e2 <asn1_get_bit_der+0xc2>
movl   $0xc,-0x4(%rbp)
jmp    11e9 <asn1_get_bit_der+0xc9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_get_bit_der>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    118e <asn1_get_bit_der+0x6e>
mov    %r9,%r12
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdx
call   1040 <asn1_get_length_der@plt>
test   %eax,%eax
jle    1195 <asn1_get_bit_der+0x75>
movslq 0xc(%rsp),%rdx
lea    (%rdx,%rax,1),%ecx
add    $0xffffffff,%eax
mov    %ecx,0x0(%rbp)
lea    0x0(,%rax,8),%ecx
movzbl (%rbx,%rdx,1),%esi
sub    %esi,%ecx
mov    %ecx,(%r12)
mov    $0xc,%ecx
cmp    %r15d,%eax
jg     119a <asn1_get_bit_der+0x7a>
add    %rdx,%rbx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <memcpy@plt>
xor    %ecx,%ecx
jmp    119a <asn1_get_bit_der+0x7a>
mov    $0x6,%ecx
jmp    119a <asn1_get_bit_der+0x7a>
mov    $0x4,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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