#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 showCerts(SSL *ssl) {
  char *line;
  X509 *cert = SSL_get_peer_certificate(ssl);
  if (cert != NULL) {
    printf("Server certificates:\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);
  } else {
    printf("No certificates were found\n");
  }
}


x86 assembly (clang, -O0):
<showCerts>:
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,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     121a <showCerts+0xaa>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%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,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%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,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1090 <X509_free@plt>
jmp    1228 <showCerts+0xb8>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showCerts>:
push   %r14
push   %rbx
push   %rax
call   1090 <SSL_get_peer_certificate@plt>
test   %rax,%rax
je     120a <showCerts+0x8a>
mov    %rax,%r14
lea    0xe9c(%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    0xe24(%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    0xe08(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>

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

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