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

/* Variables and functions */
int /*<<< orphan*/ X509_NAME_oneline(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ *X509_STORE_CTX_get_current_cert(int /*<<< orphan*/ *);
int X509_STORE_CTX_get_error(int /*<<< orphan*/ *);
int X509_STORE_CTX_get_error_depth(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_issuer_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_subject_name(int /*<<< orphan*/ *);
char *X509_verify_cert_error_string(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int verify_callback(int ok, X509_STORE_CTX *store) {
  char data[256];
  if (!ok) {
    X509 *cert = X509_STORE_CTX_get_current_cert(store);
    int depth = X509_STORE_CTX_get_error_depth(store);
    int err = X509_STORE_CTX_get_error(store);
    fprintf(stderr, "-Error with certificate at depth: %i\n", depth);
    X509_NAME_oneline(X509_get_issuer_name(cert), data, 256);
    fprintf(stderr, "    issuer    = %s\n", data);
    X509_NAME_oneline(X509_get_subject_name(cert), data, 256);
    fprintf(stderr, "    subject    = %s\n", data);
    fprintf(stderr, "    err %i:%s\n", err, X509_verify_cert_error_string(err));
  }
  return ok;
}


x86 assembly (clang, -O0):
<verify_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    12a4 <verify_callback+0x124>
mov    -0x10(%rbp),%rdi
call   1070 <X509_STORE_CTX_get_current_cert@plt>
mov    %rax,-0x118(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <X509_STORE_CTX_get_error_depth@plt>
mov    %eax,-0x11c(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <X509_STORE_CTX_get_error@plt>
mov    %eax,-0x120(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x11c(%rbp),%edx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x118(%rbp),%rdi
call   1050 <X509_get_issuer_name@plt>
mov    %eax,%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x118(%rbp),%rdi
call   1040 <X509_get_subject_name@plt>
mov    %eax,%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rdx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x128(%rbp)
mov    -0x120(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x120(%rbp),%edi
call   1060 <X509_verify_cert_error_string@plt>
mov    -0x128(%rbp),%edi
mov    -0x124(%rbp),%edx
mov    %rax,%rcx
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_callback>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
test   %edi,%edi
jne    1258 <verify_callback+0xd8>
mov    %rsi,%rbp
mov    %rsi,%rdi
call   1070 <X509_STORE_CTX_get_current_cert@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   10a0 <X509_STORE_CTX_get_error_depth@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1080 <X509_STORE_CTX_get_error@plt>
mov    %eax,%r14d
mov    0x2e1a(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe2f(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1050 <X509_get_issuer_name@plt>
mov    %rsp,%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
mov    0x0(%r13),%edi
lea    0xe26(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1040 <X509_get_subject_name@plt>
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
mov    0x0(%r13),%edi
lea    0xe0e(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x0(%r13),%ebp
mov    %r14d,%edi
call   1060 <X509_verify_cert_error_string@plt>
lea    0xe06(%rip),%rsi
mov    %ebp,%edi
mov    %r14d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"-Error with certificate at depth: %i\0A\00"
@.str.1 = [20 x i8] c" issuer = %s\0A\00"
@.str.2 = [21 x i8] c" subject = %s\0A\00"
@.str.3 = [15 x i8] c" err %i:%s\0A\00"
define i32 @verify_callback(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [256 x 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 = icmp ne i32 %9, 0
br i1 %10, label %40, label %11
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = call i32* @X509_STORE_CTX_get_current_cert(i32* %12)
store i32* %13, i32** %6
%14 = load i32*, i32** %4
%15 = call i32 @X509_STORE_CTX_get_error_depth(i32* %14)
store i32 %15, i32* %7
%16 = load i32*, i32** %4
%17 = call i32 @X509_STORE_CTX_get_error(i32* %16)
store i32 %17, i32* %8
%18 = load i32, i32* @stderr
%19 = load i32, i32* %7
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %6
%22 = call i32 @X509_get_issuer_name(i32* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%24 = call i32 @X509_NAME_oneline(i32 %22, i8* %23, i32 256)
%25 = load i32, i32* @stderr
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32*, i32** %6
%29 = call i32 @X509_get_subject_name(i32* %28)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%31 = call i32 @X509_NAME_oneline(i32 %29, i8* %30, i32 256)
%32 = load i32, i32* @stderr
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @stderr
%36 = load i32, i32* %8
%37 = load i32, i32* %8
%38 = call i8* @X509_verify_cert_error_string(i32 %37)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %36, i8* %38)
br label %40
40: ; preds = %11, %2
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"-Error with certificate at depth: %i\0A\00"
@.str.1 = [20 x i8] c" issuer = %s\0A\00"
@.str.2 = [21 x i8] c" subject = %s\0A\00"
@.str.3 = [15 x i8] c" err %i:%s\0A\00"
define i32 @verify_callback(i32 returned %0, i32* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %23
6: ; preds = %2
%7 = tail call i32* @X509_STORE_CTX_get_current_cert(i32* %1)
%8 = tail call i32 @X509_STORE_CTX_get_error_depth(i32* %1)
%9 = tail call i32 @X509_STORE_CTX_get_error(i32* %1)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %8)
%12 = tail call i32 @X509_get_issuer_name(i32* %7)
%13 = call i32 @X509_NAME_oneline(i32 %12, i8* %4, i32 256)
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%16 = call i32 @X509_get_subject_name(i32* %7)
%17 = call i32 @X509_NAME_oneline(i32 %16, i8* %4, i32 256)
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%20 = load i32, i32* @stderr
%21 = call i8* @X509_verify_cert_error_string(i32 %9)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %9, i8* %21)
br label %23
23: ; preds = %6, %2
ret i32 %0
}