#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int boolean;
  int /*<<< orphan*/ *ptr;
};
struct TYPE_5__ {
  int type;
  TYPE_1__ value;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_2__ ASN1_TYPE;

/* Variables and functions */
int V_ASN1_BOOLEAN;
int /*<<< orphan*/ asn1_primitive_free(int /*<<< orphan*/ **,
                                       int /*<<< orphan*/ *);
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) {
  if (a->value.ptr != NULL) {
    ASN1_TYPE **tmp_a = &a;
    asn1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
  }
  a->type = type;
  if (type == V_ASN1_BOOLEAN)
    a->value.boolean = value ? 0xff : 0;
  else
    a->value.ptr = value;
}


x86 assembly (clang, -O0):
<ASN1_TYPE_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1147 <ASN1_TYPE_set+0x37>
lea    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <asn1_primitive_free@plt>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%eax
jne    1180 <ASN1_TYPE_set+0x70>
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
mov    $0xff,%eax
cmp    $0x0,%rdx
cmovne %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
jmp    118c <ASN1_TYPE_set+0x7c>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_TYPE_set>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,(%rsp)
cmpq   $0x0,0x10(%rdi)
je     1131 <ASN1_TYPE_set+0x21>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <asn1_primitive_free@plt>
mov    (%rsp),%rdi
mov    %ebp,(%rdi)
mov    0x2ea6(%rip),%rax
cmp    %ebp,(%rax)
jne    1150 <ASN1_TYPE_set+0x40>
xor    %eax,%eax
test   %rbx,%rbx
mov    $0xff,%ecx
cmove  %eax,%ecx
mov    %ecx,0x8(%rdi)
jmp    1154 <ASN1_TYPE_set+0x44>
mov    %rbx,0x10(%rdi)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32* }
@V_ASN1_BOOLEAN = global i32 0
define void @ASN1_TYPE_set(%struct.TYPE_5__* %0, i32 %1, i8* %2) {
%4 = alloca %struct.TYPE_5__*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.TYPE_5__**
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %9, i32 0, i32 1
%11 = load i32*, i32** %10
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
store %struct.TYPE_5__** %4, %struct.TYPE_5__*** %7
%14 = load %struct.TYPE_5__**, %struct.TYPE_5__*** %7
%15 = bitcast %struct.TYPE_5__** %14 to i32**
%16 = call i32 @asn1_primitive_free(i32** %15, i32* null)
br label %17
17: ; preds = %13, %3
%18 = load i32, i32* %5
%19 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %5
%22 = load i32, i32* @V_ASN1_BOOLEAN
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 255, i32 0
%29 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %29, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %30, i32 0, i32 0
store i32 %28, i32* %31
br label %38
32: ; preds = %17
%33 = load i8*, i8** %6
%34 = bitcast i8* %33 to i32*
%35 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%36 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 1
store i32* %34, i32** %37
br label %38
38: ; preds = %32, %24
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32* }
@V_ASN1_BOOLEAN = global i32 0
define void @ASN1_TYPE_set(%struct.TYPE_5__* %0, i32 %1, i8* %2) {
%4 = alloca %struct.TYPE_5__*
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %4
%5 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 1, i32 1
%6 = load i32*, i32** %5
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = bitcast %struct.TYPE_5__** %4 to i32**
%10 = call i32 @asn1_primitive_free(i32** %9, i32* null)
%11 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
br label %12
12: ; preds = %8, %3
%13 = phi %struct.TYPE_5__* [ %11, %8 ], [ %0, %3 ]
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 0
store i32 %1, i32* %14
%15 = load i32, i32* @V_ASN1_BOOLEAN
%16 = icmp eq i32 %15, %1
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = icmp eq i8* %2, null
%19 = select i1 %18, i32 0, i32 255
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 1, i32 0
store i32 %19, i32* %20
br label %24
21: ; preds = %12
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 1, i32 1
%23 = bitcast i32** %22 to i8**
store i8* %2, i8** %23
br label %24
24: ; preds = %21, %17
ret void
}