#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;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
scalar_t__ BIO_get_mem_data(int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ X509_NAME_print_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ *X509_get_subject_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ XN_FLAG_ONELINE;
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
void printSubjOneline(X509 *cert, FILE *fp) {
  char *ptr;
  int n;
  X509_NAME *subj = X509_get_subject_name(cert);
  BIO *bmem = BIO_new(BIO_s_mem());
  X509_NAME_print_ex(bmem, subj, 0, XN_FLAG_ONELINE);
  n = (int)BIO_get_mem_data(bmem, &ptr);
  if (n <= 0)
    ptr = "?", n = 1;
  fwrite(ptr, 1, n, fp);
  if (bmem) {
    BIO_free_all(bmem);
  }
  if (subj) {
    free(subj);
  }
}


x86 assembly (clang, -O0):
<printSubjOneline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <X509_get_subject_name@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1090 <BIO_s_mem@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2e2a(%rip),%rax
mov    (%rax),%ecx
xor    %edx,%edx
call   1060 <X509_NAME_print_ex@plt>
mov    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <BIO_get_mem_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11f3 <printSubjOneline+0x73>
lea    0xe18(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
cmpq   $0x0,-0x30(%rbp)
je     121c <printSubjOneline+0x9c>
mov    -0x30(%rbp),%rdi
call   1070 <BIO_free_all@plt>
cmpq   $0x0,-0x28(%rbp)
je     1230 <printSubjOneline+0xb0>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printSubjOneline>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
call   1040 <X509_get_subject_name@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1090 <BIO_s_mem@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1060 <X509_NAME_print_ex@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <BIO_get_mem_data@plt>
test   %eax,%eax
jle    11d3 <printSubjOneline+0x53>
mov    0x8(%rsp),%rdi
jmp    11e4 <printSubjOneline+0x64>
lea    0xe26(%rip),%rdi
mov    %rdi,0x8(%rsp)
mov    $0x1,%eax
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
test   %rbx,%rbx
je     1200 <printSubjOneline+0x80>
mov    %rbx,%rdi
call   1070 <BIO_free_all@plt>
test   %r15,%r15
je     120d <printSubjOneline+0x8d>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@XN_FLAG_ONELINE = global i32 0
@.str = [2 x i8] c"?\00"
define void @printSubjOneline(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = load i32*, i32** %3
%10 = call i32* @X509_get_subject_name(i32* %9)
store i32* %10, i32** %7
%11 = call i32 (...) @BIO_s_mem()
%12 = call i32* @BIO_new(i32 %11)
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = load i32*, i32** %7
%15 = load i32, i32* @XN_FLAG_ONELINE
%16 = call i32 @X509_NAME_print_ex(i32* %13, i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %8
%18 = call i64 @BIO_get_mem_data(i32* %17, i8** %5)
%19 = trunc i64 %18 to i32
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 1, i32* %6
br label %23
23: ; preds = %22, %2
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = load i32*, i32** %4
%27 = call i32 @fwrite(i8* %24, i32 1, i32 %25, i32* %26)
%28 = load i32*, i32** %8
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i32*, i32** %8
%32 = call i32 @BIO_free_all(i32* %31)
br label %33
33: ; preds = %30, %23
%34 = load i32*, i32** %7
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32*, i32** %7
%38 = call i32 @free(i32* %37)
br label %39
39: ; preds = %36, %33
ret void
}

LLVM IR (-O2):
@XN_FLAG_ONELINE = global i32 0
@.str = [2 x i8] c"?\00"
define void @printSubjOneline(i32* %0, i32* nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32* @X509_get_subject_name(i32* %0)
%6 = tail call i32 (...) @BIO_s_mem()
%7 = tail call i32* @BIO_new(i32 %6)
%8 = load i32, i32* @XN_FLAG_ONELINE
%9 = tail call i32 @X509_NAME_print_ex(i32* %7, i32* %5, i32 0, i32 %8)
%10 = call i64 @BIO_get_mem_data(i32* %7, i8** %3)
%11 = trunc i64 %10 to i32
%12 = icmp slt i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = load i8*, i8** %3
br label %16
15: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %16
16: ; preds = %13, %15
%17 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %15 ], [ %14, %13 ]
%18 = phi i32 [ 1, %15 ], [ %11, %13 ]
%19 = call i32 @fwrite(i8* %17, i32 1, i32 %18, i32* %1)
%20 = icmp eq i32* %7, null
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 @BIO_free_all(i32* %7)
br label %23
23: ; preds = %21, %16
%24 = icmp eq i32* %5, null
br i1 %24, label %27, label %25
25: ; preds = %23
%26 = call i32 @free(i32* %5)
br label %27
27: ; preds = %25, %23
ret void
}