#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 */
typedef int /*<<< orphan*/ X509V3_EXT_METHOD;
struct TYPE_4__ {
  int /*<<< orphan*/ type;
};
typedef int /*<<< orphan*/ BIGNUM;
typedef TYPE_1__ ASN1_INTEGER;

/* Variables and functions */
int BN_dec2bn(int /*<<< orphan*/ **, char const *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int BN_hex2bn(int /*<<< orphan*/ **, char const *);
scalar_t__ BN_is_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
TYPE_1__ *BN_to_ASN1_INTEGER(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ V_ASN1_NEG;
int /*<<< orphan*/ X509V3_R_BN_DEC2BN_ERROR;
int /*<<< orphan*/ X509V3_R_BN_TO_ASN1_INTEGER_ERROR;
int /*<<< orphan*/ X509V3_R_INVALID_NULL_VALUE;
int /*<<< orphan*/ X509V3error(int /*<<< orphan*/);
ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, const char *value) {
  BIGNUM *bn = NULL;
  ASN1_INTEGER *aint;
  int isneg, ishex;
  int ret;
  if (!value) {
    X509V3error(X509V3_R_INVALID_NULL_VALUE);
    return 0;
  }
  bn = BN_new();
  if (value[0] == '-') {
    value++;
    isneg = 1;
  } else
    isneg = 0;
  if (value[0] == '0' && ((value[1] == 'x') || (value[1] == 'X'))) {
    value += 2;
    ishex = 1;
  } else
    ishex = 0;
  if (ishex)
    ret = BN_hex2bn(&bn, value);
  else
    ret = BN_dec2bn(&bn, value);
  if (!ret || value[ret]) {
    BN_free(bn);
    X509V3error(X509V3_R_BN_DEC2BN_ERROR);
    return 0;
  }
  if (isneg && BN_is_zero(bn))
    isneg = 0;
  aint = BN_to_ASN1_INTEGER(bn, NULL);
  BN_free(bn);
  if (!aint) {
    X509V3error(X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
    return 0;
  }
  if (isneg)
    aint->type |= V_ASN1_NEG;
  return aint;
}


x86 assembly (clang, -O0):
<s2i_ASN1_INTEGER>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ae <s2i_ASN1_INTEGER+0x3e>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1060 <X509V3error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1332 <s2i_ASN1_INTEGER+0x1c2>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11e1 <s2i_ASN1_INTEGER+0x71>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11e8 <s2i_ASN1_INTEGER+0x78>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1232 <s2i_ASN1_INTEGER+0xc2>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     121a <s2i_ASN1_INTEGER+0xaa>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    1232 <s2i_ASN1_INTEGER+0xc2>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1239 <s2i_ASN1_INTEGER+0xc9>
movl   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1258 <s2i_ASN1_INTEGER+0xe8>
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1040 <BN_hex2bn@plt>
mov    %eax,-0x34(%rbp)
jmp    1268 <s2i_ASN1_INTEGER+0xf8>
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1030 <BN_dec2bn@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1287 <s2i_ASN1_INTEGER+0x117>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12ab <s2i_ASN1_INTEGER+0x13b>
mov    -0x20(%rbp),%rdi
call   1070 <BN_free@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1060 <X509V3error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1332 <s2i_ASN1_INTEGER+0x1c2>
cmpl   $0x0,-0x2c(%rbp)
je     12cf <s2i_ASN1_INTEGER+0x15f>
mov    -0x20(%rbp),%rdi
call   1080 <BN_is_zero@plt>
cmp    $0x0,%rax
je     12cf <s2i_ASN1_INTEGER+0x15f>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <BN_to_ASN1_INTEGER@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <BN_free@plt>
cmpq   $0x0,-0x28(%rbp)
jne    130f <s2i_ASN1_INTEGER+0x19f>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   1060 <X509V3error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1332 <s2i_ASN1_INTEGER+0x1c2>
cmpl   $0x0,-0x2c(%rbp)
je     132a <s2i_ASN1_INTEGER+0x1ba>
mov    0x2cb8(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s2i_ASN1_INTEGER>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rsi,%rsi
je     11f0 <s2i_ASN1_INTEGER+0x80>
mov    %rsi,%rbx
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,0x8(%rsp)
mov    (%rbx),%bpl
xor    %eax,%eax
cmp    $0x2d,%bpl
sete   %al
lea    (%rbx,%rax,1),%r14
cmpb   $0x30,(%rbx,%rax,1)
jne    11c3 <s2i_ASN1_INTEGER+0x53>
mov    0x1(%r14),%al
or     $0x20,%al
cmp    $0x78,%al
jne    11c3 <s2i_ASN1_INTEGER+0x53>
add    $0x2,%r14
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1040 <BN_hex2bn@plt>
test   %eax,%eax
jne    11d4 <s2i_ASN1_INTEGER+0x64>
jmp    11dd <s2i_ASN1_INTEGER+0x6d>
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <BN_dec2bn@plt>
test   %eax,%eax
je     11dd <s2i_ASN1_INTEGER+0x6d>
cltq
cmpb   $0x0,(%r14,%rax,1)
je     120c <s2i_ASN1_INTEGER+0x9c>
mov    0x8(%rsp),%rdi
call   1070 <BN_free@plt>
mov    0x2df2(%rip),%rax
jmp    11f7 <s2i_ASN1_INTEGER+0x87>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1060 <X509V3error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%r14b
cmp    $0x2d,%bpl
jne    1226 <s2i_ASN1_INTEGER+0xb6>
mov    0x8(%rsp),%rdi
call   1080 <BN_is_zero@plt>
test   %rax,%rax
setne  %r14b
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1090 <BN_to_ASN1_INTEGER@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1070 <BN_free@plt>
test   %rbx,%rbx
je     1256 <s2i_ASN1_INTEGER+0xe6>
test   %r14b,%r14b
jne    1200 <s2i_ASN1_INTEGER+0x90>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
or     %eax,(%rbx)
jmp    1200 <s2i_ASN1_INTEGER+0x90>
mov    0x2d93(%rip),%rax
jmp    11f7 <s2i_ASN1_INTEGER+0x87>

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

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 }
@X509V3_R_INVALID_NULL_VALUE = global i32 0
@X509V3_R_BN_DEC2BN_ERROR = global i32 0
@X509V3_R_BN_TO_ASN1_INTEGER_ERROR = global i32 0
@V_ASN1_NEG = global i32 0
define %struct.TYPE_4__* @s2i_ASN1_INTEGER(i32* nocapture readnone %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = icmp eq i8* %1, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @X509V3_R_INVALID_NULL_VALUE
%8 = tail call i32 @X509V3error(i32 %7)
br label %60
9: ; preds = %2
%10 = tail call i32* (...) @BN_new()
store i32* %10, i32** %3
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 45
%13 = zext i1 %12 to i64
%14 = getelementptr i8, i8* %1, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 48
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = load i8, i8* %18
switch i8 %19, label %23 [
i8 120, label %20
i8 88, label %20
]
20: ; preds = %17, %17
%21 = getelementptr inbounds i8, i8* %14, i64 2
%22 = call i32 @BN_hex2bn(i32** %3, i8* %21)
br label %25
23: ; preds = %17, %9
%24 = call i32 @BN_dec2bn(i32** %3, i8* %14)
br label %25
25: ; preds = %23, %20
%26 = phi i8* [ %21, %20 ], [ %14, %23 ]
%27 = phi i32 [ %22, %20 ], [ %24, %23 ]
%28 = icmp eq i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = sext i32 %27 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %29, %25
%35 = load i32*, i32** %3
%36 = call i32 @BN_free(i32* %35)
%37 = load i32, i32* @X509V3_R_BN_DEC2BN_ERROR
%38 = call i32 @X509V3error(i32 %37)
br label %60
39: ; preds = %29
br i1 %12, label %40, label %44
40: ; preds = %39
%41 = load i32*, i32** %3
%42 = call i64 @BN_is_zero(i32* %41)
%43 = icmp ne i64 %42, 0
br label %44
44: ; preds = %40, %39
%45 = phi i1 [ true, %39 ], [ %43, %40 ]
%46 = load i32*, i32** %3
%47 = call %struct.TYPE_4__* @BN_to_ASN1_INTEGER(i32* %46, i32* null)
%48 = load i32*, i32** %3
%49 = call i32 @BN_free(i32* %48)
%50 = icmp eq %struct.TYPE_4__* %47, null
br i1 %50, label %51, label %54
51: ; preds = %44
%52 = load i32, i32* @X509V3_R_BN_TO_ASN1_INTEGER_ERROR
%53 = call i32 @X509V3error(i32 %52)
br label %60
54: ; preds = %44
br i1 %45, label %60, label %55
55: ; preds = %54
%56 = load i32, i32* @V_ASN1_NEG
%57 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %47, i64 0, i32 0
%58 = load i32, i32* %57
%59 = or i32 %58, %56
store i32 %59, i32* %57
br label %60
60: ; preds = %54, %55, %51, %34, %6
%61 = phi %struct.TYPE_4__* [ null, %34 ], [ null, %51 ], [ null, %6 ], [ %47, %55 ], [ %47, %54 ]
ret %struct.TYPE_4__* %61
}