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

/* Variables and functions */
int /*<<< orphan*/ ASN1_STRING_copy(int /*<<< orphan*/ *,
                                    int /*<<< orphan*/ const *);
int /*<<< orphan*/ ASN1_STRING_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASN1_STRING_new();
ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) {
  ASN1_STRING *ret;
  if (!str)
    return NULL;
  ret = ASN1_STRING_new();
  if (ret == NULL)
    return NULL;
  if (!ASN1_STRING_copy(ret, str)) {
    ASN1_STRING_free(ret);
    return NULL;
  }
  return ret;
}


x86 assembly (clang, -O0):
<ASN1_STRING_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <ASN1_STRING_dup+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11ab <ASN1_STRING_dup+0x7b>
mov    $0x0,%al
call   1050 <ASN1_STRING_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <ASN1_STRING_dup+0x47>
movq   $0x0,-0x8(%rbp)
jmp    11ab <ASN1_STRING_dup+0x7b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <ASN1_STRING_copy@plt>
cmp    $0x0,%eax
jne    11a3 <ASN1_STRING_dup+0x73>
mov    -0x18(%rbp),%rdi
call   1030 <ASN1_STRING_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ab <ASN1_STRING_dup+0x7b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_STRING_dup>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1162 <ASN1_STRING_dup+0x32>
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <ASN1_STRING_new@plt>
test   %rax,%rax
je     1162 <ASN1_STRING_dup+0x32>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <ASN1_STRING_copy@plt>
test   %eax,%eax
jne    1164 <ASN1_STRING_dup+0x34>
mov    %rbx,%rdi
call   1030 <ASN1_STRING_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32* @ASN1_STRING_dup(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i32* (...) @ASN1_STRING_new()
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @ASN1_STRING_copy(i32* %4, i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @ASN1_STRING_free(i32* %4)
br label %11
11: ; preds = %6, %3, %1, %9
%12 = phi i32* [ null, %9 ], [ null, %1 ], [ null, %3 ], [ %4, %6 ]
ret i32* %12
}