#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_10__ TYPE_4__;
typedef struct TYPE_9__ TYPE_3__;
typedef struct TYPE_8__ TYPE_2__;
typedef struct TYPE_7__ TYPE_1__;

/* Type definitions */
struct TYPE_10__ {
  scalar_t__ itype;
  int utype;
  int size;
  TYPE_3__ *funcs;
};
struct TYPE_9__ {
  int /*<<< orphan*/ (*prim_free)(int /*<<< orphan*/ **, TYPE_4__ const *);
};
struct TYPE_7__ {
  int /*<<< orphan*/ ptr;
};
struct TYPE_8__ {
  int type;
  TYPE_1__ value;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_2__ ASN1_TYPE;
typedef int /*<<< orphan*/ ASN1_STRING;
typedef TYPE_3__ ASN1_PRIMITIVE_FUNCS;
typedef int /*<<< orphan*/ ASN1_OBJECT;
typedef TYPE_4__ ASN1_ITEM;
typedef int ASN1_BOOLEAN;

/* Variables and functions */
scalar_t__ ASN1_ITYPE_MSTRING;
int /*<<< orphan*/ ASN1_OBJECT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1_STRING_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ OPENSSL_free(int /*<<< orphan*/ *);
#define V_ASN1_ANY 131
#define V_ASN1_BOOLEAN 130
#define V_ASN1_NULL 129
#define V_ASN1_OBJECT 128
int /*<<< orphan*/ stub1(int /*<<< orphan*/ **, TYPE_4__ const *);
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
  int utype;
  if (it) {
    const ASN1_PRIMITIVE_FUNCS *pf;
    pf = it->funcs;
    if (pf && pf->prim_free) {
      pf->prim_free(pval, it);
      return;
    }
  }
  if (!it) {
    ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
    utype = typ->type;
    pval = (ASN1_VALUE **)&typ->value.ptr;
    if (!*pval)
      return;
  } else if (it->itype == ASN1_ITYPE_MSTRING) {
    utype = -1;
    if (!*pval)
      return;
  } else {
    utype = it->utype;
    if ((utype != V_ASN1_BOOLEAN) && !*pval)
      return;
  }
  switch (utype) {
  case V_ASN1_OBJECT:
    ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
    break;
  case V_ASN1_BOOLEAN:
    if (it)
      *(ASN1_BOOLEAN *)pval = it->size;
    else
      *(ASN1_BOOLEAN *)pval = -1;
    return;
  case V_ASN1_NULL:
    break;
  case V_ASN1_ANY:
    ASN1_primitive_free(pval, NULL);
    OPENSSL_free(*pval);
    break;
  default:
    ASN1_STRING_free((ASN1_STRING *)*pval);
    *pval = NULL;
    break;
  }
  *pval = NULL;
}


