#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 */

/* Type definitions */
typedef int /*<<< orphan*/ RSA;
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef int /*<<< orphan*/ ASN1_ITEM;

/* Variables and functions */
int ASN1_OP_FREE_PRE;
int ASN1_OP_NEW_PRE;
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
scalar_t__ RSA_new();
int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) {
  if (operation == ASN1_OP_NEW_PRE) {
    *pval = (ASN1_VALUE *)RSA_new();
    if (*pval)
      return 2;
    return 0;
  } else if (operation == ASN1_OP_FREE_PRE) {
    RSA_free((RSA *)*pval);
    *pval = NULL;
    return 2;
  }
  return 1;
}


x86 assembly (clang, -O0):
<rsa_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e9f(%rip),%rcx
cmp    (%rcx),%eax
jne    1180 <rsa_cb+0x60>
mov    $0x0,%al
call   1040 <RSA_new@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1174 <rsa_cb+0x54>
movl   $0x2,-0x4(%rbp)
jmp    11c1 <rsa_cb+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <rsa_cb+0xa1>
mov    -0x8(%rbp),%eax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%eax
jne    11b5 <rsa_cb+0x95>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <RSA_free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    11c1 <rsa_cb+0xa1>
jmp    11ba <rsa_cb+0x9a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_cb>:
push   %rbx
mov    %rsi,%rbx
mov    0x2eb5(%rip),%rax
cmp    %edi,(%rax)
jne    1148 <rsa_cb+0x28>
xor    %eax,%eax
call   1040 <RSA_new@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
mov    %rcx,(%rbx)
add    %eax,%eax
pop    %rbx
ret
mov    0x2e99(%rip),%rcx
mov    $0x1,%eax
cmp    %edi,(%rcx)
jne    116c <rsa_cb+0x4c>
mov    (%rbx),%rdi
call   1030 <RSA_free@plt>
movq   $0x0,(%rbx)
mov    $0x2,%eax
pop    %rbx
ret

LLVM IR (-O0):
@ASN1_OP_NEW_PRE = global i32 0
@ASN1_OP_FREE_PRE = global i32 0
define i32 @rsa_cb(i32 %0, i32** %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i32*
%9 = alloca i8*
store i32 %0, i32* %6
store i32** %1, i32*** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%10 = load i32, i32* %6
%11 = load i32, i32* @ASN1_OP_NEW_PRE
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %4
%14 = call i64 (...) @RSA_new()
%15 = inttoptr i64 %14 to i32*
%16 = load i32**, i32*** %7
store i32* %15, i32** %16
%17 = load i32**, i32*** %7
%18 = load i32*, i32** %17
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 2, i32* %5
br label %33
21: ; preds = %13
store i32 0, i32* %5
br label %33
22: ; preds = %4
%23 = load i32, i32* %6
%24 = load i32, i32* @ASN1_OP_FREE_PRE
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32**, i32*** %7
%28 = load i32*, i32** %27
%29 = call i32 @RSA_free(i32* %28)
%30 = load i32**, i32*** %7
store i32* null, i32** %30
store i32 2, i32* %5
br label %33
31: ; preds = %22
br label %32
32: ; preds = %31
store i32 1, i32* %5
br label %33
33: ; preds = %32, %26, %21, %20
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@ASN1_OP_NEW_PRE = global i32 0
@ASN1_OP_FREE_PRE = global i32 0
define i32 @rsa_cb(i32 %0, i32** nocapture %1, i32* nocapture readnone %2, i8* nocapture readnone %3) {
%5 = load i32, i32* @ASN1_OP_NEW_PRE
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i64 (...) @RSA_new()
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %1
%10 = icmp eq i64 %8, 0
%11 = select i1 %10, i32 0, i32 2
br label %18
12: ; preds = %4
%13 = load i32, i32* @ASN1_OP_FREE_PRE
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32*, i32** %1
%17 = tail call i32 @RSA_free(i32* %16)
store i32* null, i32** %1
br label %18
18: ; preds = %12, %7, %15
%19 = phi i32 [ 2, %15 ], [ %11, %7 ], [ 1, %12 ]
ret i32 %19
}