#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 == NULL) {
    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    12bf <asn1_do_adb+0x17f>
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)
mov    -0x40(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11d0 <asn1_do_adb+0x90>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x18(%rax)
jne    11bf <asn1_do_adb+0x7f>
jmp    1296 <asn1_do_adb+0x156>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12bf <asn1_do_adb+0x17f>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2dfb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11fd <asn1_do_adb+0xbd>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
call   1030 <OBJ_obj2nid@plt>
mov    %rax,-0x38(%rbp)
jmp    120d <asn1_do_adb+0xcd>
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    1271 <asn1_do_adb+0x131>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
cmp    -0x38(%rbp),%rax
jne    1252 <asn1_do_adb+0x112>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    12bf <asn1_do_adb+0x17f>
jmp    1257 <asn1_do_adb+0x117>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
jmp    1220 <asn1_do_adb+0xe0>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1285 <asn1_do_adb+0x145>
jmp    1296 <asn1_do_adb+0x156>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12bf <asn1_do_adb+0x17f>
cmpl   $0x0,-0x1c(%rbp)
je     12b7 <asn1_do_adb+0x177>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    0x2d30(%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
movslq (%r15),%rcx
mov    (%rax,%rcx,1),%rdi
test   %rdi,%rdi
je     1190 <asn1_do_adb+0x50>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
test   %eax,(%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 %106
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 = load i32*, i32** %35
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %48
38: ; preds = %21
%39 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%40 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %39, i32 0, i32 4
%41 = load %struct.TYPE_7__*, %struct.TYPE_7__** %40
%42 = icmp ne %struct.TYPE_7__* %41, null
br i1 %42, label %44, label %43
43: ; preds = %38
br label %98
44: ; preds = %38
%45 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%46 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %45, i32 0, i32 4
%47 = load %struct.TYPE_7__*, %struct.TYPE_7__** %46
store %struct.TYPE_7__* %47, %struct.TYPE_7__** %4
br label %106
48: ; preds = %21
%49 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%50 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = load i32, i32* @ASN1_TFLG_ADB_OID
%53 = and i32 %51, %52
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = load i32**, i32*** %11
%57 = load i32*, i32** %56
%58 = call i64 @OBJ_obj2nid(i32* %57)
store i64 %58, i64* %10
br label %63
59: ; preds = %48
%60 = load i32**, i32*** %11
%61 = load i32*, i32** %60
%62 = call i64 @ASN1_INTEGER_get(i32* %61)
store i64 %62, i64* %10
br label %63
63: ; preds = %59, %55
%64 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%65 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %64, i32 0, i32 3
%66 = load %struct.TYPE_8__*, %struct.TYPE_8__** %65
store %struct.TYPE_8__* %66, %struct.TYPE_8__** %9
store i32 0, i32* %12
br label %67
67: ; preds = %83, %63
%68 = load i32, i32* %12
%69 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%70 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = icmp slt i32 %68, %71
br i1 %72, label %73, label %88
73: ; preds = %67
%74 = load %struct.TYPE_8__*, %struct.TYPE_8__** %9
%75 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %74, i32 0, i32 0
%76 = load i64, i64* %75
%77 = load i64, i64* %10
%78 = icmp eq i64 %76, %77
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = load %struct.TYPE_8__*, %struct.TYPE_8__** %9
%81 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %80, i32 0, i32 1
store %struct.TYPE_7__* %81, %struct.TYPE_7__** %4
br label %106
82: ; preds = %73
br label %83
83: ; preds = %82
%84 = load i32, i32* %12
%85 = add nsw i32 %84, 1
store i32 %85, i32* %12
%86 = load %struct.TYPE_8__*, %struct.TYPE_8__** %9
%87 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %86, i32 1
store %struct.TYPE_8__* %87, %struct.TYPE_8__** %9
br label %67
88: ; preds = %67
%89 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%90 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %89, i32 0, i32 2
%91 = load %struct.TYPE_7__*, %struct.TYPE_7__** %90
%92 = icmp ne %struct.TYPE_7__* %91, null
br i1 %92, label %94, label %93
93: ; preds = %88
br label %98
94: ; preds = %88
%95 = load %struct.TYPE_9__*, %struct.TYPE_9__** %8
%96 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %95, i32 0, i32 2
%97 = load %struct.TYPE_7__*, %struct.TYPE_7__** %96
store %struct.TYPE_7__* %97, %struct.TYPE_7__** %4
br label %106
98: ; preds = %93, %43
%99 = load i32, i32* %7
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %105
101: ; preds = %98
%102 = load i32, i32* @ASN1_F_ASN1_DO_ADB
%103 = load i32, i32* @ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE
%104 = call i32 @ASN1err(i32 %102, i32 %103)
br label %105
105: ; preds = %101, %98
store %struct.TYPE_7__* null, %struct.TYPE_7__** %4
br label %106
106: ; preds = %105, %94, %79, %44, %19
%107 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
ret %struct.TYPE_7__* %107
}

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 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %12, i64 0, i32 0
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = bitcast i8* %18 to i32**
%20 = load i32*, i32** %19
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %9
%23 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %12, i64 0, i32 4
%24 = load %struct.TYPE_7__*, %struct.TYPE_7__** %23
%25 = icmp eq %struct.TYPE_7__* %24, null
br i1 %25, label %59, label %65
26: ; preds = %9
%27 = load i32, i32* %4
%28 = load i32, i32* @ASN1_TFLG_ADB_OID
%29 = and i32 %28, %27
%30 = icmp eq i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = tail call i64 @OBJ_obj2nid(i32* %20)
br label %35
33: ; preds = %26
%34 = tail call i64 @ASN1_INTEGER_get(i32* %20)
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, %22
%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, %22, %3, %49
%66 = phi %struct.TYPE_7__* [ %50, %49 ], [ %1, %3 ], [ %24, %22 ], [ %57, %55 ], [ null, %61 ], [ null, %59 ]
ret %struct.TYPE_7__* %66
}