#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 */
typedef struct TYPE_8__ TYPE_3__;
typedef struct TYPE_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct TYPE_8__ {
  int offset;
  int tblcount;
  TYPE_1__ const *default_tt;
  TYPE_2__ *tbl;
  TYPE_1__ const *null_tt;
};
struct TYPE_6__ {
  int flags;
  scalar_t__ item;
};
struct TYPE_7__ {
  long value;
  TYPE_1__ const tt;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_1__ ASN1_TEMPLATE;
typedef int /*<<< orphan*/ ASN1_OBJECT;
typedef int /*<<< orphan*/ ASN1_INTEGER;
typedef TYPE_2__ ASN1_ADB_TABLE;
typedef TYPE_3__ ASN1_ADB;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_DO_ADB;
long ASN1_INTEGER_get(int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE;
int ASN1_TFLG_ADB_MASK;
int ASN1_TFLG_ADB_OID;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
long OBJ_obj2nid(int /*<<< orphan*/ *);
const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
                                 int nullerr) {
  const ASN1_ADB *adb;
  const ASN1_ADB_TABLE *atbl;
  long selector;
  ASN1_VALUE **sfld;
  int i;
  if (!(tt->flags & ASN1_TFLG_ADB_MASK))
    return tt;
  adb = (const ASN1_ADB *)tt->item;
  sfld = (void *)(((char *)*pval) + adb->offset);
  if (!sfld) {
    if (!adb->null_tt)
      goto err;
    return adb->null_tt;
  }
  if (tt->flags & ASN1_TFLG_ADB_OID)
    selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
  else
    selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
  for (atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
    if (atbl->value == selector)
      return &atbl->tt;
  if (!adb->default_tt)
    goto err;
  return adb->default_tt;
err:
  if (nullerr)
    ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
  return NULL;
}


x86 assembly (clang, -O0):
<asn1_do_adb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e70(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1168 <asn1_do_adb+0x38>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a8 <asn1_do_adb+0x178>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11b9 <asn1_do_adb+0x89>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x18(%rax)
jne    11a8 <asn1_do_adb+0x78>
jmp    127f <asn1_do_adb+0x14f>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12a8 <asn1_do_adb+0x178>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e12(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e6 <asn1_do_adb+0xb6>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
call   1030 <OBJ_obj2nid@plt>
mov    %rax,-0x38(%rbp)
jmp    11f6 <asn1_do_adb+0xc6>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
call   1050 <ASN1_INTEGER_get@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    0x4(%rcx),%eax
jge    125a <asn1_do_adb+0x12a>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
cmp    -0x38(%rbp),%rax
jne    123b <asn1_do_adb+0x10b>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    12a8 <asn1_do_adb+0x178>
jmp    1240 <asn1_do_adb+0x110>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x30(%rbp)
jmp    1209 <asn1_do_adb+0xd9>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    126e <asn1_do_adb+0x13e>
jmp    127f <asn1_do_adb+0x14f>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12a8 <asn1_do_adb+0x178>
cmpl   $0x0,-0x1c(%rbp)
je     12a0 <asn1_do_adb+0x170>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_do_adb>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rax
mov    (%rsi),%ecx
mov    0x2e7f(%rip),%rdx
test   %ecx,(%rdx)
je     11c5 <asn1_do_adb+0x95>
mov    0x8(%rax),%rbx
mov    (%rdi),%rax
test   %rax,%rax
je     116e <asn1_do_adb+0x3e>
movslq (%rbx),%rdx
mov    0x2e79(%rip),%rsi
mov    (%rax,%rdx,1),%rdi
test   %ecx,(%rsi)
je     1179 <asn1_do_adb+0x49>
call   1030 <OBJ_obj2nid@plt>
jmp    117e <asn1_do_adb+0x4e>
mov    0x18(%rbx),%rax
test   %rax,%rax
jne    11c5 <asn1_do_adb+0x95>
jmp    11a8 <asn1_do_adb+0x78>
call   1050 <ASN1_INTEGER_get@plt>
mov    %rax,%rcx
mov    0x4(%rbx),%edx
test   %edx,%edx
jle    119f <asn1_do_adb+0x6f>
mov    0x10(%rbx),%rax
add    $0x8,%rax
cmp    %rcx,-0x8(%rax)
je     11c5 <asn1_do_adb+0x95>
add    $0x18,%rax
add    $0xffffffff,%edx
jne    1190 <asn1_do_adb+0x60>
mov    0x8(%rbx),%rax
test   %rax,%rax
jne    11c5 <asn1_do_adb+0x95>
test   %ebp,%ebp
je     11c3 <asn1_do_adb+0x93>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i64 }
%struct.TYPE_8__ = type { i32, i32, %struct.TYPE_6__*, %struct.TYPE_7__*, %struct.TYPE_6__* }
%struct.TYPE_7__ = type { i64, %struct.TYPE_6__ }
@ASN1_TFLG_ADB_MASK = global i32 0
@ASN1_TFLG_ADB_OID = global i32 0
@ASN1_F_ASN1_DO_ADB = global i32 0
@ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE = global i32 0
define %struct.TYPE_6__* @asn1_do_adb(i32** %0, %struct.TYPE_6__* %1, i32 %2) {
%4 = alloca %struct.TYPE_6__*
%5 = alloca i32**
%6 = alloca %struct.TYPE_6__*
%7 = alloca i32
%8 = alloca %struct.TYPE_8__*
%9 = alloca %struct.TYPE_7__*
%10 = alloca i64
%11 = alloca i32**
%12 = alloca i32
store i32** %0, i32*** %5
store %struct.TYPE_6__* %1, %struct.TYPE_6__** %6
store i32 %2, i32* %7
%13 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* @ASN1_TFLG_ADB_MASK
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %3
%20 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
store %struct.TYPE_6__* %20, %struct.TYPE_6__** %4
br label %105
21: ; preds = %3
%22 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%23 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to %struct.TYPE_8__*
store %struct.TYPE_8__* %25, %struct.TYPE_8__** %8
%26 = load i32**, i32*** %5
%27 = load i32*, i32** %26
%28 = bitcast i32* %27 to i8*
%29 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%30 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = bitcast i8* %33 to i32**
store i32** %34, i32*** %11
%35 = load i32**, i32*** %11
%36 = icmp ne i32** %35, null
br i1 %36, label %47, label %37
37: ; preds = %21
%38 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%39 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %38, i32 0, i32 4
%40 = load %struct.TYPE_6__*, %struct.TYPE_6__** %39
%41 = icmp ne %struct.TYPE_6__* %40, null
br i1 %41, label %43, label %42
42: ; preds = %37
br label %97
43: ; preds = %37
%44 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%45 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %44, i32 0, i32 4
%46 = load %struct.TYPE_6__*, %struct.TYPE_6__** %45
store %struct.TYPE_6__* %46, %struct.TYPE_6__** %4
br label %105
47: ; preds = %21
%48 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%49 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = load i32, i32* @ASN1_TFLG_ADB_OID
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %47
%55 = load i32**, i32*** %11
%56 = load i32*, i32** %55
%57 = call i64 @OBJ_obj2nid(i32* %56)
store i64 %57, i64* %10
br label %62
58: ; preds = %47
%59 = load i32**, i32*** %11
%60 = load i32*, i32** %59
%61 = call i64 @ASN1_INTEGER_get(i32* %60)
store i64 %61, i64* %10
br label %62
62: ; preds = %58, %54
%63 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%64 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %63, i32 0, i32 3
%65 = load %struct.TYPE_7__*, %struct.TYPE_7__** %64
store %struct.TYPE_7__* %65, %struct.TYPE_7__** %9
store i32 0, i32* %12
br label %66
66: ; preds = %82, %62
%67 = load i32, i32* %12
%68 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%69 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %68, i32 0, i32 1
%70 = load i32, i32* %69
%71 = icmp slt i32 %67, %70
br i1 %71, label %72, label %87
72: ; preds = %66
%73 = load %struct.TYPE_7__*, %struct.TYPE_7__** %9
%74 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %73, i32 0, i32 0
%75 = load i64, i64* %74
%76 = load i64, i64* %10
%77 = icmp eq i64 %75, %76
br i1 %77, label %78, label %81
78: ; preds = %72
%79 = load %struct.TYPE_7__*, %struct.TYPE_7__** %9
%80 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %79, i32 0, i32 1
store %struct.TYPE_6__* %80, %struct.TYPE_6__** %4
br label %105
81: ; preds = %72
br label %82
82: ; preds = %81
%83 = load i32, i32* %12
%84 = add nsw i32 %83, 1
store i32 %84, i32* %12
%85 = load %struct.TYPE_7__*, %struct.TYPE_7__** %9
%86 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %85, i32 1
store %struct.TYPE_7__* %86, %struct.TYPE_7__** %9
br label %66
87: ; preds = %66
%88 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%89 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %88, i32 0, i32 2
%90 = load %struct.TYPE_6__*, %struct.TYPE_6__** %89
%91 = icmp ne %struct.TYPE_6__* %90, null
br i1 %91, label %93, label %92
92: ; preds = %87
br label %97
93: ; preds = %87
%94 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%95 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %94, i32 0, i32 2
%96 = load %struct.TYPE_6__*, %struct.TYPE_6__** %95
store %struct.TYPE_6__* %96, %struct.TYPE_6__** %4
br label %105
97: ; preds = %92, %42
%98 = load i32, i32* %7
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %104
100: ; preds = %97
%101 = load i32, i32* @ASN1_F_ASN1_DO_ADB
%102 = load i32, i32* @ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE
%103 = call i32 @ASN1err(i32 %101, i32 %102)
br label %104
104: ; preds = %100, %97
store %struct.TYPE_6__* null, %struct.TYPE_6__** %4
br label %105
105: ; preds = %104, %93, %78, %43, %19
%106 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
ret %struct.TYPE_6__* %106
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i64 }
%struct.TYPE_8__ = type { i32, i32, %struct.TYPE_6__*, %struct.TYPE_7__*, %struct.TYPE_6__* }
%struct.TYPE_7__ = type { i64, %struct.TYPE_6__ }
@ASN1_TFLG_ADB_MASK = global i32 0
@ASN1_TFLG_ADB_OID = global i32 0
@ASN1_F_ASN1_DO_ADB = global i32 0
@ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE = global i32 0
define %struct.TYPE_6__* @asn1_do_adb(i32** nocapture %0, %struct.TYPE_6__* %1, i32 %2) {
%4 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = load i32, i32* @ASN1_TFLG_ADB_MASK
%7 = and i32 %6, %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %64, label %9
9: ; preds = %3
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to %struct.TYPE_8__*
%13 = bitcast i32** %0 to i8**
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %12, i64 0, i32 4
%18 = load %struct.TYPE_6__*, %struct.TYPE_6__** %17
%19 = icmp eq %struct.TYPE_6__* %18, null
br i1 %19, label %58, label %64
20: ; preds = %9
%21 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %12, i64 0, i32 0
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %14, i64 %23
%25 = bitcast i8* %24 to i32**
%26 = load i32, i32* @ASN1_TFLG_ADB_OID
%27 = and i32 %26, %5
%28 = icmp eq i32 %27, 0
%29 = load i32*, i32** %25
br i1 %28, label %32, label %30
30: ; preds = %20
%31 = tail call i64 @OBJ_obj2nid(i32* %29)
br label %34
32: ; preds = %20
%33 = tail call i64 @ASN1_INTEGER_get(i32* %29)
br label %34
34: ; preds = %32, %30
%35 = phi i64 [ %31, %30 ], [ %33, %32 ]
%36 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %12, i64 0, i32 1
%37 = load i32, i32* %36
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %54
39: ; preds = %34
%40 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %12, i64 0, i32 3
%41 = load %struct.TYPE_7__*, %struct.TYPE_7__** %40
br label %42
42: ; preds = %39, %50
%43 = phi i32 [ %51, %50 ], [ 0, %39 ]
%44 = phi %struct.TYPE_7__* [ %52, %50 ], [ %41, %39 ]
%45 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %44, i64 0, i32 0
%46 = load i64, i64* %45
%47 = icmp eq i64 %46, %35
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %44, i64 0, i32 1
br label %64
50: ; preds = %42
%51 = add nuw nsw i32 %43, 1
%52 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %44, i64 1
%53 = icmp eq i32 %51, %37
br i1 %53, label %54, label %42
54: ; preds = %50, %34
%55 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %12, i64 0, i32 2
%56 = load %struct.TYPE_6__*, %struct.TYPE_6__** %55
%57 = icmp eq %struct.TYPE_6__* %56, null
br i1 %57, label %58, label %64
58: ; preds = %54, %16
%59 = icmp eq i32 %2, 0
br i1 %59, label %64, label %60
60: ; preds = %58
%61 = load i32, i32* @ASN1_F_ASN1_DO_ADB
%62 = load i32, i32* @ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE
%63 = tail call i32 @ASN1err(i32 %61, i32 %62)
br label %64
64: ; preds = %58, %60, %54, %16, %3, %48
%65 = phi %struct.TYPE_6__* [ %49, %48 ], [ %1, %3 ], [ %18, %16 ], [ %56, %54 ], [ null, %60 ], [ null, %58 ]
ret %struct.TYPE_6__* %65
}