#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, int, int);
int /*<<< orphan*/ ASN1_put_eoc(unsigned char **);
int /*<<< orphan*/ ASN1_put_object(unsigned char **, int, 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;
  int ndef = 0;
  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 (len == -2) {
    ndef = 2;
    len = 0;
  }
  if (tag == -1)
    tag = utype;
  if (out) {
    if (usetag)
      ASN1_put_object(out, ndef, len, tag, aclass);
    asn1_ex_i2c(pval, *out, &utype, it);
    if (ndef)
      ASN1_put_eoc(out);
    else
      *out += len;
  }
  if (usetag)
    return ASN1_object_size(ndef, 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)
movl   $0x0,-0x38(%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    0x2e3b(%rip),%rcx
cmp    (%rcx),%eax
je     11b9 <asn1_i2d_ex_primitive+0x79>
mov    -0x30(%rbp),%eax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%eax
je     11b9 <asn1_i2d_ex_primitive+0x79>
mov    -0x30(%rbp),%eax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%eax
jne    11c5 <asn1_i2d_ex_primitive+0x85>
movl   $0x0,-0x34(%rbp)
jmp    11cc <asn1_i2d_ex_primitive+0x8c>
movl   $0x1,-0x34(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11e2 <asn1_i2d_ex_primitive+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <asn1_i2d_ex_primitive+0x163>
cmpl   $0xfffffffe,-0x2c(%rbp)
jne    11fa <asn1_i2d_ex_primitive+0xba>
movl   $0x2,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    120a <asn1_i2d_ex_primitive+0xca>
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     127d <asn1_i2d_ex_primitive+0x13d>
cmpl   $0x0,-0x34(%rbp)
je     1235 <asn1_i2d_ex_primitive+0xf5>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
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>
cmpl   $0x0,-0x38(%rbp)
je     1265 <asn1_i2d_ex_primitive+0x125>
mov    -0x18(%rbp),%rdi
call   1060 <ASN1_put_eoc@plt>
jmp    1278 <asn1_i2d_ex_primitive+0x138>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
jmp    127d <asn1_i2d_ex_primitive+0x13d>
cmpl   $0x0,-0x34(%rbp)
je     129d <asn1_i2d_ex_primitive+0x15d>
mov    -0x38(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <ASN1_object_size@plt>
mov    %eax,-0x4(%rbp)
jmp    12a3 <asn1_i2d_ex_primitive+0x163>
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    $0x28,%rsp
mov    %r8d,0x8(%rsp)
mov    %ecx,0xc(%rsp)
mov    %rdx,%rbx
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
mov    (%rdx),%eax
mov    %eax,0x4(%rsp)
xor    %r15d,%r15d
lea    0x4(%rsp),%rdx
xor    %esi,%esi
mov    %rbx,%rcx
call   1030 <asn1_ex_i2c@plt>
mov    %eax,%r13d
mov    0x4(%rsp),%ebp
mov    0x2e40(%rip),%rax
cmp    (%rax),%ebp
sete   %r12b
mov    0x2e43(%rip),%rax
cmp    (%rax),%ebp
sete   %al
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%ebp
sete   %cl
cmp    $0xffffffff,%r13d
je     1242 <asn1_i2d_ex_primitive+0x102>
mov    %rbx,0x18(%rsp)
mov    %r14,0x20(%rsp)
or     %al,%r12b
or     %cl,%r12b
xor    %r15d,%r15d
xor    %r14d,%r14d
cmp    $0xfffffffe,%r13d
sete   %r14b
cmovne %r13d,%r15d
add    %r14d,%r14d
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
cmovne %eax,%ebp
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     122d <asn1_i2d_ex_primitive+0xed>
test   %r12b,%r12b
jne    1205 <asn1_i2d_ex_primitive+0xc5>
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    0x8(%rsp),%r8d
call   1040 <ASN1_put_object@plt>
mov    0x10(%rsp),%rdi
mov    %rdi,%rbx
mov    (%rdi),%rsi
lea    0x4(%rsp),%rdx
mov    0x20(%rsp),%rdi
mov    0x18(%rsp),%rcx
call   1030 <asn1_ex_i2c@plt>
cmp    $0xfffffffe,%r13d
jne    1254 <asn1_i2d_ex_primitive+0x114>
mov    %rbx,%rdi
call   1060 <ASN1_put_eoc@plt>
test   %r12b,%r12b
jne    1242 <asn1_i2d_ex_primitive+0x102>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1050 <ASN1_object_size@plt>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %r15d,%rax
add    %rax,(%rbx)
test   %r12b,%r12b
je     1232 <asn1_i2d_ex_primitive+0xf2>
jmp    1242 <asn1_i2d_ex_primitive+0x102>

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
%15 = 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
store i32 0, i32* %15
%16 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %13
%19 = load i32**, i32*** %7
%20 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%21 = call i32 @asn1_ex_i2c(i32** %19, i8* null, i32* %13, %struct.TYPE_4__* %20)
store i32 %21, i32* %12
%22 = load i32, i32* %13
%23 = load i32, i32* @V_ASN1_SEQUENCE
%24 = icmp eq i32 %22, %23
br i1 %24, label %33, label %25
25: ; preds = %5
%26 = load i32, i32* %13
%27 = load i32, i32* @V_ASN1_SET
%28 = icmp eq i32 %26, %27
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i32, i32* %13
%31 = load i32, i32* @V_ASN1_OTHER
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29, %25, %5
store i32 0, i32* %14
br label %35
34: ; preds = %29
store i32 1, i32* %14
br label %35
35: ; preds = %34, %33
%36 = load i32, i32* %12
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 0, i32* %6
br label %89
39: ; preds = %35
%40 = load i32, i32* %12
%41 = icmp eq i32 %40, -2
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 2, i32* %15
store i32 0, i32* %12
br label %43
43: ; preds = %42, %39
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = load i32, i32* %13
store i32 %47, i32* %10
br label %48
48: ; preds = %46, %43
%49 = load i8**, i8*** %8
%50 = icmp ne i8** %49, null
br i1 %50, label %51, label %79
51: ; preds = %48
%52 = load i32, i32* %14
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %51
%55 = load i8**, i8*** %8
%56 = load i32, i32* %15
%57 = load i32, i32* %12
%58 = load i32, i32* %10
%59 = load i32, i32* %11
%60 = call i32 @ASN1_put_object(i8** %55, i32 %56, i32 %57, i32 %58, i32 %59)
br label %61
61: ; preds = %54, %51
%62 = load i32**, i32*** %7
%63 = load i8**, i8*** %8
%64 = load i8*, i8** %63
%65 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%66 = call i32 @asn1_ex_i2c(i32** %62, i8* %64, i32* %13, %struct.TYPE_4__* %65)
%67 = load i32, i32* %15
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %61
%70 = load i8**, i8*** %8
%71 = call i32 @ASN1_put_eoc(i8** %70)
br label %78
72: ; preds = %61
%73 = load i32, i32* %12
%74 = load i8**, i8*** %8
%75 = load i8*, i8** %74
%76 = sext i32 %73 to i64
%77 = getelementptr inbounds i8, i8* %75, i64 %76
store i8* %77, i8** %74
br label %78
78: ; preds = %72, %69
br label %79
79: ; preds = %78, %48
%80 = load i32, i32* %14
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %87
82: ; preds = %79
%83 = load i32, i32* %15
%84 = load i32, i32* %12
%85 = load i32, i32* %10
%86 = call i32 @ASN1_object_size(i32 %83, i32 %84, i32 %85)
store i32 %86, i32* %6
br label %89
87: ; preds = %79
%88 = load i32, i32* %12
store i32 %88, i32* %6
br label %89
89: ; preds = %87, %82, %38
%90 = load i32, i32* %6
ret i32 %90
}

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 %43, label %21
21: ; preds = %5
%22 = icmp eq i32 %10, -2
%23 = select i1 %22, i32 0, i32 %10
%24 = select i1 %22, i32 2, i32 0
%25 = icmp eq i32 %3, -1
%26 = select i1 %25, i32 %11, i32 %3
%27 = icmp eq i8** %1, null
br i1 %27, label %40, label %28
28: ; preds = %21
br i1 %19, label %31, label %29
29: ; preds = %28
%30 = call i32 @ASN1_put_object(i8** %1, i32 %24, i32 %23, i32 %26, i32 %4)
br label %31
31: ; preds = %29, %28
%32 = load i8*, i8** %1
%33 = call i32 @asn1_ex_i2c(i32** %0, i8* %32, i32* %6, %struct.TYPE_4__* %2)
br i1 %22, label %34, label %36
34: ; preds = %31
%35 = call i32 @ASN1_put_eoc(i8** %1)
br label %40
36: ; preds = %31
%37 = load i8*, i8** %1
%38 = sext i32 %23 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8* %39, i8** %1
br label %40
40: ; preds = %34, %36, %21
br i1 %19, label %43, label %41
41: ; preds = %40
%42 = call i32 @ASN1_object_size(i32 %24, i32 %23, i32 %26)
br label %43
43: ; preds = %40, %5, %41
%44 = phi i32 [ %42, %41 ], [ 0, %5 ], [ %23, %40 ]
ret i32 %44
}