#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 /*<<< orphan*/ *ptr;
};
struct TYPE_5__ {
  int type;
  TYPE_1__ value;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_2__ ASN1_TYPE;

/* Variables and functions */
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;
  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,0x8(%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    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%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,0x8(%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    %rbx,0x8(%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* }
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 0
%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 i8*, i8** %6
%22 = bitcast i8* %21 to i32*
%23 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %23, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 0
store i32* %22, i32** %25
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32* }
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 0
%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 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 1, i32 0
%16 = bitcast i32** %15 to i8**
store i8* %2, i8** %16
ret void
}