#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*/ X509_NAME;
typedef int /*<<< orphan*/ X509;

/* Variables and functions */
int /*<<< orphan*/ NID_organizationalUnitName;
int X509_NAME_get_text_by_NID(int /*<<< orphan*/ *, int /*<<< orphan*/, char *,
                              int);
int /*<<< orphan*/ *X509_get_subject_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ logmsg(int, char *);
char *conn_getOUname(X509 *peercert) {
  static char cnbuf[256];
  X509_NAME *xname;
  int r;
  xname = X509_get_subject_name(peercert);
  if (!xname) {
    logmsg(2, "X509_get_subject_name() failed");
    return NULL;
  }
  r = X509_NAME_get_text_by_NID(xname, NID_organizationalUnitName, cnbuf, 256);
  cnbuf[255] = 0;
  if (r < 1) {
    logmsg(2, "X509_NAME_get_text_by_NID() failed");
    return NULL;
  }
  return &cnbuf[0];
}


x86 assembly (clang, -O0):
<conn_getOUname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <X509_get_subject_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1172 <conn_getOUname+0x42>
mov    $0x2,%edi
lea    0xea0(%rip),%rsi
call   1050 <logmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cd <conn_getOUname+0x9d>
mov    -0x18(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0x2eca(%rip),%rdx
mov    $0x100,%ecx
call   1030 <X509_NAME_get_text_by_NID@plt>
mov    %eax,-0x1c(%rbp)
movb   $0x0,0x2fb5(%rip)
cmpl   $0x1,-0x1c(%rbp)
jge    11c2 <conn_getOUname+0x92>
mov    $0x2,%edi
lea    0xe6f(%rip),%rsi
call   1050 <logmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cd <conn_getOUname+0x9d>
lea    0x2e87(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conn_getOUname>:
push   %rbx
call   1040 <X509_get_subject_name@plt>
test   %rax,%rax
je     116f <conn_getOUname+0x3f>
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%esi
lea    0x2f05(%rip),%rbx
mov    %rax,%rdi
mov    %rbx,%rdx
mov    $0x100,%ecx
call   1030 <X509_NAME_get_text_by_NID@plt>
movb   $0x0,0x2fed(%rip)
test   %eax,%eax
jg     1182 <conn_getOUname+0x52>
lea    0xeb2(%rip),%rsi
jmp    1176 <conn_getOUname+0x46>
lea    0xe8a(%rip),%rsi
mov    $0x2,%edi
call   1050 <logmsg@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@conn_getOUname.cnbuf = internal global [256 x i8] zeroinitializer
@.str = [31 x i8] c"X509_get_subject_name() failed\00"
@NID_organizationalUnitName = global i32 0
@.str.1 = [35 x i8] c"X509_NAME_get_text_by_NID() failed\00"
define i8* @conn_getOUname(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32* @X509_get_subject_name(i32* %6)
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @logmsg(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %21
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = load i32, i32* @NID_organizationalUnitName
%15 = call i32 @X509_NAME_get_text_by_NID(i32* %13, i32 %14, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conn_getOUname.cnbuf, i64 0, i64 0), i32 256)
store i32 %15, i32* %5
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conn_getOUname.cnbuf, i64 0, i64 255)
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @logmsg(i32 2, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %21
20: ; preds = %12
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conn_getOUname.cnbuf, i64 0, i64 0), i8** %2
br label %21
21: ; preds = %20, %18, %10
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@conn_getOUname.cnbuf = internal global [256 x i8] zeroinitializer
@.str = [31 x i8] c"X509_get_subject_name() failed\00"
@NID_organizationalUnitName = global i32 0
@.str.1 = [35 x i8] c"X509_NAME_get_text_by_NID() failed\00"
define i8* @conn_getOUname(i32* %0) {
%2 = tail call i32* @X509_get_subject_name(i32* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i32, i32* @NID_organizationalUnitName
%6 = tail call i32 @X509_NAME_get_text_by_NID(i32* %2, i32 %5, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conn_getOUname.cnbuf, i64 0, i64 0), i32 256)
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conn_getOUname.cnbuf, i64 0, i64 255)
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %4, %1
%9 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), %4 ]
%10 = tail call i32 @logmsg(i32 2, i8* %9)
br label %11
11: ; preds = %8, %4
%12 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @conn_getOUname.cnbuf, i64 0, i64 0), %4 ], [ null, %8 ]
ret i8* %12
}