#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_14__ TYPE_5__;
typedef struct TYPE_13__ TYPE_4__;
typedef struct TYPE_12__ TYPE_3__;
typedef struct TYPE_11__ TYPE_2__;
typedef struct TYPE_10__ TYPE_1__;

/* Type definitions */
struct TYPE_14__ {
  scalar_t__ itype;
  int utype;
  int /*<<< orphan*/ size;
  TYPE_4__ *funcs;
};
struct TYPE_13__ {
  int (*prim_new)(int /*<<< orphan*/ **, TYPE_5__ const *);
};
struct TYPE_12__ {
  int /*<<< orphan*/ flags;
};
struct TYPE_10__ {
  int /*<<< orphan*/ *ptr;
};
struct TYPE_11__ {
  int type;
  TYPE_1__ value;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_2__ ASN1_TYPE;
typedef TYPE_3__ ASN1_STRING;
typedef TYPE_4__ ASN1_PRIMITIVE_FUNCS;
typedef TYPE_5__ ASN1_ITEM;
typedef int /*<<< orphan*/ ASN1_BOOLEAN;

/* Variables and functions */
scalar_t__ ASN1_ITYPE_MSTRING;
int /*<<< orphan*/ ASN1_STRING_FLAG_MSTRING;
TYPE_3__ *ASN1_STRING_type_new(int);
int /*<<< orphan*/ NID_undef;
scalar_t__ OBJ_nid2obj(int /*<<< orphan*/);
TYPE_2__ *OPENSSL_malloc(int);
#define V_ASN1_ANY 131
#define V_ASN1_BOOLEAN 130
#define V_ASN1_NULL 129
#define V_ASN1_OBJECT 128
int stub1(int /*<<< orphan*/ **, TYPE_5__ const *);
int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
  ASN1_TYPE *typ;
  ASN1_STRING *str;
  int utype;
  if (!it)
    return 0;
  if (it->funcs) {
    const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
    if (pf->prim_new)
      return pf->prim_new(pval, it);
  }
  if (it->itype == ASN1_ITYPE_MSTRING)
    utype = -1;
  else
    utype = it->utype;
  switch (utype) {
  case V_ASN1_OBJECT:
    *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
    return 1;
  case V_ASN1_BOOLEAN:
    *(ASN1_BOOLEAN *)pval = it->size;
    return 1;
  case V_ASN1_NULL:
    *pval = (ASN1_VALUE *)1;
    return 1;
  case V_ASN1_ANY:
    typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
    if (!typ)
      return 0;
    typ->value.ptr = NULL;
    typ->type = -1;
    *pval = (ASN1_VALUE *)typ;
    break;
  default:
    str = ASN1_STRING_type_new(utype);
    if (it->itype == ASN1_ITYPE_MSTRING && str)
      str->flags |= ASN1_STRING_FLAG_MSTRING;
    *pval = (ASN1_VALUE *)str;
    break;
  }
  if (*pval)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<ASN1_primitive_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1157 <ASN1_primitive_new+0x27>
movl   $0x0,-0x4(%rbp)
jmp    12ff <ASN1_primitive_new+0x1cf>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     119e <ASN1_primitive_new+0x6e>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpq   $0x0,(%rax)
je     1199 <ASN1_primitive_new+0x69>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    12ff <ASN1_primitive_new+0x1cf>
jmp    119e <ASN1_primitive_new+0x6e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
jne    11c1 <ASN1_primitive_new+0x91>
movl   $0xffffffff,-0x2c(%rbp)
jmp    11cb <ASN1_primitive_new+0x9b>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x3,%eax
ja     1294 <ASN1_primitive_new+0x164>
mov    -0x40(%rbp),%rax
lea    0xe15(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1030 <OBJ_nid2obj@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12ff <ASN1_primitive_new+0x1cf>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12ff <ASN1_primitive_new+0x1cf>
mov    -0x10(%rbp),%rax
mov    $0x1,%ecx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12ff <ASN1_primitive_new+0x1cf>
mov    $0x10,%edi
call   1040 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126e <ASN1_primitive_new+0x13e>
movl   $0x0,-0x4(%rbp)
jmp    12ff <ASN1_primitive_new+0x1cf>
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    12de <ASN1_primitive_new+0x1ae>
mov    -0x2c(%rbp),%edi
call   1050 <ASN1_STRING_type_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2d2a(%rip),%rcx
cmp    (%rcx),%rax
jne    12d3 <ASN1_primitive_new+0x1a3>
cmpq   $0x0,-0x28(%rbp)
je     12d3 <ASN1_primitive_new+0x1a3>
mov    0x2d1f(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12f8 <ASN1_primitive_new+0x1c8>
movl   $0x1,-0x4(%rbp)
jmp    12ff <ASN1_primitive_new+0x1cf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_primitive_new>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rsi,%rsi
je     11a4 <ASN1_primitive_new+0x74>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x10(%rsi),%rax
test   %rax,%rax
je     1167 <ASN1_primitive_new+0x37>
mov    (%rax),%rax
test   %rax,%rax
je     1167 <ASN1_primitive_new+0x37>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    *%rax
mov    (%rbx),%rax
mov    0x2e67(%rip),%r15
mov    $0xffffffff,%edi
cmp    (%r15),%rax
jne    11b1 <ASN1_primitive_new+0x81>
call   1050 <ASN1_STRING_type_new@plt>
mov    (%rbx),%rcx
cmp    (%r15),%rcx
jne    1198 <ASN1_primitive_new+0x68>
test   %rax,%rax
je     1198 <ASN1_primitive_new+0x68>
mov    0x2e54(%rip),%rcx
mov    (%rcx),%ecx
or     %ecx,(%rax)
mov    %rax,(%r14)
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%edi
lea    -0x80(%rdi),%eax
cmp    $0x3,%eax
ja     117b <ASN1_primitive_new+0x4b>
lea    0xe3d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1030 <OBJ_nid2obj@plt>
mov    %rax,(%r14)
mov    $0x1,%ebp
jmp    11a4 <ASN1_primitive_new+0x74>
movq   $0x1,(%r14)
mov    $0x1,%ebp
jmp    11a4 <ASN1_primitive_new+0x74>
mov    0xc(%rbx),%eax
mov    %eax,(%r14)
mov    $0x1,%ebp
jmp    11a4 <ASN1_primitive_new+0x74>
mov    $0x10,%edi
call   1040 <OPENSSL_malloc@plt>
test   %rax,%rax
je     11a4 <ASN1_primitive_new+0x74>
movq   $0x0,0x8(%rax)
movl   $0xffffffff,(%rax)
jmp    1198 <ASN1_primitive_new+0x68>

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

LLVM IR (-O2):
%struct.TYPE_14__ = type { i64, i32, i32, %struct.TYPE_13__* }
%struct.TYPE_13__ = type { {}* }
%struct.TYPE_11__ = type { i32, %struct.TYPE_10__ }
%struct.TYPE_10__ = type { i32* }
%struct.TYPE_12__ = type { i32 }
@ASN1_ITYPE_MSTRING = global i64 0
@NID_undef = global i32 0
@ASN1_STRING_FLAG_MSTRING = global i32 0
define i32 @ASN1_primitive_new(i32** %0, %struct.TYPE_14__* %1) {
%3 = icmp eq %struct.TYPE_14__* %1, null
br i1 %3, label %56, label %4
4: ; preds = %2
%5 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %1, i64 0, i32 3
%6 = load %struct.TYPE_13__*, %struct.TYPE_13__** %5
%7 = icmp eq %struct.TYPE_13__* %6, null
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = bitcast %struct.TYPE_13__* %6 to i32 (i32**, %struct.TYPE_14__*)**
%10 = load i32 (i32**, %struct.TYPE_14__*)*, i32 (i32**, %struct.TYPE_14__*)** %9
%11 = icmp eq i32 (i32**, %struct.TYPE_14__*)* %10, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 %10(i32** %0, %struct.TYPE_14__* %1)
br label %56
14: ; preds = %8, %4
%15 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %1, i64 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @ASN1_ITYPE_MSTRING
%18 = icmp eq i64 %16, %17
br i1 %18, label %37, label %19
19: ; preds = %14
%20 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %1, i64 0, i32 1
%21 = load i32, i32* %20
switch i32 %21, label %37 [
i32 128, label %22
i32 130, label %26
i32 129, label %30
i32 131, label %31
]
22: ; preds = %19
%23 = load i32, i32* @NID_undef
%24 = tail call i64 @OBJ_nid2obj(i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %0
br label %56
26: ; preds = %19
%27 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %1, i64 0, i32 2
%28 = load i32, i32* %27
%29 = bitcast i32** %0 to i32*
store i32 %28, i32* %29
br label %56
30: ; preds = %19
store i32* inttoptr (i64 1 to i32*), i32** %0
br label %56
31: ; preds = %19
%32 = tail call %struct.TYPE_11__* @OPENSSL_malloc(i32 16)
%33 = icmp eq %struct.TYPE_11__* %32, null
br i1 %33, label %56, label %34
34: ; preds = %31
%35 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %32, i64 0, i32 1, i32 0
store i32* null, i32** %35
%36 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %32, i64 0, i32 0
store i32 -1, i32* %36
br label %52
37: ; preds = %14, %19
%38 = phi i32 [ %21, %19 ], [ -1, %14 ]
%39 = tail call %struct.TYPE_12__* @ASN1_STRING_type_new(i32 %38)
%40 = load i64, i64* %15
%41 = load i64, i64* @ASN1_ITYPE_MSTRING
%42 = icmp eq i64 %40, %41
%43 = icmp ne %struct.TYPE_12__* %39, null
%44 = select i1 %42, i1 %43, i1 false
br i1 %44, label %45, label %50
45: ; preds = %37
%46 = load i32, i32* @ASN1_STRING_FLAG_MSTRING
%47 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %39, i64 0, i32 0
%48 = load i32, i32* %47
%49 = or i32 %48, %46
store i32 %49, i32* %47
br label %50
50: ; preds = %45, %37
%51 = getelementptr %struct.TYPE_12__, %struct.TYPE_12__* %39, i64 0, i32 0
br label %52
52: ; preds = %50, %34
%53 = phi i32* [ %36, %34 ], [ %51, %50 ]
store i32* %53, i32** %0
%54 = icmp ne i32* %53, null
%55 = zext i1 %54 to i32
br label %56
56: ; preds = %12, %52, %31, %2, %30, %26, %22
%57 = phi i32 [ 1, %30 ], [ 1, %26 ], [ 1, %22 ], [ %13, %12 ], [ 0, %2 ], [ 0, %31 ], [ %55, %52 ]
ret i32 %57
}