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

/* Type definitions */
struct TYPE_9__ {
  int offset;
  int tblcount;
  TYPE_1__ const *default_tt;
  TYPE_2__ *tbl;
  TYPE_1__ const *null_tt;
};
struct TYPE_7__ {
  int flags;
  int /*<<< orphan*/ item;
};
struct TYPE_8__ {
  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 */
TYPE_3__ *ASN1_ADB_ptr(int /*<<< orphan*/);
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 = ASN1_ADB_ptr(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    0x2e60(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1178 <asn1_do_adb+0x38>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <asn1_do_adb+0x17c>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <ASN1_ADB_ptr@plt>
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    11cd <asn1_do_adb+0x8d>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x18(%rax)
jne    11bc <asn1_do_adb+0x7c>
jmp    1293 <asn1_do_adb+0x153>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <asn1_do_adb+0x17c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2dfe(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11fa <asn1_do_adb+0xba>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
call   1030 <OBJ_obj2nid@plt>
mov    %rax,-0x38(%rbp)
jmp    120a <asn1_do_adb+0xca>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
call   1060 <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    126e <asn1_do_adb+0x12e>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
cmp    -0x38(%rbp),%rax
jne    124f <asn1_do_adb+0x10f>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <asn1_do_adb+0x17c>
jmp    1254 <asn1_do_adb+0x114>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
jmp    121d <asn1_do_adb+0xdd>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1282 <asn1_do_adb+0x142>
jmp    1293 <asn1_do_adb+0x153>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <asn1_do_adb+0x17c>
cmpl   $0x0,-0x1c(%rbp)
je     12b4 <asn1_do_adb+0x174>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    0x2d33(%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   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rsi)
je     11e6 <asn1_do_adb+0xa6>
mov    %edx,%r14d
mov    %rdi,%rbp
mov    0x4(%rbx),%edi
call   1050 <ASN1_ADB_ptr@plt>
mov    %rax,%r15
mov    0x0(%rbp),%rax
test   %rax,%rax
je     1190 <asn1_do_adb+0x50>
movslq (%r15),%rcx
mov    0x2e59(%rip),%rdx
mov    (%rdx),%edx
mov    (%rax,%rcx,1),%rdi
test   %edx,(%rbx)
je     119b <asn1_do_adb+0x5b>
call   1030 <OBJ_obj2nid@plt>
jmp    11a0 <asn1_do_adb+0x60>
mov    0x18(%r15),%rbx
test   %rbx,%rbx
jne    11e6 <asn1_do_adb+0xa6>
jmp    11c8 <asn1_do_adb+0x88>
call   1060 <ASN1_INTEGER_get@plt>
mov    0x4(%r15),%ecx
test   %ecx,%ecx
jle    11bf <asn1_do_adb+0x7f>
mov    0x10(%r15),%rbx
add    $0x8,%rbx
cmp    %rax,-0x8(%rbx)
je     11e6 <asn1_do_adb+0xa6>
add    $0x10,%rbx
add    $0xffffffff,%ecx
jne    11b0 <asn1_do_adb+0x70>
mov    0x8(%r15),%rbx
test   %rbx,%rbx
jne    11e6 <asn1_do_adb+0xa6>
test   %r14d,%r14d
je     11e4 <asn1_do_adb+0xa4>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { i32, i32 }
%struct.TYPE_9__ = type { i32, i32, %struct.TYPE_7__*, %struct.TYPE_8__*, %struct.TYPE_7__* }
%struct.TYPE_8__ = type { i64, %struct.TYPE_7__ }
@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_7__* @asn1_do_adb(i32** %0, %struct.TYPE_7__* %1, i32 %2) {
%4 = alloca %struct.TYPE_7__*
%5 = alloca i32**
%6 = alloca %struct.TYPE_7__*
%7 = alloca i32
%8 = alloca %struct.TYPE_9__*
%9 = alloca %struct.TYPE_8__*
%10 = alloca i64
%11 = alloca i32**
%12 = alloca i32
store i32** %0, i32*** %5
store %struct.TYPE_7__* %1, %struct.TYPE_7__** %6
store i32 %2, i32* %7
%13 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%14 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %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_7__*, %struct.TYPE_7__** %6
store %struct.TYPE_7__* %20, %struct.TYPE_7__** %4
br label %105
21: ; preds = %3
%22 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%23 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = call %struct.TYPE_9__* @ASN1_ADB_ptr(i32 %24)
store %struct.TYPE_9__* %25, %struct.TYPE_9__** %8
%26 = load i32**, i32*** %5
%27 = load i32*, i32** %26
%28 = bitcast i32* %27 to i8*
%29 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%30 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %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_9__*, %struct.TYPE_9__** %8
%39 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %38, i32 0, i32 4
%40 = load %struct.TYPE_7__*, %struct.TYPE_7__** %39
%41 = icmp ne %struct.TYPE_7__* %40, null
br i1 %41, label %43, label %42
42: ; preds = %37
br label %97
43: ; preds = %37
%44 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%45 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %44, i32 0, i32 4
%46 = load %struct.TYPE_7__*, %struct.TYPE_7__** %45
store %struct.TYPE_7__* %46, %struct.TYPE_7__** %4
br label %105
47: ; preds = %21
%48 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%49 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %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_9__*, %struct.TYPE_9__** %8
%64 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %63, i32 0, i32 3
%65 = load %struct.TYPE_8__*, %struct.TYPE_8__** %64
store %struct.TYPE_8__* %65, %struct.TYPE_8__** %9
store i32 0, i32* %12
br label %66
66: ; preds = %82, %62
%67 = load i32, i32* %12
%68 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%69 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %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_8__*, %struct.TYPE_8__** %9
%74 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %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_8__*, %struct.TYPE_8__** %9
%80 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %79, i32 0, i32 1
store %struct.TYPE_7__* %80, %struct.TYPE_7__** %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_8__*, %struct.TYPE_8__** %9
%86 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %85, i32 1
store %struct.TYPE_8__* %86, %struct.TYPE_8__** %9
br label %66
87: ; preds = %66
%88 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%89 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %88, i32 0, i32 2
%90 = load %struct.TYPE_7__*, %struct.TYPE_7__** %89
%91 = icmp ne %struct.TYPE_7__* %90, null
br i1 %91, label %93, label %92
92: ; preds = %87
br label %97
93: ; preds = %87
%94 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%95 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %94, i32 0, i32 2
%96 = load %struct.TYPE_7__*, %struct.TYPE_7__** %95
store %struct.TYPE_7__* %96, %struct.TYPE_7__** %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_7__* null, %struct.TYPE_7__** %4
br label %105
105: ; preds = %104, %93, %78, %43, %19
%106 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
ret %struct.TYPE_7__* %106
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { i32, i32 }
%struct.TYPE_9__ = type { i32, i32, %struct.TYPE_7__*, %struct.TYPE_8__*, %struct.TYPE_7__* }
%struct.TYPE_8__ = type { i64, %struct.TYPE_7__ }
@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_7__* @asn1_do_adb(i32** nocapture %0, %struct.TYPE_7__* %1, i32 %2) {
%4 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %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 %65, label %9
9: ; preds = %3
%10 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %1, i64 0, i32 1
%11 = load i32, i32* %10
%12 = tail call %struct.TYPE_9__* @ASN1_ADB_ptr(i32 %11)
%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_9__, %struct.TYPE_9__* %12, i64 0, i32 4
%18 = load %struct.TYPE_7__*, %struct.TYPE_7__** %17
%19 = icmp eq %struct.TYPE_7__* %18, null
br i1 %19, label %59, label %65
20: ; preds = %9
%21 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %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* %4
%27 = load i32, i32* @ASN1_TFLG_ADB_OID
%28 = and i32 %27, %26
%29 = icmp eq i32 %28, 0
%30 = load i32*, i32** %25
br i1 %29, label %33, label %31
31: ; preds = %20
%32 = tail call i64 @OBJ_obj2nid(i32* %30)
br label %35
33: ; preds = %20
%34 = tail call i64 @ASN1_INTEGER_get(i32* %30)
br label %35
35: ; preds = %33, %31
%36 = phi i64 [ %32, %31 ], [ %34, %33 ]
%37 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %12, i64 0, i32 1
%38 = load i32, i32* %37
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %55
40: ; preds = %35
%41 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %12, i64 0, i32 3
%42 = load %struct.TYPE_8__*, %struct.TYPE_8__** %41
br label %43
43: ; preds = %40, %51
%44 = phi i32 [ %52, %51 ], [ 0, %40 ]
%45 = phi %struct.TYPE_8__* [ %53, %51 ], [ %42, %40 ]
%46 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %45, i64 0, i32 0
%47 = load i64, i64* %46
%48 = icmp eq i64 %47, %36
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %45, i64 0, i32 1
br label %65
51: ; preds = %43
%52 = add nuw nsw i32 %44, 1
%53 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %45, i64 1
%54 = icmp eq i32 %52, %38
br i1 %54, label %55, label %43
55: ; preds = %51, %35
%56 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %12, i64 0, i32 2
%57 = load %struct.TYPE_7__*, %struct.TYPE_7__** %56
%58 = icmp eq %struct.TYPE_7__* %57, null
br i1 %58, label %59, label %65
59: ; preds = %55, %16
%60 = icmp eq i32 %2, 0
br i1 %60, label %65, label %61
61: ; preds = %59
%62 = load i32, i32* @ASN1_F_ASN1_DO_ADB
%63 = load i32, i32* @ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE
%64 = tail call i32 @ASN1err(i32 %62, i32 %63)
br label %65
65: ; preds = %59, %61, %55, %16, %3, %49
%66 = phi %struct.TYPE_7__* [ %50, %49 ], [ %1, %3 ], [ %18, %16 ], [ %57, %55 ], [ null, %61 ], [ null, %59 ]
ret %struct.TYPE_7__* %66
}