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

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

/* Variables and functions */
scalar_t__ ASN1_ITYPE_MSTRING;
scalar_t__ 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_4__ const *);
int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
  ASN1_TYPE *typ;
  int utype;
  const ASN1_PRIMITIVE_FUNCS *pf;
  pf = it->funcs;
  if (pf && 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:
    if (it)
      *(ASN1_BOOLEAN *)pval = it->size;
    else
      *(ASN1_BOOLEAN *)pval = -1;
    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:
    *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
    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)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     117e <ASN1_primitive_new+0x4e>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     117e <ASN1_primitive_new+0x4e>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    12cc <ASN1_primitive_new+0x19c>
cmpq   $0x0,-0x18(%rbp)
je     11a0 <ASN1_primitive_new+0x70>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%rax
jne    11ac <ASN1_primitive_new+0x7c>
movl   $0xffffffff,-0x24(%rbp)
jmp    11b6 <ASN1_primitive_new+0x86>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x3,%eax
ja     1299 <ASN1_primitive_new+0x169>
mov    -0x38(%rbp),%rax
lea    0xe2a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2df2(%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    12cc <ASN1_primitive_new+0x19c>
cmpq   $0x0,-0x18(%rbp)
je     1220 <ASN1_primitive_new+0xf0>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    122a <ASN1_primitive_new+0xfa>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12cc <ASN1_primitive_new+0x19c>
mov    -0x10(%rbp),%rax
mov    $0x1,%ecx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12cc <ASN1_primitive_new+0x19c>
mov    $0x10,%edi
call   1040 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1273 <ASN1_primitive_new+0x143>
movl   $0x0,-0x4(%rbp)
jmp    12cc <ASN1_primitive_new+0x19c>
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    12ab <ASN1_primitive_new+0x17b>
mov    -0x24(%rbp),%edi
call   1050 <ASN1_STRING_type_new@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12c5 <ASN1_primitive_new+0x195>
movl   $0x1,-0x4(%rbp)
jmp    12cc <ASN1_primitive_new+0x19c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_primitive_new>:
push   %rbx
mov    %rdi,%rbx
mov    0x10(%rsi),%rax
test   %rax,%rax
je     114b <ASN1_primitive_new+0x1b>
mov    (%rax),%rax
test   %rax,%rax
je     114b <ASN1_primitive_new+0x1b>
mov    %rbx,%rdi
pop    %rbx
jmp    *%rax
mov    (%rsi),%rax
mov    0x2e8b(%rip),%rcx
mov    $0xffffffff,%edi
cmp    (%rcx),%rax
jne    1174 <ASN1_primitive_new+0x44>
call   1050 <ASN1_STRING_type_new@plt>
mov    %rax,%rcx
mov    %rcx,(%rbx)
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
pop    %rbx
ret
mov    0x8(%rsi),%edi
lea    -0x80(%rdi),%eax
cmp    $0x3,%eax
ja     115f <ASN1_primitive_new+0x2f>
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1030 <OBJ_nid2obj@plt>
mov    %rax,(%rbx)
jmp    11b0 <ASN1_primitive_new+0x80>
movq   $0x1,(%rbx)
jmp    11b0 <ASN1_primitive_new+0x80>
mov    0xc(%rsi),%eax
mov    %eax,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret
mov    $0x10,%edi
call   1040 <OPENSSL_malloc@plt>
test   %rax,%rax
je     11d9 <ASN1_primitive_new+0xa9>
mov    %rax,%rcx
movq   $0x0,0x8(%rax)
movl   $0xffffffff,(%rax)
jmp    1167 <ASN1_primitive_new+0x37>
xor    %eax,%eax
pop    %rbx
ret

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

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