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

/* Variables and functions */
int /*<<< orphan*/ *SSL_get_peer_certificate(int /*<<< orphan*/ *);
char *X509_NAME_oneline(int /*<<< orphan*/, int /*<<< orphan*/ *,
                        int /*<<< orphan*/);
int /*<<< orphan*/ X509_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_issuer_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_subject_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
void show_certificates(SSL *ssl) {
  X509 *cert;
  char *line;
  cert = SSL_get_peer_certificate(ssl);
  if (!cert) {
    printf("No client certificate\n");
    return;
  }
  printf("client certificate:\n");
  line = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
  printf("* Subject: %s\n", line);
  free(line);
  line = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
  printf("* Issuer: %s\n", line);
  free(line);
  X509_free(cert);
}


x86 assembly (clang, -O0):
<show_certificates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <SSL_get_peer_certificate@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a7 <show_certificates+0x37>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1228 <show_certificates+0xb8>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <X509_get_subject_name@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <X509_NAME_oneline@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1070 <X509_get_issuer_name@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <X509_NAME_oneline@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1090 <X509_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_certificates>:
push   %r14
push   %rbx
push   %rax
call   1090 <SSL_get_peer_certificate@plt>
test   %rax,%rax
je     120a <show_certificates+0x8a>
mov    %rax,%r14
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1070 <X509_get_subject_name@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <X509_NAME_oneline@plt>
mov    %rax,%rbx
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1080 <X509_get_issuer_name@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <X509_NAME_oneline@plt>
mov    %rax,%rbx
lea    0xe26(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <X509_free@plt>
lea    0xe0c(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"No client certificate\0A\00"
@.str.1 = [21 x i8] c"client certificate:\0A\00"
@.str.2 = [15 x i8] c"* Subject: %s\0A\00"
@.str.3 = [14 x i8] c"* Issuer: %s\0A\00"
define void @show_certificates(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32* @SSL_get_peer_certificate(i32* %5)
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %29
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32*, i32** %3
%14 = call i32 @X509_get_subject_name(i32* %13)
%15 = call i8* @X509_NAME_oneline(i32 %14, i32* null, i32 0)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
%20 = load i32*, i32** %3
%21 = call i32 @X509_get_issuer_name(i32* %20)
%22 = call i8* @X509_NAME_oneline(i32 %21, i32* null, i32 0)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 @free(i8* %25)
%27 = load i32*, i32** %3
%28 = call i32 @X509_free(i32* %27)
br label %29
29: ; preds = %11, %9
ret void
}

LLVM IR (-O2):
@.str.2 = [15 x i8] c"* Subject: %s\0A\00"
@.str.3 = [14 x i8] c"* Issuer: %s\0A\00"
@str = [22 x i8] c"No client certificate\00"
@str.4 = [20 x i8] c"client certificate:\00"
define void @show_certificates(i32* %0) {
%2 = tail call i32* @SSL_get_peer_certificate(i32* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %17
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%8 = tail call i32 @X509_get_subject_name(i32* %2)
%9 = tail call i8* @X509_NAME_oneline(i32 %8, i32* null, i32 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = tail call i32 @free(i8* %9)
%12 = tail call i32 @X509_get_issuer_name(i32* %2)
%13 = tail call i8* @X509_NAME_oneline(i32 %12, i32* null, i32 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = tail call i32 @free(i8* %13)
%16 = tail call i32 @X509_free(i32* %2)
br label %17
17: ; preds = %6, %4
ret void
}