#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ type;
  int /*<<< orphan*/ length;
  int /*<<< orphan*/ data;
};
typedef int /*<<< orphan*/ BIGNUM;
typedef TYPE_1__ ASN1_INTEGER;

/* Variables and functions */
int /*<<< orphan*/ ASN1_INTEGER_valid(TYPE_1__ const *);
int /*<<< orphan*/ ASN1_R_BN_LIB;
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
int /*<<< orphan*/ *BN_bin2bn(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_set_negative(int /*<<< orphan*/ *, int);
scalar_t__ V_ASN1_NEG_INTEGER;
BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) {
  BIGNUM *ret;
  if (!ASN1_INTEGER_valid(ai))
    return (NULL);
  if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
    ASN1error(ASN1_R_BN_LIB);
  else if (ai->type == V_ASN1_NEG_INTEGER)
    BN_set_negative(ret, 1);
  return (ret);
}


x86 assembly (clang, -O0):
<ASN1_INTEGER_to_BN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ASN1_INTEGER_valid@plt>
cmp    $0x0,%eax
jne    116f <ASN1_INTEGER_to_BN+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <ASN1_INTEGER_to_BN+0x99>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x18(%rbp),%rdx
call   1030 <BN_bin2bn@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a7 <ASN1_INTEGER_to_BN+0x67>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@plt>
jmp    11d1 <ASN1_INTEGER_to_BN+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    11cc <ASN1_INTEGER_to_BN+0x8c>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1050 <BN_set_negative@plt>
jmp    11d1 <ASN1_INTEGER_to_BN+0x91>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_INTEGER_to_BN>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <ASN1_INTEGER_valid@plt>
test   %eax,%eax
je     1195 <ASN1_INTEGER_to_BN+0x55>
mov    0x8(%rbx),%esi
mov    0xc(%rbx),%edi
mov    %r14,%rdx
call   1030 <BN_bin2bn@plt>
test   %rax,%rax
je     1187 <ASN1_INTEGER_to_BN+0x47>
mov    %rax,%r14
mov    (%rbx),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <ASN1_INTEGER_to_BN+0x58>
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <BN_set_negative@plt>
jmp    1198 <ASN1_INTEGER_to_BN+0x58>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i32, i32 }
@ASN1_R_BN_LIB = global i32 0
@V_ASN1_NEG_INTEGER = global i64 0
define i32* @ASN1_INTEGER_to_BN(%struct.TYPE_4__* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca %struct.TYPE_4__*
%5 = alloca i32*
%6 = alloca i32*
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %4
store i32* %1, i32** %5
%7 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
%8 = call i32 @ASN1_INTEGER_valid(%struct.TYPE_4__* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i32* null, i32** %3
br label %36
11: ; preds = %2
%12 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 2
%14 = load i32, i32* %13
%15 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load i32*, i32** %5
%19 = call i32* @BN_bin2bn(i32 %14, i32 %17, i32* %18)
store i32* %19, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* @ASN1_R_BN_LIB
%23 = call i32 @ASN1error(i32 %22)
br label %34
24: ; preds = %11
%25 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64, i64* @V_ASN1_NEG_INTEGER
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32*, i32** %6
%32 = call i32 @BN_set_negative(i32* %31, i32 1)
br label %33
33: ; preds = %30, %24
br label %34
34: ; preds = %33, %21
%35 = load i32*, i32** %6
store i32* %35, i32** %3
br label %36
36: ; preds = %34, %10
%37 = load i32*, i32** %3
ret i32* %37
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i32, i32 }
@ASN1_R_BN_LIB = global i32 0
@V_ASN1_NEG_INTEGER = global i64 0
define i32* @ASN1_INTEGER_to_BN(%struct.TYPE_4__* %0, i32* %1) {
%3 = tail call i32 @ASN1_INTEGER_valid(%struct.TYPE_4__* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%9 = load i32, i32* %8
%10 = tail call i32* @BN_bin2bn(i32 %7, i32 %9, i32* %1)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = load i32, i32* @ASN1_R_BN_LIB
%14 = tail call i32 @ASN1error(i32 %13)
br label %22
15: ; preds = %5
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @V_ASN1_NEG_INTEGER
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @BN_set_negative(i32* %10, i32 1)
br label %22
22: ; preds = %12, %20, %15, %2
%23 = phi i32* [ null, %2 ], [ %10, %15 ], [ %10, %20 ], [ null, %12 ]
ret i32* %23
}