#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*/);
#define V_ASN1_ANY 131
#define V_ASN1_BOOLEAN 130
#define V_ASN1_NULL 129
#define V_ASN1_OBJECT 128
TYPE_2__ *malloc(int);
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 && it->funcs) {
    const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
    if (pf->prim_new)
      return pf->prim_new(pval, it);
  }
  if (!it || (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 = 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)
je     1192 <ASN1_primitive_new+0x62>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1192 <ASN1_primitive_new+0x62>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpq   $0x0,(%rax)
je     118d <ASN1_primitive_new+0x5d>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    12fe <ASN1_primitive_new+0x1ce>
jmp    1192 <ASN1_primitive_new+0x62>
cmpq   $0x0,-0x18(%rbp)
je     11b4 <ASN1_primitive_new+0x84>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <ASN1_primitive_new+0x90>
movl   $0xffffffff,-0x2c(%rbp)
jmp    11ca <ASN1_primitive_new+0x9a>
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     1293 <ASN1_primitive_new+0x163>
mov    -0x40(%rbp),%rax
lea    0xe16(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dd6(%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    12fe <ASN1_primitive_new+0x1ce>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12fe <ASN1_primitive_new+0x1ce>
mov    -0x10(%rbp),%rax
mov    $0x1,%ecx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12fe <ASN1_primitive_new+0x1ce>
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126d <ASN1_primitive_new+0x13d>
movl   $0x0,-0x4(%rbp)
jmp    12fe <ASN1_primitive_new+0x1ce>
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    12dd <ASN1_primitive_new+0x1ad>
mov    -0x2c(%rbp),%edi
call   1050 <ASN1_STRING_type_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2d2b(%rip),%rcx
cmp    (%rcx),%rax
jne    12d2 <ASN1_primitive_new+0x1a2>
cmpq   $0x0,-0x28(%rbp)
je     12d2 <ASN1_primitive_new+0x1a2>
mov    0x2d20(%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     12f7 <ASN1_primitive_new+0x1c7>
movl   $0x1,-0x4(%rbp)
jmp    12fe <ASN1_primitive_new+0x1ce>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_primitive_new>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0xffffffff,%edi
test   %rsi,%rsi
je     1173 <ASN1_primitive_new+0x43>
mov    0x10(%rbx),%rax
test   %rax,%rax
je     1164 <ASN1_primitive_new+0x34>
mov    (%rax),%rax
test   %rax,%rax
je     1164 <ASN1_primitive_new+0x34>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    *%rax
mov    (%rbx),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
jne    11ac <ASN1_primitive_new+0x7c>
call   1050 <ASN1_STRING_type_new@plt>
mov    (%rbx),%rcx
mov    0x2e56(%rip),%rdx
cmp    (%rdx),%rcx
jne    1197 <ASN1_primitive_new+0x67>
test   %rax,%rax
je     1197 <ASN1_primitive_new+0x67>
mov    0x2e55(%rip),%rcx
mov    (%rcx),%ecx
or     %ecx,(%rax)
mov    %rax,(%r14)
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rbx),%edi
lea    -0x80(%rdi),%eax
cmp    $0x3,%eax
ja     1173 <ASN1_primitive_new+0x43>
lea    0xe42(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1030 <OBJ_nid2obj@plt>
mov    %rax,(%r14)
mov    $0x1,%ecx
jmp    11a2 <ASN1_primitive_new+0x72>
movq   $0x1,(%r14)
mov    $0x1,%ecx
jmp    11a2 <ASN1_primitive_new+0x72>
mov    0xc(%rbx),%eax
mov    %eax,(%r14)
mov    $0x1,%ecx
jmp    11a2 <ASN1_primitive_new+0x72>
mov    $0x10,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     121c <ASN1_primitive_new+0xec>
movq   $0x0,0x8(%rax)
movl   $0xffffffff,(%rax)
jmp    1197 <ASN1_primitive_new+0x67>
xor    %ecx,%ecx
jmp    11a2 <ASN1_primitive_new+0x72>

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

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 %37, 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 %57
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 %57
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 %57
30: ; preds = %19
store i32* inttoptr (i64 1 to i32*), i32** %0
br label %57
31: ; preds = %19
%32 = tail call %struct.TYPE_11__* @malloc(i32 16)
%33 = icmp eq %struct.TYPE_11__* %32, null
br i1 %33, label %57, 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 %53
37: ; preds = %14, %2, %19
%38 = phi i32 [ %21, %19 ], [ -1, %2 ], [ -1, %14 ]
%39 = tail call %struct.TYPE_12__* @ASN1_STRING_type_new(i32 %38)
%40 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %1, i64 0, i32 0
%41 = load i64, i64* %40
%42 = load i64, i64* @ASN1_ITYPE_MSTRING
%43 = icmp eq i64 %41, %42
%44 = icmp ne %struct.TYPE_12__* %39, null
%45 = select i1 %43, i1 %44, i1 false
br i1 %45, label %46, label %51
46: ; preds = %37
%47 = load i32, i32* @ASN1_STRING_FLAG_MSTRING
%48 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %39, i64 0, i32 0
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
br label %51
51: ; preds = %46, %37
%52 = getelementptr %struct.TYPE_12__, %struct.TYPE_12__* %39, i64 0, i32 0
br label %53
53: ; preds = %51, %34
%54 = phi i32* [ %36, %34 ], [ %52, %51 ]
store i32* %54, i32** %0
%55 = icmp ne i32* %54, null
%56 = zext i1 %55 to i32
br label %57
57: ; preds = %12, %53, %31, %30, %26, %22
%58 = phi i32 [ 1, %30 ], [ 1, %26 ], [ 1, %22 ], [ %13, %12 ], [ 0, %31 ], [ %56, %53 ]
ret i32 %58
}