x86 assembly (clang, -O0):
<ASN1_primitive_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119b <ASN1_primitive_free+0x5b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1196 <ASN1_primitive_free+0x56>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1196 <ASN1_primitive_free+0x56>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   *%rax
jmp    12f3 <ASN1_primitive_free+0x1b3>
jmp    119b <ASN1_primitive_free+0x5b>
cmpq   $0x0,-0x10(%rbp)
jne    11de <ASN1_primitive_free+0x9e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11d9 <ASN1_primitive_free+0x99>
jmp    12f3 <ASN1_primitive_free+0x1b3>
jmp    1248 <ASN1_primitive_free+0x108>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%rax
jne    1214 <ASN1_primitive_free+0xd4>
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    120f <ASN1_primitive_free+0xcf>
jmp    12f3 <ASN1_primitive_free+0x1b3>
jmp    1243 <ASN1_primitive_free+0x103>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x82,-0x14(%rbp)
je     123e <ASN1_primitive_free+0xfe>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    123e <ASN1_primitive_free+0xfe>
jmp    12f3 <ASN1_primitive_free+0x1b3>
jmp    1243 <ASN1_primitive_free+0x103>
jmp    1248 <ASN1_primitive_free+0x108>
mov    -0x14(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     12d1 <ASN1_primitive_free+0x191>
mov    -0x30(%rbp),%rax
lea    0xd98(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <ASN1_OBJECT_free@plt>
jmp    12e8 <ASN1_primitive_free+0x1a8>
cmpq   $0x0,-0x10(%rbp)
je     129f <ASN1_primitive_free+0x15f>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    12a9 <ASN1_primitive_free+0x169>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    12f3 <ASN1_primitive_free+0x1b3>
jmp    12e8 <ASN1_primitive_free+0x1a8>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <ASN1_primitive_free@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <OPENSSL_free@plt>
jmp    12e8 <ASN1_primitive_free+0x1a8>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <ASN1_STRING_free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_primitive_free>:
push   %rbx
mov    %rdi,%rbx
test   %rsi,%rsi
je     1179 <ASN1_primitive_free+0x39>
mov    0x10(%rsi),%rax
test   %rax,%rax
je     1160 <ASN1_primitive_free+0x20>
mov    (%rax),%rax
test   %rax,%rax
je     1160 <ASN1_primitive_free+0x20>
mov    %rbx,%rdi
pop    %rbx
jmp    *%rax
mov    (%rsi),%rax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <ASN1_primitive_free+0x6a>
mov    (%rbx),%rdi
test   %rdi,%rdi
jne    11be <ASN1_primitive_free+0x7e>
pop    %rbx
ret
mov    (%rbx),%rbx
mov    0x4(%rbx),%rdi
test   %rdi,%rdi
je     1177 <ASN1_primitive_free+0x37>
mov    (%rbx),%eax
add    $0x4,%rbx
add    $0xffffff80,%eax
cmp    $0x3,%eax
ja     11be <ASN1_primitive_free+0x7e>
lea    0xe66(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
call   1050 <ASN1_OBJECT_free@plt>
jmp    11ea <ASN1_primitive_free+0xaa>
mov    0x8(%rsi),%eax
cmp    $0x82,%eax
je     11d1 <ASN1_primitive_free+0x91>
mov    (%rbx),%rdi
test   %rdi,%rdi
jne    118b <ASN1_primitive_free+0x4b>
jmp    1177 <ASN1_primitive_free+0x37>
call   1040 <ASN1_STRING_free@plt>
movq   $0x0,(%rbx)
jmp    11ea <ASN1_primitive_free+0xaa>
test   %rsi,%rsi
je     11f3 <ASN1_primitive_free+0xb3>
mov    0xc(%rsi),%eax
mov    %eax,(%rbx)
pop    %rbx
ret
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <ASN1_primitive_free@plt>
mov    (%rbx),%rdi
call   1060 <OPENSSL_free@plt>
movq   $0x0,(%rbx)
pop    %rbx
ret
movl   $0xffffffff,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_10__ = type { i64, i32, i32, %struct.TYPE_9__* }
%struct.TYPE_9__ = type { i32 (i32**, %struct.TYPE_10__*)* }
%struct.TYPE_8__ = type { i32, %struct.TYPE_7__ }
%struct.TYPE_7__ = type { i32 }
@ASN1_ITYPE_MSTRING = global i64 0
define void @ASN1_primitive_free(i32** %0, %struct.TYPE_10__* %1) {
%3 = alloca i32**
%4 = alloca %struct.TYPE_10__*
%5 = alloca i32
%6 = alloca %struct.TYPE_9__*
%7 = alloca %struct.TYPE_8__*
store i32** %0, i32*** %3
store %struct.TYPE_10__* %1, %struct.TYPE_10__** %4
%8 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%9 = icmp ne %struct.TYPE_10__* %8, null
br i1 %9, label %10, label %29
10: ; preds = %2
%11 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%12 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %11, i32 0, i32 3
%13 = load %struct.TYPE_9__*, %struct.TYPE_9__** %12
store %struct.TYPE_9__* %13, %struct.TYPE_9__** %6
%14 = load %struct.TYPE_9__*, %struct.TYPE_9__** %6
%15 = icmp ne %struct.TYPE_9__* %14, null
br i1 %15, label %16, label %28
16: ; preds = %10
%17 = load %struct.TYPE_9__*, %struct.TYPE_9__** %6
%18 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %17, i32 0, i32 0
%19 = load i32 (i32**, %struct.TYPE_10__*)*, i32 (i32**, %struct.TYPE_10__*)** %18
%20 = icmp ne i32 (i32**, %struct.TYPE_10__*)* %19, null
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load %struct.TYPE_9__*, %struct.TYPE_9__** %6
%23 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %22, i32 0, i32 0
%24 = load i32 (i32**, %struct.TYPE_10__*)*, i32 (i32**, %struct.TYPE_10__*)** %23
%25 = load i32**, i32*** %3
%26 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%27 = call i32 %24(i32** %25, %struct.TYPE_10__* %26)
br label %105
28: ; preds = %16, %10
br label %29
29: ; preds = %28, %2
%30 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%31 = icmp ne %struct.TYPE_10__* %30, null
br i1 %31, label %48, label %32
32: ; preds = %29
%33 = load i32**, i32*** %3
%34 = load i32*, i32** %33
%35 = bitcast i32* %34 to %struct.TYPE_8__*
store %struct.TYPE_8__* %35, %struct.TYPE_8__** %7
%36 = load %struct.TYPE_8__*, %struct.TYPE_8__** %7
%37 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %36, i32 0, i32 0
%38 = load i32, i32* %37
store i32 %38, i32* %5
%39 = load %struct.TYPE_8__*, %struct.TYPE_8__** %7
%40 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %39, i32 0, i32 1
%41 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %40, i32 0, i32 0
%42 = bitcast i32* %41 to i32**
store i32** %42, i32*** %3
%43 = load i32**, i32*** %3
%44 = load i32*, i32** %43
%45 = icmp ne i32* %44, null
br i1 %45, label %47, label %46
46: ; preds = %32
br label %105
47: ; preds = %32
br label %73
48: ; preds = %29
%49 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%50 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %49, i32 0, i32 0
%51 = load i64, i64* %50
%52 = load i64, i64* @ASN1_ITYPE_MSTRING
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %60
54: ; preds = %48
store i32 -1, i32* %5
%55 = load i32**, i32*** %3
%56 = load i32*, i32** %55
%57 = icmp ne i32* %56, null
br i1 %57, label %59, label %58
58: ; preds = %54
br label %105
59: ; preds = %54
br label %72
60: ; preds = %48
%61 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%62 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %61, i32 0, i32 1
%63 = load i32, i32* %62
store i32 %63, i32* %5
%64 = load i32, i32* %5
%65 = icmp ne i32 %64, 130
br i1 %65, label %66, label %71
66: ; preds = %60
%67 = load i32**, i32*** %3
%68 = load i32*, i32** %67
%69 = icmp ne i32* %68, null
br i1 %69, label %71, label %70
70: ; preds = %66
br label %105
71: ; preds = %66, %60
br label %72
72: ; preds = %71, %59
br label %73
73: ; preds = %72, %47
%74 = load i32, i32* %5
switch i32 %74, label %98 [
i32 128, label %75
i32 130, label %79
i32 129, label %92
i32 131, label %93
]
75: ; preds = %73
%76 = load i32**, i32*** %3
%77 = load i32*, i32** %76
%78 = call i32 @ASN1_OBJECT_free(i32* %77)
br label %103
79: ; preds = %73
%80 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%81 = icmp ne %struct.TYPE_10__* %80, null
br i1 %81, label %82, label %88
82: ; preds = %79
%83 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%84 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %83, i32 0, i32 2
%85 = load i32, i32* %84
%86 = load i32**, i32*** %3
%87 = bitcast i32** %86 to i32*
store i32 %85, i32* %87
br label %91
88: ; preds = %79
%89 = load i32**, i32*** %3
%90 = bitcast i32** %89 to i32*
store i32 -1, i32* %90
br label %91
91: ; preds = %88, %82
br label %105
92: ; preds = %73
br label %103
93: ; preds = %73
%94 = load i32**, i32*** %3
%95 = load i32**, i32*** %3
%96 = load i32*, i32** %95
%97 = call i32 @OPENSSL_free(i32* %96)
br label %103
98: ; preds = %73
%99 = load i32**, i32*** %3
%100 = load i32*, i32** %99
%101 = call i32 @ASN1_STRING_free(i32* %100)
%102 = load i32**, i32*** %3
store i32* null, i32** %102
br label %103
103: ; preds = %98, %93, %92, %75
%104 = load i32**, i32*** %3
store i32* null, i32** %104
br label %105
105: ; preds = %103, %91, %70, %58, %46, %21
ret void
}

LLVM IR (-O2):
%struct.TYPE_10__ = type { i64, i32, i32, %struct.TYPE_9__* }
%struct.TYPE_9__ = type { i32 (i32**, %struct.TYPE_10__*)* }
%struct.TYPE_8__ = type { i32, %struct.TYPE_7__ }
%struct.TYPE_7__ = type { i32 }
@ASN1_ITYPE_MSTRING = global i64 0
define void @ASN1_primitive_free(i32** %0, %struct.TYPE_10__* %1) {
%3 = icmp eq %struct.TYPE_10__* %1, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %1, i64 0, i32 3
%6 = load %struct.TYPE_9__*, %struct.TYPE_9__** %5
%7 = icmp eq %struct.TYPE_9__* %6, null
br i1 %7, label %23, label %8
8: ; preds = %4
%9 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %6, i64 0, i32 0
%10 = load i32 (i32**, %struct.TYPE_10__*)*, i32 (i32**, %struct.TYPE_10__*)** %9
%11 = icmp eq i32 (i32**, %struct.TYPE_10__*)* %10, null
br i1 %11, label %23, label %12
12: ; preds = %8
%13 = tail call i32 %10(i32** %0, %struct.TYPE_10__* %1)
br label %61
14: ; preds = %2
%15 = bitcast i32** %0 to %struct.TYPE_8__**
%16 = load %struct.TYPE_8__*, %struct.TYPE_8__** %15
%17 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %16, i64 0, i32 1, i32 0
%20 = bitcast i32* %19 to i32**
%21 = load i32*, i32** %20
%22 = icmp eq i32* %21, null
br i1 %22, label %61, label %38
23: ; preds = %4, %8
%24 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %1, i64 0, i32 0
%25 = load i64, i64* %24
%26 = load i64, i64* @ASN1_ITYPE_MSTRING
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32*, i32** %0
%30 = icmp eq i32* %29, null
br i1 %30, label %61, label %55
31: ; preds = %23
%32 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %1, i64 0, i32 1
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 130
br i1 %34, label %45, label %35
35: ; preds = %31
%36 = load i32*, i32** %0
%37 = icmp eq i32* %36, null
br i1 %37, label %61, label %38
38: ; preds = %35, %14
%39 = phi i32* [ %36, %35 ], [ %21, %14 ]
%40 = phi i32 [ %33, %35 ], [ %18, %14 ]
%41 = phi i32** [ %0, %35 ], [ %20, %14 ]
switch i32 %40, label %55 [
i32 128, label %42
i32 130, label %44
i32 129, label %59
i32 131, label %52
]
42: ; preds = %38
%43 = tail call i32 @ASN1_OBJECT_free(i32* %39)
br label %59
44: ; preds = %38
br i1 %3, label %50, label %45
45: ; preds = %31, %44
%46 = phi i32** [ %41, %44 ], [ %0, %31 ]
%47 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %1, i64 0, i32 2
%48 = load i32, i32* %47
%49 = bitcast i32** %46 to i32*
store i32 %48, i32* %49
br label %61
50: ; preds = %44
%51 = bitcast i32** %41 to i32*
store i32 -1, i32* %51
br label %61
52: ; preds = %38
tail call void @ASN1_primitive_free(i32** %41, %struct.TYPE_10__* null)
%53 = load i32*, i32** %41
%54 = tail call i32 @OPENSSL_free(i32* %53)
br label %59
55: ; preds = %28, %38
%56 = phi i32* [ %39, %38 ], [ %29, %28 ]
%57 = phi i32** [ %41, %38 ], [ %0, %28 ]
%58 = tail call i32 @ASN1_STRING_free(i32* %56)
store i32* null, i32** %57
br label %59
59: ; preds = %55, %52, %38, %42
%60 = phi i32** [ %57, %55 ], [ %41, %52 ], [ %41, %38 ], [ %41, %42 ]
store i32* null, i32** %60
br label %61
61: ; preds = %45, %50, %35, %28, %12, %14, %59
ret void
}