#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*/ const BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_copy(int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ const *);
int /*<<< orphan*/ const *BN_new();
int /*<<< orphan*/ bn_check_top(int /*<<< orphan*/ const *);
BIGNUM *BN_dup(const BIGNUM *a) {
  BIGNUM *t;
  if (a == NULL)
    return NULL;
  bn_check_top(a);
  t = BN_new();
  if (t == NULL)
    return NULL;
  if (!BN_copy(t, a)) {
    BN_free(t);
    return NULL;
  }
  bn_check_top(t);
  return t;
}


x86 assembly (clang, -O0):
<BN_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <BN_dup+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11cd <BN_dup+0x8d>
mov    -0x10(%rbp),%rdi
call   1040 <bn_check_top@plt>
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <BN_dup+0x50>
movq   $0x0,-0x8(%rbp)
jmp    11cd <BN_dup+0x8d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <BN_copy@plt>
cmp    $0x0,%eax
jne    11bc <BN_dup+0x7c>
mov    -0x18(%rbp),%rdi
call   1050 <BN_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cd <BN_dup+0x8d>
mov    -0x18(%rbp),%rdi
call   1040 <bn_check_top@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_dup>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1181 <BN_dup+0x41>
mov    %rdi,%rbx
call   1040 <bn_check_top@plt>
xor    %eax,%eax
call   1030 <BN_new@plt>
test   %rax,%rax
je     1181 <BN_dup+0x41>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <BN_copy@plt>
test   %eax,%eax
je     1179 <BN_dup+0x39>
mov    %r14,%rdi
call   1040 <bn_check_top@plt>
jmp    1184 <BN_dup+0x44>
mov    %r14,%rdi
call   1050 <BN_free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @BN_dup(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32* null, i32** %2
br label %27
8: ; preds = %1
%9 = load i32*, i32** %3
%10 = call i32 @bn_check_top(i32* %9)
%11 = call i32* (...) @BN_new()
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %8
store i32* null, i32** %2
br label %27
15: ; preds = %8
%16 = load i32*, i32** %4
%17 = load i32*, i32** %3
%18 = call i32 @BN_copy(i32* %16, i32* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = call i32 @BN_free(i32* %21)
store i32* null, i32** %2
br label %27
23: ; preds = %15
%24 = load i32*, i32** %4
%25 = call i32 @bn_check_top(i32* %24)
%26 = load i32*, i32** %4
store i32* %26, i32** %2
br label %27
27: ; preds = %23, %20, %14, %7
%28 = load i32*, i32** %2
ret i32* %28
}

LLVM IR (-O2):
define i32* @BN_dup(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32 @bn_check_top(i32* %0)
%5 = tail call i32* (...) @BN_new()
%6 = icmp eq i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = tail call i32 @BN_copy(i32* %5, i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @BN_free(i32* %5)
br label %14
12: ; preds = %7
%13 = tail call i32 @bn_check_top(i32* %5)
br label %14
14: ; preds = %3, %1, %12, %10
%15 = phi i32* [ %5, %12 ], [ null, %10 ], [ null, %1 ], [ null, %3 ]
ret i32* %15
}