#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 */

/* Type definitions */
typedef int /*<<< orphan*/ ASN1_OBJECT;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_D2I_ASN1_OBJECT;
int ASN1_R_BAD_OBJECT_HEADER;
int ASN1_R_EXPECTING_AN_OBJECT;
int ASN1_get_object(unsigned char const **, long *, int *, int *, long);
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int);
int V_ASN1_OBJECT;
int /*<<< orphan*/ *c2i_ASN1_OBJECT(int /*<<< orphan*/ **,
                                    unsigned char const **, long);
ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
                             long length) {
  const unsigned char *p;
  long len;
  int tag, xclass;
  int inf, i;
  ASN1_OBJECT *ret = NULL;
  p = *pp;
  inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
  if (inf & 0x80) {
    i = ASN1_R_BAD_OBJECT_HEADER;
    goto err;
  }
  if (tag != V_ASN1_OBJECT) {
    i = ASN1_R_EXPECTING_AN_OBJECT;
    goto err;
  }
  ret = c2i_ASN1_OBJECT(a, &p, len);
  if (ret)
    *pp = p;
  return ret;
err:
  ASN1err(ASN1_F_D2I_ASN1_OBJECT, i);
  return (NULL);
}


x86 assembly (clang, -O0):
<d2i_ASN1_OBJECT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%r8
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1040 <ASN1_get_object@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1195 <d2i_ASN1_OBJECT+0x65>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    11f0 <d2i_ASN1_OBJECT+0xc0>
mov    -0x34(%rbp),%eax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
je     11b8 <d2i_ASN1_OBJECT+0x88>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    11f0 <d2i_ASN1_OBJECT+0xc0>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1050 <c2i_ASN1_OBJECT@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11e3 <d2i_ASN1_OBJECT+0xb3>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1209 <d2i_ASN1_OBJECT+0xd9>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%esi
call   1030 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2i_ASN1_OBJECT>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r8
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x24(%rsp),%rcx
call   1040 <ASN1_get_object@plt>
test   $0x80,%al
jne    1195 <d2i_ASN1_OBJECT+0x65>
mov    0x14(%rsp),%eax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%eax
jne    119e <d2i_ASN1_OBJECT+0x6e>
mov    0x18(%rsp),%rdx
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <c2i_ASN1_OBJECT@plt>
test   %rax,%rax
je     11b5 <d2i_ASN1_OBJECT+0x85>
mov    0x8(%rsp),%rcx
mov    %rcx,(%rbx)
jmp    11b7 <d2i_ASN1_OBJECT+0x87>
mov    0x2e34(%rip),%rax
jmp    11a5 <d2i_ASN1_OBJECT+0x75>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1030 <ASN1err@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ASN1_R_BAD_OBJECT_HEADER = global i32 0
@V_ASN1_OBJECT = global i32 0
@ASN1_R_EXPECTING_AN_OBJECT = global i32 0
@ASN1_F_D2I_ASN1_OBJECT = global i32 0
define i32* @d2i_ASN1_OBJECT(i32** %0, i8** %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
store i32** %0, i32*** %5
store i8** %1, i8*** %6
store i64 %2, i64* %7
store i32* null, i32** %14
%15 = load i8**, i8*** %6
%16 = load i8*, i8** %15
store i8* %16, i8** %8
%17 = load i64, i64* %7
%18 = call i32 @ASN1_get_object(i8** %8, i64* %9, i32* %10, i32* %11, i64 %17)
store i32 %18, i32* %12
%19 = load i32, i32* %12
%20 = and i32 %19, 128
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = load i32, i32* @ASN1_R_BAD_OBJECT_HEADER
store i32 %23, i32* %13
br label %41
24: ; preds = %3
%25 = load i32, i32* %10
%26 = load i32, i32* @V_ASN1_OBJECT
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i32, i32* @ASN1_R_EXPECTING_AN_OBJECT
store i32 %29, i32* %13
br label %41
30: ; preds = %24
%31 = load i32**, i32*** %5
%32 = load i64, i64* %9
%33 = call i32* @c2i_ASN1_OBJECT(i32** %31, i8** %8, i64 %32)
store i32* %33, i32** %14
%34 = load i32*, i32** %14
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i8*, i8** %8
%38 = load i8**, i8*** %6
store i8* %37, i8** %38
br label %39
39: ; preds = %36, %30
%40 = load i32*, i32** %14
store i32* %40, i32** %4
br label %45
41: ; preds = %28, %22
%42 = load i32, i32* @ASN1_F_D2I_ASN1_OBJECT
%43 = load i32, i32* %13
%44 = call i32 @ASN1err(i32 %42, i32 %43)
store i32* null, i32** %4
br label %45
45: ; preds = %41, %39
%46 = load i32*, i32** %4
ret i32* %46
}

LLVM IR (-O2):
@ASN1_R_BAD_OBJECT_HEADER = global i32 0
@V_ASN1_OBJECT = global i32 0
@ASN1_R_EXPECTING_AN_OBJECT = global i32 0
@ASN1_F_D2I_ASN1_OBJECT = global i32 0
define i32* @d2i_ASN1_OBJECT(i32** %0, i8** nocapture %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i8** %4 to i8*
%9 = bitcast i64* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = load i8*, i8** %1
store i8* %12, i8** %4
%13 = call i32 @ASN1_get_object(i8** %4, i64* %5, i32* %6, i32* %7, i64 %2)
%14 = and i32 %13, 128
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = load i32, i32* %6
%18 = load i32, i32* @V_ASN1_OBJECT
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i64, i64* %5
%22 = call i32* @c2i_ASN1_OBJECT(i32** %0, i8** %4, i64 %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %31, label %24
24: ; preds = %20
%25 = load i8*, i8** %4
store i8* %25, i8** %1
br label %31
26: ; preds = %16, %3
%27 = phi i32* [ @ASN1_R_BAD_OBJECT_HEADER, %3 ], [ @ASN1_R_EXPECTING_AN_OBJECT, %16 ]
%28 = load i32, i32* %27
%29 = load i32, i32* @ASN1_F_D2I_ASN1_OBJECT
%30 = call i32 @ASN1err(i32 %29, i32 %28)
br label %31
31: ; preds = %20, %24, %26
%32 = phi i32* [ null, %26 ], [ %22, %24 ], [ null, %20 ]
ret i32* %32
}