#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int utype;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_1__ ASN1_ITEM;

/* Variables and functions */
int ASN1_object_size(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ ASN1_put_object(unsigned char **, int /*<<< orphan*/, int,
                                   int, int);
int V_ASN1_OTHER;
int V_ASN1_SEQUENCE;
int V_ASN1_SET;
int asn1_ex_i2c(int /*<<< orphan*/ **, unsigned char *, int *,
                TYPE_1__ const *);
int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
                          const ASN1_ITEM *it, int tag, int aclass) {
  int len;
  int utype;
  int usetag;
  utype = it->utype;
  len = asn1_ex_i2c(pval, NULL, &utype, it);
  if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
      (utype == V_ASN1_OTHER))
    usetag = 0;
  else
    usetag = 1;
  if (len == -1)
    return 0;
  if (tag == -1)
    tag = utype;
  if (out) {
    if (usetag)
      ASN1_put_object(out, 0, len, tag, aclass);
    asn1_ex_i2c(pval, *out, &utype, it);
    *out += len;
  }
  if (usetag)
    return ASN1_object_size(0, len, tag);
  return len;
}


x86 assembly (clang, -O0):
<asn1_i2d_ex_primitive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
call   1030 <asn1_ex_i2c@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
je     11a2 <asn1_i2d_ex_primitive+0x72>
mov    -0x30(%rbp),%eax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
je     11a2 <asn1_i2d_ex_primitive+0x72>
mov    -0x30(%rbp),%eax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%eax
jne    11ae <asn1_i2d_ex_primitive+0x7e>
movl   $0x0,-0x34(%rbp)
jmp    11b5 <asn1_i2d_ex_primitive+0x85>
movl   $0x1,-0x34(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11cb <asn1_i2d_ex_primitive+0x9b>
movl   $0x0,-0x4(%rbp)
jmp    1255 <asn1_i2d_ex_primitive+0x125>
cmpl   $0xffffffff,-0x24(%rbp)
jne    11db <asn1_i2d_ex_primitive+0xab>
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1230 <asn1_i2d_ex_primitive+0x100>
cmpl   $0x0,-0x34(%rbp)
je     1205 <asn1_i2d_ex_primitive+0xd5>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
xor    %esi,%esi
call   1040 <ASN1_put_object@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdx
call   1030 <asn1_ex_i2c@plt>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
cmpl   $0x0,-0x34(%rbp)
je     124f <asn1_i2d_ex_primitive+0x11f>
mov    -0x2c(%rbp),%esi
mov    -0x24(%rbp),%edx
xor    %edi,%edi
call   1050 <ASN1_object_size@plt>
mov    %eax,-0x4(%rbp)
jmp    1255 <asn1_i2d_ex_primitive+0x125>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_i2d_ex_primitive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,0x8(%rsp)
mov    %ecx,0xc(%rsp)
mov    %rdx,%rbx
mov    %rsi,%r13
mov    (%rdx),%eax
mov    %eax,0x4(%rsp)
xor    %r14d,%r14d
lea    0x4(%rsp),%rdx
mov    %rdi,0x10(%rsp)
xor    %esi,%esi
mov    %rbx,%rcx
call   1030 <asn1_ex_i2c@plt>
mov    %eax,%r15d
mov    0x4(%rsp),%ebp
mov    0x2e50(%rip),%rax
cmp    (%rax),%ebp
sete   %r12b
mov    0x2e53(%rip),%rax
cmp    (%rax),%ebp
sete   %al
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%ebp
sete   %cl
cmp    $0xffffffff,%r15d
je     1200 <asn1_i2d_ex_primitive+0xd0>
or     %al,%r12b
or     %cl,%r12b
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
cmovne %eax,%ebp
test   %r13,%r13
je     11e7 <asn1_i2d_ex_primitive+0xb7>
test   %r12b,%r12b
jne    11ca <asn1_i2d_ex_primitive+0x9a>
mov    %r13,%rdi
xor    %esi,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    0x8(%rsp),%r8d
call   1040 <ASN1_put_object@plt>
mov    0x0(%r13),%rsi
lea    0x4(%rsp),%rdx
mov    0x10(%rsp),%rdi
mov    %rbx,%rcx
call   1030 <asn1_ex_i2c@plt>
movslq %r15d,%rax
add    %rax,0x0(%r13)
test   %r12b,%r12b
je     11f1 <asn1_i2d_ex_primitive+0xc1>
mov    %r15d,%r14d
jmp    1200 <asn1_i2d_ex_primitive+0xd0>
xor    %edi,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1050 <ASN1_object_size@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32 }
@V_ASN1_SEQUENCE = global i32 0
@V_ASN1_SET = global i32 0
@V_ASN1_OTHER = global i32 0
define i32 @asn1_i2d_ex_primitive(i32** %0, i8** %1, %struct.TYPE_4__* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i8**
%9 = alloca %struct.TYPE_4__*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32** %0, i32*** %7
store i8** %1, i8*** %8
store %struct.TYPE_4__* %2, %struct.TYPE_4__** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%15 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %13
%18 = load i32**, i32*** %7
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%20 = call i32 @asn1_ex_i2c(i32** %18, i8* null, i32* %13, %struct.TYPE_4__* %19)
store i32 %20, i32* %12
%21 = load i32, i32* %13
%22 = load i32, i32* @V_ASN1_SEQUENCE
%23 = icmp eq i32 %21, %22
br i1 %23, label %32, label %24
24: ; preds = %5
%25 = load i32, i32* %13
%26 = load i32, i32* @V_ASN1_SET
%27 = icmp eq i32 %25, %26
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i32, i32* %13
%30 = load i32, i32* @V_ASN1_OTHER
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28, %24, %5
store i32 0, i32* %14
br label %34
33: ; preds = %28
store i32 1, i32* %14
br label %34
34: ; preds = %33, %32
%35 = load i32, i32* %12
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 0, i32* %6
br label %75
38: ; preds = %34
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = load i32, i32* %13
store i32 %42, i32* %10
br label %43
43: ; preds = %41, %38
%44 = load i8**, i8*** %8
%45 = icmp ne i8** %44, null
br i1 %45, label %46, label %66
46: ; preds = %43
%47 = load i32, i32* %14
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = load i8**, i8*** %8
%51 = load i32, i32* %12
%52 = load i32, i32* %10
%53 = load i32, i32* %11
%54 = call i32 @ASN1_put_object(i8** %50, i32 0, i32 %51, i32 %52, i32 %53)
br label %55
55: ; preds = %49, %46
%56 = load i32**, i32*** %7
%57 = load i8**, i8*** %8
%58 = load i8*, i8** %57
%59 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%60 = call i32 @asn1_ex_i2c(i32** %56, i8* %58, i32* %13, %struct.TYPE_4__* %59)
%61 = load i32, i32* %12
%62 = load i8**, i8*** %8
%63 = load i8*, i8** %62
%64 = sext i32 %61 to i64
%65 = getelementptr inbounds i8, i8* %63, i64 %64
store i8* %65, i8** %62
br label %66
66: ; preds = %55, %43
%67 = load i32, i32* %14
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load i32, i32* %12
%71 = load i32, i32* %10
%72 = call i32 @ASN1_object_size(i32 0, i32 %70, i32 %71)
store i32 %72, i32* %6
br label %75
73: ; preds = %66
%74 = load i32, i32* %12
store i32 %74, i32* %6
br label %75
75: ; preds = %73, %69, %37
%76 = load i32, i32* %6
ret i32 %76
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 }
@V_ASN1_SEQUENCE = global i32 0
@V_ASN1_SET = global i32 0
@V_ASN1_OTHER = global i32 0
define i32 @asn1_i2d_ex_primitive(i32** %0, i8** %1, %struct.TYPE_4__* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%9 = load i32, i32* %8
store i32 %9, i32* %6
%10 = call i32 @asn1_ex_i2c(i32** %0, i8* null, i32* %6, %struct.TYPE_4__* %2)
%11 = load i32, i32* %6
%12 = load i32, i32* @V_ASN1_SEQUENCE
%13 = icmp eq i32 %11, %12
%14 = load i32, i32* @V_ASN1_SET
%15 = icmp eq i32 %11, %14
%16 = select i1 %13, i1 true, i1 %15
%17 = load i32, i32* @V_ASN1_OTHER
%18 = icmp eq i32 %11, %17
%19 = select i1 %16, i1 true, i1 %18
%20 = icmp eq i32 %10, -1
br i1 %20, label %37, label %21
21: ; preds = %5
%22 = icmp eq i32 %3, -1
%23 = select i1 %22, i32 %11, i32 %3
%24 = icmp eq i8** %1, null
br i1 %24, label %34, label %25
25: ; preds = %21
br i1 %19, label %28, label %26
26: ; preds = %25
%27 = call i32 @ASN1_put_object(i8** %1, i32 0, i32 %10, i32 %23, i32 %4)
br label %28
28: ; preds = %26, %25
%29 = load i8*, i8** %1
%30 = call i32 @asn1_ex_i2c(i32** %0, i8* %29, i32* %6, %struct.TYPE_4__* %2)
%31 = load i8*, i8** %1
%32 = sext i32 %10 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %1
br label %34
34: ; preds = %28, %21
br i1 %19, label %37, label %35
35: ; preds = %34
%36 = call i32 @ASN1_object_size(i32 0, i32 %10, i32 %23)
br label %37
37: ; preds = %34, %5, %35
%38 = phi i32 [ %36, %35 ], [ 0, %5 ], [ %10, %34 ]
ret i32 %38
}