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

/* Variables and functions */
int /*<<< orphan*/ ERR_clear_error();
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*/ *);
#define X509_V_ERR_CERT_HAS_EXPIRED 137
#define X509_V_ERR_CRL_HAS_EXPIRED 136
#define X509_V_ERR_CRL_NOT_YET_VALID 135
#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 134
#define X509_V_ERR_INVALID_CA 133
#define X509_V_ERR_INVALID_NON_CA 132
#define X509_V_ERR_INVALID_PURPOSE 131
#define X509_V_ERR_NO_EXPLICIT_POLICY 130
#define X509_V_ERR_PATH_LENGTH_EXCEEDED 129
#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 128
int X509_V_OK;
int /*<<< orphan*/ X509_get_subject_name(int /*<<< orphan*/ *);
char *X509_verify_cert_error_string(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ policies_print(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int verify_callback(int ok, X509_STORE_CTX *ctx) {
  static int v_verbose = 0;
  int cert_error = X509_STORE_CTX_get_error(ctx);
  if (!ok) {
    X509 *current_cert = X509_STORE_CTX_get_current_cert(ctx);
    if (current_cert) {
      char buf[256];
      X509_NAME_oneline(X509_get_subject_name(current_cert), buf, sizeof(buf));
      fprintf(stderr, "%s\n", buf);
    }
    {
      int error_depth = X509_STORE_CTX_get_error_depth(ctx);
      const char *error_msg = X509_verify_cert_error_string(cert_error);
      fprintf(stderr, "%sError %d at %d depth lookup: %s\n", "", cert_error,
              error_depth, error_msg);
    }
    switch (cert_error) {
    case X509_V_ERR_NO_EXPLICIT_POLICY:
      policies_print(NULL, ctx);
    case X509_V_ERR_CERT_HAS_EXPIRED:
    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
    case X509_V_ERR_INVALID_CA:
    case X509_V_ERR_INVALID_NON_CA:
    case X509_V_ERR_PATH_LENGTH_EXCEEDED:
    case X509_V_ERR_INVALID_PURPOSE:
    case X509_V_ERR_CRL_HAS_EXPIRED:
    case X509_V_ERR_CRL_NOT_YET_VALID:
    case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
      ok = 1;
    }
    return ok;
  }
  if (cert_error == X509_V_OK && ok == 2)
    policies_print(NULL, ctx);
  if (!v_verbose)
    ERR_clear_error();
  return ok;
}


x86 assembly (clang, -O0):
<verify_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <X509_STORE_CTX_get_error@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    12bf <verify_callback+0x12f>
mov    -0x10(%rbp),%rdi
call   1060 <X509_STORE_CTX_get_current_cert@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120a <verify_callback+0x7a>
mov    -0x20(%rbp),%rdi
call   1040 <X509_get_subject_name@plt>
mov    %eax,%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <X509_STORE_CTX_get_error_depth@plt>
mov    %eax,-0x124(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <X509_verify_cert_error_string@plt>
mov    %rax,-0x130(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%ecx
mov    -0x124(%rbp),%r8d
mov    -0x130(%rbp),%r9
lea    0xdb7(%rip),%rsi
lea    0xdd2(%rip),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x134(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     12ad <verify_callback+0x11d>
jmp    1271 <verify_callback+0xe1>
mov    -0x134(%rbp),%eax
sub    $0x82,%eax
je     12a0 <verify_callback+0x110>
jmp    1287 <verify_callback+0xf7>
mov    -0x134(%rbp),%eax
add    $0xffffff7d,%eax
sub    $0x7,%eax
jb     12ad <verify_callback+0x11d>
jmp    12b4 <verify_callback+0x124>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <policies_print@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1302 <verify_callback+0x172>
mov    -0x14(%rbp),%eax
mov    0x2d2f(%rip),%rcx
cmp    (%rcx),%eax
jne    12e8 <verify_callback+0x158>
cmpl   $0x2,-0x8(%rbp)
jne    12e8 <verify_callback+0x158>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <policies_print@plt>
cmpl   $0x0,0x2d7d(%rip)
jne    12fc <verify_callback+0x16c>
mov    $0x0,%al
call   1090 <ERR_clear_error@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_callback>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsi,%rdi
call   1070 <X509_STORE_CTX_get_error@plt>
mov    %eax,%ebp
test   %ebx,%ebx
je     11d6 <verify_callback+0x46>
cmp    $0x2,%ebx
jne    11ca <verify_callback+0x3a>
mov    0x2e3c(%rip),%rax
cmp    (%rax),%ebp
jne    11ca <verify_callback+0x3a>
xor    %edi,%edi
mov    %r14,%rsi
call   10a0 <policies_print@plt>
xor    %eax,%eax
call   1090 <ERR_clear_error@plt>
jmp    1263 <verify_callback+0xd3>
mov    %r14,%rdi
call   1060 <X509_STORE_CTX_get_current_cert@plt>
test   %rax,%rax
je     1217 <verify_callback+0x87>
mov    %rax,%rdi
call   1040 <X509_get_subject_name@plt>
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   10b0 <X509_STORE_CTX_get_error_depth@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1050 <X509_verify_cert_error_string@plt>
mov    0x2da8(%rip),%rcx
mov    (%rcx),%edi
lea    0xdc7(%rip),%rsi
lea    0xde2(%rip),%rdx
xor    %ebx,%ebx
mov    %ebp,%ecx
mov    %r15d,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0xffffff80,%ebp
cmp    $0x9,%ebp
ja     1263 <verify_callback+0xd3>
cmp    $0x2,%ebp
je     1273 <verify_callback+0xe3>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
mov    %r14,%rsi
call   10a0 <policies_print@plt>
jmp    125e <verify_callback+0xce>

LLVM IR (-O0):
@verify_callback.v_verbose = internal global i32 0
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [35 x i8] c"%sError %d at %d depth lookup: %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@X509_V_OK = global i32 0
define i32 @verify_callback(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %4
store i32* %1, i32** %5
%11 = load i32*, i32** %5
%12 = call i32 @X509_STORE_CTX_get_error(i32* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %45, label %15
15: ; preds = %2
%16 = load i32*, i32** %5
%17 = call i32* @X509_STORE_CTX_get_current_cert(i32* %16)
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load i32*, i32** %7
%22 = call i32 @X509_get_subject_name(i32* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, 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]* %8, i64 0, i64 0
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %20, %15
%29 = load i32*, i32** %5
%30 = call i32 @X509_STORE_CTX_get_error_depth(i32* %29)
store i32 %30, i32* %9
%31 = load i32, i32* %6
%32 = call i8* @X509_verify_cert_error_string(i32 %31)
store i8* %32, i8** %10
%33 = load i32, i32* @stderr
%34 = load i32, i32* %6
%35 = load i32, i32* %9
%36 = load i8*, i8** %10
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %35, i8* %36)
%38 = load i32, i32* %6
switch i32 %38, label %43 [
i32 130, label %39
i32 137, label %42
i32 134, label %42
i32 133, label %42
i32 132, label %42
i32 129, label %42
i32 131, label %42
i32 136, label %42
i32 135, label %42
i32 128, label %42
]
39: ; preds = %28
%40 = load i32*, i32** %5
%41 = call i32 @policies_print(i32* null, i32* %40)
br label %42
42: ; preds = %28, %28, %28, %28, %28, %28, %28, %28, %28, %39
store i32 1, i32* %4
br label %43
43: ; preds = %42, %28
%44 = load i32, i32* %4
store i32 %44, i32* %3
br label %62
45: ; preds = %2
%46 = load i32, i32* %6
%47 = load i32, i32* @X509_V_OK
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %55
49: ; preds = %45
%50 = load i32, i32* %4
%51 = icmp eq i32 %50, 2
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32*, i32** %5
%54 = call i32 @policies_print(i32* null, i32* %53)
br label %55
55: ; preds = %52, %49, %45
%56 = load i32, i32* @verify_callback.v_verbose
%57 = icmp ne i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i32 (...) @ERR_clear_error()
br label %60
60: ; preds = %58, %55
%61 = load i32, i32* %4
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %43
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [35 x i8] c"%sError %d at %d depth lookup: %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@X509_V_OK = global i32 0
define i32 @verify_callback(i32 %0, i32* %1) {
%3 = alloca [256 x i8]
%4 = tail call i32 @X509_STORE_CTX_get_error(i32* %1)
%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 = icmp eq i32* %7, null
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = tail call i32 @X509_get_subject_name(i32* %7)
%12 = call i32 @X509_NAME_oneline(i32 %11, i8* %10, i32 256)
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %15
15: ; preds = %9, %6
%16 = call i32 @X509_STORE_CTX_get_error_depth(i32* %1)
%17 = call i8* @X509_verify_cert_error_string(i32 %4)
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %16, i8* %17)
switch i32 %4, label %32 [
i32 130, label %20
i32 137, label %22
i32 134, label %22
i32 133, label %22
i32 132, label %22
i32 129, label %22
i32 131, label %22
i32 136, label %22
i32 135, label %22
i32 128, label %22
]
20: ; preds = %15
%21 = call i32 @policies_print(i32* null, i32* %1)
br label %22
22: ; preds = %15, %15, %15, %15, %15, %15, %15, %15, %15, %20
br label %32
23: ; preds = %2
%24 = load i32, i32* @X509_V_OK
%25 = icmp eq i32 %4, %24
%26 = icmp eq i32 %0, 2
%27 = and i1 %26, %25
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = tail call i32 @policies_print(i32* null, i32* %1)
br label %30
30: ; preds = %23, %28
%31 = tail call i32 (...) @ERR_clear_error()
br label %32
32: ; preds = %15, %22, %30
%33 = phi i32 [ %0, %30 ], [ 0, %15 ], [ 1, %22 ]
ret i32 %33
}