#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;
  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:
    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)
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,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     118d <ASN1_primitive_new+0x5d>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    12e0 <ASN1_primitive_new+0x1b0>
jmp    1192 <ASN1_primitive_new+0x62>
cmpq   $0x0,-0x18(%rbp)
je     11b4 <ASN1_primitive_new+0x84>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <ASN1_primitive_new+0x90>
movl   $0xffffffff,-0x24(%rbp)
jmp    11ca <ASN1_primitive_new+0x9a>
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     12ad <ASN1_primitive_new+0x17d>
mov    -0x38(%rbp),%rax
lea    0xe16(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dde(%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    12e0 <ASN1_primitive_new+0x1b0>
cmpq   $0x0,-0x18(%rbp)
je     1234 <ASN1_primitive_new+0x104>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    123e <ASN1_primitive_new+0x10e>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12e0 <ASN1_primitive_new+0x1b0>
mov    -0x10(%rbp),%rax
mov    $0x1,%ecx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12e0 <ASN1_primitive_new+0x1b0>
mov    $0x10,%edi
call   1040 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1287 <ASN1_primitive_new+0x157>
movl   $0x0,-0x4(%rbp)
jmp    12e0 <ASN1_primitive_new+0x1b0>
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    12bf <ASN1_primitive_new+0x18f>
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     12d9 <ASN1_primitive_new+0x1a9>
movl   $0x1,-0x4(%rbp)
jmp    12e0 <ASN1_primitive_new+0x1b0>
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    $0xffffffff,%edi
test   %rsi,%rsi
je     1164 <ASN1_primitive_new+0x34>
mov    0x10(%rsi),%rax
test   %rax,%rax
je     1155 <ASN1_primitive_new+0x25>
mov    (%rax),%rax
test   %rax,%rax
je     1155 <ASN1_primitive_new+0x25>
mov    %rbx,%rdi
pop    %rbx
jmp    *%rax
mov    (%rsi),%rax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%rax
jne    1179 <ASN1_primitive_new+0x49>
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     1164 <ASN1_primitive_new+0x34>
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1030 <OBJ_nid2obj@plt>
mov    %rax,(%rbx)
jmp    11b5 <ASN1_primitive_new+0x85>
movq   $0x1,(%rbx)
jmp    11b5 <ASN1_primitive_new+0x85>
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     11de <ASN1_primitive_new+0xae>
mov    %rax,%rcx
movq   $0x0,0x8(%rax)
movl   $0xffffffff,(%rax)
jmp    116c <ASN1_primitive_new+0x3c>
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 = icmp ne %struct.TYPE_11__* %9, null
br i1 %10, label %11, label %34
11: ; preds = %2
%12 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%13 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %12, i32 0, i32 3
%14 = load %struct.TYPE_10__*, %struct.TYPE_10__** %13
%15 = icmp ne %struct.TYPE_10__* %14, null
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%18 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %17, i32 0, i32 3
%19 = load %struct.TYPE_10__*, %struct.TYPE_10__** %18
store %struct.TYPE_10__* %19, %struct.TYPE_10__** %8
%20 = load %struct.TYPE_10__*, %struct.TYPE_10__** %8
%21 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %20, i32 0, i32 0
%22 = bitcast {}** %21 to i32 (i32**, %struct.TYPE_11__*)**
%23 = load i32 (i32**, %struct.TYPE_11__*)*, i32 (i32**, %struct.TYPE_11__*)** %22
%24 = icmp ne i32 (i32**, %struct.TYPE_11__*)* %23, null
br i1 %24, label %25, label %33
25: ; preds = %16
%26 = load %struct.TYPE_10__*, %struct.TYPE_10__** %8
%27 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %26, i32 0, i32 0
%28 = bitcast {}** %27 to i32 (i32**, %struct.TYPE_11__*)**
%29 = load i32 (i32**, %struct.TYPE_11__*)*, i32 (i32**, %struct.TYPE_11__*)** %28
%30 = load i32**, i32*** %4
%31 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%32 = call i32 %29(i32** %30, %struct.TYPE_11__* %31)
store i32 %32, i32* %3
br label %95
33: ; preds = %16
br label %34
34: ; preds = %33, %11, %2
%35 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%36 = icmp ne %struct.TYPE_11__* %35, null
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%39 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %38, i32 0, i32 0
%40 = load i64, i64* %39
%41 = load i64, i64* @ASN1_ITYPE_MSTRING
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %37, %34
store i32 -1, i32* %7
br label %48
44: ; preds = %37
%45 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%46 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %45, i32 0, i32 1
%47 = load i32, i32* %46
store i32 %47, i32* %7
br label %48
48: ; preds = %44, %43
%49 = load i32, i32* %7
switch i32 %49, label %84 [
i32 128, label %50
i32 130, label %55
i32 129, label %68
i32 131, label %70
]
50: ; preds = %48
%51 = load i32, i32* @NID_undef
%52 = call i64 @OBJ_nid2obj(i32 %51)
%53 = inttoptr i64 %52 to i32*
%54 = load i32**, i32*** %4
store i32* %53, i32** %54
store i32 1, i32* %3
br label %95
55: ; preds = %48
%56 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%57 = icmp ne %struct.TYPE_11__* %56, null
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load %struct.TYPE_11__*, %struct.TYPE_11__** %5
%60 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %59, i32 0, i32 2
%61 = load i32, i32* %60
%62 = load i32**, i32*** %4
%63 = bitcast i32** %62 to i32*
store i32 %61, i32* %63
br label %67
64: ; preds = %55
%65 = load i32**, i32*** %4
%66 = bitcast i32** %65 to i32*
store i32 -1, i32* %66
br label %67
67: ; preds = %64, %58
store i32 1, i32* %3
br label %95
68: ; preds = %48
%69 = load i32**, i32*** %4
store i32* inttoptr (i64 1 to i32*), i32** %69
store i32 1, i32* %3
br label %95
70: ; preds = %48
%71 = call %struct.TYPE_9__* @OPENSSL_malloc(i32 16)
store %struct.TYPE_9__* %71, %struct.TYPE_9__** %6
%72 = load %struct.TYPE_9__*, %struct.TYPE_9__** %6
%73 = icmp ne %struct.TYPE_9__* %72, null
br i1 %73, label %75, label %74
74: ; preds = %70
store i32 0, i32* %3
br label %95
75: ; preds = %70
%76 = load %struct.TYPE_9__*, %struct.TYPE_9__** %6
%77 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %76, i32 0, i32 1
%78 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %77, i32 0, i32 0
store i32* null, i32** %78
%79 = load %struct.TYPE_9__*, %struct.TYPE_9__** %6
%80 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %79, i32 0, i32 0
store i32 -1, i32* %80
%81 = load %struct.TYPE_9__*, %struct.TYPE_9__** %6
%82 = bitcast %struct.TYPE_9__* %81 to i32*
%83 = load i32**, i32*** %4
store i32* %82, i32** %83
br label %89
84: ; preds = %48
%85 = load i32, i32* %7
%86 = call i64 @ASN1_STRING_type_new(i32 %85)
%87 = inttoptr i64 %86 to i32*
%88 = load i32**, i32*** %4
store i32* %87, i32** %88
br label %89
89: ; preds = %84, %75
%90 = load i32**, i32*** %4
%91 = load i32*, i32** %90
%92 = icmp ne i32* %91, null
br i1 %92, label %93, label %94
93: ; preds = %89
store i32 1, i32* %3
br label %95
94: ; preds = %89
store i32 0, i32* %3
br label %95
95: ; preds = %94, %93, %74, %68, %67, %50, %25
%96 = load i32, i32* %3
ret i32 %96
}

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 = icmp eq %struct.TYPE_11__* %1, null
br i1 %3, label %37, label %4
4: ; preds = %2
%5 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %1, i64 0, i32 3
%6 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%7 = icmp eq %struct.TYPE_10__* %6, null
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = bitcast %struct.TYPE_10__* %6 to i32 (i32**, %struct.TYPE_11__*)**
%10 = load i32 (i32**, %struct.TYPE_11__*)*, i32 (i32**, %struct.TYPE_11__*)** %9
%11 = icmp eq i32 (i32**, %struct.TYPE_11__*)* %10, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 %10(i32** %0, %struct.TYPE_11__* %1)
br label %45
14: ; preds = %8, %4
%15 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %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_11__, %struct.TYPE_11__* %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 %45
26: ; preds = %19
%27 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %1, i64 0, i32 2
%28 = load i32, i32* %27
%29 = bitcast i32** %0 to i32*
store i32 %28, i32* %29
br label %45
30: ; preds = %19
store i32* inttoptr (i64 1 to i32*), i32** %0
br label %45
31: ; preds = %19
%32 = tail call %struct.TYPE_9__* @OPENSSL_malloc(i32 16)
%33 = icmp eq %struct.TYPE_9__* %32, null
br i1 %33, label %45, label %34
34: ; preds = %31
%35 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %32, i64 0, i32 1, i32 0
store i32* null, i32** %35
%36 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %32, i64 0, i32 0
store i32 -1, i32* %36
br label %41
37: ; preds = %14, %2, %19
%38 = phi i32 [ %21, %19 ], [ -1, %2 ], [ -1, %14 ]
%39 = tail call i64 @ASN1_STRING_type_new(i32 %38)
%40 = inttoptr i64 %39 to i32*
br label %41
41: ; preds = %37, %34
%42 = phi i32* [ %36, %34 ], [ %40, %37 ]
store i32* %42, i32** %0
%43 = icmp ne i32* %42, null
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %12, %41, %31, %26, %30, %22
%46 = phi i32 [ 1, %30 ], [ 1, %22 ], [ %13, %12 ], [ 1, %26 ], [ 0, %31 ], [ %44, %41 ]
ret i32 %46
}