#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int flags;
  int ref_offset;
  int /*<<< orphan*/ ref_lock;
};
struct TYPE_4__ {
  scalar_t__ itype;
  TYPE_2__ *funcs;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_1__ ASN1_ITEM;
typedef TYPE_2__ ASN1_AUX;

/* Variables and functions */
int ASN1_AFLG_REFCOUNT;
scalar_t__ ASN1_ITYPE_NDEF_SEQUENCE;
scalar_t__ ASN1_ITYPE_SEQUENCE;
int CRYPTO_add(int *, int, int /*<<< orphan*/);
int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) {
  const ASN1_AUX *aux;
  int *lck, ret;
  if ((it->itype != ASN1_ITYPE_SEQUENCE) &&
      (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
    return 0;
  aux = it->funcs;
  if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
    return 0;
  lck = (void *)(((char *)*pval) + aux->ref_offset);
  if (op == 0) {
    *lck = 1;
    return 1;
  }
  ret = CRYPTO_add(lck, op, aux->ref_lock);
  return ret;
}


x86 assembly (clang, -O0):
<asn1_do_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e9f(%rip),%rcx
cmp    (%rcx),%rax
je     115d <asn1_do_lock+0x4d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2ea0(%rip),%rcx
cmp    (%rcx),%rax
je     115d <asn1_do_lock+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11ea <asn1_do_lock+0xda>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     118c <asn1_do_lock+0x7c>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    0x2e5f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1198 <asn1_do_lock+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11ea <asn1_do_lock+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
movslq 0x4(%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ce <asn1_do_lock+0xbe>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11ea <asn1_do_lock+0xda>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edx
call   1030 <CRYPTO_add@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_do_lock>:
mov    (%rdx),%r9
mov    0x2eb6(%rip),%r8
xor    %eax,%eax
cmp    (%r8),%r9
je     112e <asn1_do_lock+0x1e>
mov    0x2ec0(%rip),%rcx
cmp    (%rcx),%r9
je     112e <asn1_do_lock+0x1e>
ret
mov    0x8(%rdx),%rcx
test   %rcx,%rcx
je     112d <asn1_do_lock+0x1d>
mov    0x2ea2(%rip),%rdx
mov    (%rdx),%edx
test   %edx,(%rcx)
je     112d <asn1_do_lock+0x1d>
movslq 0x4(%rcx),%rax
add    (%rdi),%rax
test   %esi,%esi
je     115a <asn1_do_lock+0x4a>
mov    0x8(%rcx),%edx
mov    %rax,%rdi
jmp    1030 <CRYPTO_add@plt>
movl   $0x1,(%rax)
mov    $0x1,%eax
ret

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

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, %struct.TYPE_5__* }
%struct.TYPE_5__ = type { i32, i32, i32 }
@ASN1_ITYPE_SEQUENCE = global i64 0
@ASN1_ITYPE_NDEF_SEQUENCE = global i64 0
@ASN1_AFLG_REFCOUNT = global i32 0
define i32 @asn1_do_lock(i32** nocapture %0, i32 %1, %struct.TYPE_4__* nocapture %2) {
%4 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @ASN1_ITYPE_SEQUENCE
%7 = icmp eq i64 %5, %6
%8 = load i64, i64* @ASN1_ITYPE_NDEF_SEQUENCE
%9 = icmp eq i64 %5, %8
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %35
11: ; preds = %3
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
%13 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%14 = icmp eq %struct.TYPE_5__* %13, null
br i1 %14, label %35, label %15
15: ; preds = %11
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @ASN1_AFLG_REFCOUNT
%19 = and i32 %18, %17
%20 = icmp eq i32 %19, 0
br i1 %20, label %35, label %21
21: ; preds = %15
%22 = bitcast i32** %0 to i8**
%23 = load i8*, i8** %22
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 1
%25 = load i32, i32* %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = bitcast i8* %27 to i32*
%29 = icmp eq i32 %1, 0
br i1 %29, label %30, label %31
30: ; preds = %21
store i32 1, i32* %28
br label %35
31: ; preds = %21
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 2
%33 = load i32, i32* %32
%34 = tail call i32 @CRYPTO_add(i32* %28, i32 %1, i32 %33)
br label %35
35: ; preds = %11, %15, %3, %31, %30
%36 = phi i32 [ 1, %30 ], [ %34, %31 ], [ 0, %3 ], [ 0, %15 ], [ 0, %11 ]
ret i32 %36
}