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

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ *parameter;
  int /*<<< orphan*/ *algorithm;
};
typedef TYPE_1__ X509_ALGOR;
typedef int /*<<< orphan*/ ASN1_OBJECT;

/* Variables and functions */
int /*<<< orphan*/ ASN1_OBJECT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1_TYPE_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASN1_TYPE_new();
int /*<<< orphan*/ ASN1_TYPE_set(int /*<<< orphan*/ *, int, void *);
int V_ASN1_UNDEF;
int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) {
  if (!alg)
    return 0;
  if (ptype != V_ASN1_UNDEF) {
    if (alg->parameter == NULL)
      alg->parameter = ASN1_TYPE_new();
    if (alg->parameter == NULL)
      return 0;
  }
  if (alg) {
    if (alg->algorithm)
      ASN1_OBJECT_free(alg->algorithm);
    alg->algorithm = aobj;
  }
  if (ptype == 0)
    return 1;
  if (ptype == V_ASN1_UNDEF) {
    if (alg->parameter) {
      ASN1_TYPE_free(alg->parameter);
      alg->parameter = NULL;
    }
  } else
    ASN1_TYPE_set(alg->parameter, ptype, pval);
  return 1;
}


x86 assembly (clang, -O0):
<X509_ALGOR_set0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <X509_ALGOR_set0+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    125d <X509_ALGOR_set0+0x11d>
mov    -0x1c(%rbp),%eax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%eax
je     11be <X509_ALGOR_set0+0x7e>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    119f <X509_ALGOR_set0+0x5f>
mov    $0x0,%al
call   1030 <ASN1_TYPE_new@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b9 <X509_ALGOR_set0+0x79>
movl   $0x0,-0x4(%rbp)
jmp    125d <X509_ALGOR_set0+0x11d>
jmp    11be <X509_ALGOR_set0+0x7e>
cmpq   $0x0,-0x10(%rbp)
je     11f1 <X509_ALGOR_set0+0xb1>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11e5 <X509_ALGOR_set0+0xa5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <ASN1_OBJECT_free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
cmpl   $0x0,-0x1c(%rbp)
jne    1207 <X509_ALGOR_set0+0xc7>
movl   $0x1,-0x4(%rbp)
jmp    125d <X509_ALGOR_set0+0x11d>
mov    -0x1c(%rbp),%eax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%eax
jne    1243 <X509_ALGOR_set0+0x103>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     123e <X509_ALGOR_set0+0xfe>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <ASN1_TYPE_free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    1256 <X509_ALGOR_set0+0x116>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1060 <ASN1_TYPE_set@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_ALGOR_set0>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b8 <X509_ALGOR_set0+0x78>
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e86(%rip),%r13
cmp    %edx,0x0(%r13)
je     1180 <X509_ALGOR_set0+0x40>
cmpq   $0x0,(%rbx)
jne    1180 <X509_ALGOR_set0+0x40>
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <ASN1_TYPE_new@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11c7 <X509_ALGOR_set0+0x87>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     118e <X509_ALGOR_set0+0x4e>
call   1050 <ASN1_OBJECT_free@plt>
mov    %r12,0x8(%rbx)
mov    $0x1,%r15d
test   %ebp,%ebp
je     11c7 <X509_ALGOR_set0+0x87>
mov    (%rbx),%rdi
cmp    %ebp,0x0(%r13)
jne    11bd <X509_ALGOR_set0+0x7d>
test   %rdi,%rdi
je     11c7 <X509_ALGOR_set0+0x87>
call   1040 <ASN1_TYPE_free@plt>
movq   $0x0,(%rbx)
jmp    11c7 <X509_ALGOR_set0+0x87>
xor    %r15d,%r15d
jmp    11c7 <X509_ALGOR_set0+0x87>
mov    %ebp,%esi
mov    %r14,%rdx
call   1060 <ASN1_TYPE_set@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32*, i32* }
@V_ASN1_UNDEF = global i32 0
define i32 @X509_ALGOR_set0(%struct.TYPE_3__* %0, i32* %1, i32 %2, i8* %3) {
%5 = icmp eq %struct.TYPE_3__* %0, null
br i1 %5, label %35, label %6
6: ; preds = %4
%7 = load i32, i32* @V_ASN1_UNDEF
%8 = icmp eq i32 %7, %2
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32* (...) @ASN1_TYPE_new()
store i32* %14, i32** %10
%15 = icmp eq i32* %14, null
br i1 %15, label %35, label %16
16: ; preds = %9, %6, %13
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%18 = load i32*, i32** %17
%19 = icmp eq i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @ASN1_OBJECT_free(i32* %18)
br label %22
22: ; preds = %20, %16
store i32* %1, i32** %17
%23 = icmp eq i32 %2, 0
br i1 %23, label %35, label %24
24: ; preds = %22
%25 = load i32, i32* @V_ASN1_UNDEF
%26 = icmp eq i32 %25, %2
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%28 = load i32*, i32** %27
br i1 %26, label %29, label %33
29: ; preds = %24
%30 = icmp eq i32* %28, null
br i1 %30, label %35, label %31
31: ; preds = %29
%32 = tail call i32 @ASN1_TYPE_free(i32* %28)
store i32* null, i32** %27
br label %35
33: ; preds = %24
%34 = tail call i32 @ASN1_TYPE_set(i32* %28, i32 %2, i8* %3)
br label %35
35: ; preds = %33, %31, %29, %22, %13, %4
%36 = phi i32 [ 0, %4 ], [ 0, %13 ], [ 1, %22 ], [ 1, %29 ], [ 1, %31 ], [ 1, %33 ]
ret i32 %36
}