#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_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  TYPE_1__ *bmpstring;
};
struct TYPE_7__ {
  scalar_t__ type;
  TYPE_2__ value;
};
struct TYPE_5__ {
  int /*<<< orphan*/ length;
  int /*<<< orphan*/ data;
};
typedef int /*<<< orphan*/ PKCS12_SAFEBAG;
typedef TYPE_3__ ASN1_TYPE;

/* Variables and functions */
int /*<<< orphan*/ NID_friendlyName;
TYPE_3__ *PKCS12_get_attr(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ V_ASN1_BMPSTRING;
char *uni2asc(int /*<<< orphan*/, int /*<<< orphan*/);
char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag) {
  ASN1_TYPE *atype;
  if (!(atype = PKCS12_get_attr(bag, NID_friendlyName)))
    return NULL;
  if (atype->type != V_ASN1_BMPSTRING)
    return NULL;
  return uni2asc(atype->value.bmpstring->data, atype->value.bmpstring->length);
}


x86 assembly (clang, -O0):
<PKCS12_get_friendlyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
call   1040 <PKCS12_get_attr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1159 <PKCS12_get_friendlyname+0x39>
movq   $0x0,-0x8(%rbp)
jmp    119b <PKCS12_get_friendlyname+0x7b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
je     117d <PKCS12_get_friendlyname+0x5d>
movq   $0x0,-0x8(%rbp)
jmp    119b <PKCS12_get_friendlyname+0x7b>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
call   1030 <uni2asc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS12_get_friendlyname>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%esi
call   1040 <PKCS12_get_attr@plt>
test   %rax,%rax
je     1152 <PKCS12_get_friendlyname+0x32>
mov    (%rax),%rcx
mov    0x2e9a(%rip),%rdx
cmp    (%rdx),%rcx
jne    1152 <PKCS12_get_friendlyname+0x32>
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    0x4(%rax),%edi
pop    %rax
jmp    1030 <uni2asc@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { i64, %struct.TYPE_6__ }
%struct.TYPE_6__ = type { %struct.TYPE_5__* }
%struct.TYPE_5__ = type { i32, i32 }
@NID_friendlyName = global i32 0
@V_ASN1_BMPSTRING = global i64 0
define i8* @PKCS12_get_friendlyname(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.TYPE_7__*
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = load i32, i32* @NID_friendlyName
%7 = call %struct.TYPE_7__* @PKCS12_get_attr(i32* %5, i32 %6)
store %struct.TYPE_7__* %7, %struct.TYPE_7__** %4
%8 = icmp ne %struct.TYPE_7__* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i8* null, i8** %2
br label %31
10: ; preds = %1
%11 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
%12 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* @V_ASN1_BMPSTRING
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %10
store i8* null, i8** %2
br label %31
17: ; preds = %10
%18 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
%19 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %18, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %19, i32 0, i32 0
%21 = load %struct.TYPE_5__*, %struct.TYPE_5__** %20
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
%25 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %24, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %25, i32 0, i32 0
%27 = load %struct.TYPE_5__*, %struct.TYPE_5__** %26
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i8* @uni2asc(i32 %23, i32 %29)
store i8* %30, i8** %2
br label %31
31: ; preds = %17, %16, %9
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { i64, %struct.TYPE_6__ }
%struct.TYPE_6__ = type { %struct.TYPE_5__* }
%struct.TYPE_5__ = type { i32, i32 }
@NID_friendlyName = global i32 0
@V_ASN1_BMPSTRING = global i64 0
define i8* @PKCS12_get_friendlyname(i32* %0) {
%2 = load i32, i32* @NID_friendlyName
%3 = tail call %struct.TYPE_7__* @PKCS12_get_attr(i32* %0, i32 %2)
%4 = icmp eq %struct.TYPE_7__* %3, null
br i1 %4, label %18, label %5
5: ; preds = %1
%6 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 0
%7 = load i64, i64* %6
%8 = load i64, i64* @V_ASN1_BMPSTRING
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 1, i32 0
%12 = load %struct.TYPE_5__*, %struct.TYPE_5__** %11
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i8* @uni2asc(i32 %14, i32 %16)
br label %18
18: ; preds = %5, %1, %10
%19 = phi i8* [ %17, %10 ], [ null, %1 ], [ null, %5 ]
ret i8* %19
}