#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;

/* Variables and functions */
char *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 130
#define X509_V_ERR_CERT_NOT_YET_VALID 129
#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 128
int /*<<< orphan*/ X509_get_subject_name(int /*<<< orphan*/);
char *X509_verify_cert_error_string(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ stderr;
int verify_callback(int ok, X509_STORE_CTX *ctx) {
  char *s, buf[256];
  s = X509_NAME_oneline(
      X509_get_subject_name(X509_STORE_CTX_get_current_cert(ctx)), buf,
      sizeof(buf));
  if (s != NULL) {
    if (ok)
      printf("depth=%d %s\n", X509_STORE_CTX_get_error_depth(ctx), buf);
    else {
      fprintf(stderr, "depth=%d error=%d %s\n",
              X509_STORE_CTX_get_error_depth(ctx),
              X509_STORE_CTX_get_error(ctx), buf);
    }
  }
  if (ok == 0) {
    int i = X509_STORE_CTX_get_error(ctx);
    switch (i) {
    default:
      fprintf(stderr, "Error string: %s\n", X509_verify_cert_error_string(i));
      break;
    case X509_V_ERR_CERT_NOT_YET_VALID:
    case X509_V_ERR_CERT_HAS_EXPIRED:
    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
      ok = 1;
      break;
    }
  }
  return ok;
}


x86 assembly (clang, -O0):
<verify_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <X509_STORE_CTX_get_current_cert@plt>
mov    %eax,%edi
call   1050 <X509_get_subject_name@plt>
mov    %eax,%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1240 <verify_callback+0xc0>
cmpl   $0x0,-0x4(%rbp)
je     11f1 <verify_callback+0x71>
mov    -0x10(%rbp),%rdi
call   10a0 <X509_STORE_CTX_get_error_depth@plt>
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
jmp    123b <verify_callback+0xbb>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <X509_STORE_CTX_get_error_depth@plt>
mov    %eax,-0x128(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <X509_STORE_CTX_get_error@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%edx
mov    %eax,%ecx
lea    -0x120(%rbp),%r8
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1240 <verify_callback+0xc0>
cmpl   $0x0,-0x4(%rbp)
jne    12b2 <verify_callback+0x132>
mov    -0x10(%rbp),%rdi
call   1080 <X509_STORE_CTX_get_error@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
jb     12a6 <verify_callback+0x126>
jmp    1270 <verify_callback+0xf0>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
mov    -0x124(%rbp),%edi
call   1060 <X509_verify_cert_error_string@plt>
mov    -0x130(%rbp),%edi
mov    %rax,%rdx
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12ad <verify_callback+0x12d>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <verify_callback+0x132>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_callback>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1070 <X509_STORE_CTX_get_current_cert@plt>
mov    %eax,%edi
call   1050 <X509_get_subject_name@plt>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1030 <X509_NAME_oneline@plt>
test   %rax,%rax
je     11d2 <verify_callback+0x52>
test   %ebp,%ebp
je     11d8 <verify_callback+0x58>
mov    %rbx,%rdi
call   10a0 <X509_STORE_CTX_get_error_depth@plt>
lea    0xe3a(%rip),%rdi
mov    %rsp,%rdx
mov    %eax,%esi
call   1040 <printf@plt>
jmp    1246 <verify_callback+0xc6>
test   %ebp,%ebp
jne    1246 <verify_callback+0xc6>
jmp    120c <verify_callback+0x8c>
mov    0x2e01(%rip),%rax
mov    (%rax),%r14d
mov    %rbx,%rdi
call   10a0 <X509_STORE_CTX_get_error_depth@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <X509_STORE_CTX_get_error@plt>
lea    0xe12(%rip),%rsi
mov    %rsp,%r8
mov    %r14d,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <X509_STORE_CTX_get_error@plt>
lea    -0x80(%rax),%ecx
mov    $0x1,%ebp
cmp    $0x3,%ecx
jb     1246 <verify_callback+0xc6>
mov    0x2db8(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <X509_verify_cert_error_string@plt>
lea    0xdeb(%rip),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"depth=%d %s\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"depth=%d error=%d %s\0A\00"
@.str.2 = [18 x i8] c"Error string: %s\0A\00"
define i32 @verify_callback(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = load i32*, i32** %4
%9 = call i32 @X509_STORE_CTX_get_current_cert(i32* %8)
%10 = call i32 @X509_get_subject_name(i32 %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i8* @X509_NAME_oneline(i32 %10, i8* %11, i32 256)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %32
15: ; preds = %2
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32*, i32** %4
%20 = call i32 @X509_STORE_CTX_get_error_depth(i32* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21)
br label %31
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = load i32*, i32** %4
%26 = call i32 @X509_STORE_CTX_get_error_depth(i32* %25)
%27 = load i32*, i32** %4
%28 = call i32 @X509_STORE_CTX_get_error(i32* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %28, i8* %29)
br label %31
31: ; preds = %23, %18
br label %32
32: ; preds = %31, %2
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %32
%36 = load i32*, i32** %4
%37 = call i32 @X509_STORE_CTX_get_error(i32* %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
switch i32 %38, label %39 [
i32 129, label %44
i32 130, label %44
i32 128, label %44
]
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i32, i32* %7
%42 = call i8* @X509_verify_cert_error_string(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %45
44: ; preds = %35, %35, %35
store i32 1, i32* %3
br label %45
45: ; preds = %44, %39
br label %46
46: ; preds = %45, %32
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [13 x i8] c"depth=%d %s\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"depth=%d error=%d %s\0A\00"
@.str.2 = [18 x i8] c"Error string: %s\0A\00"
define i32 @verify_callback(i32 %0, i32* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @X509_STORE_CTX_get_current_cert(i32* %1)
%6 = tail call i32 @X509_get_subject_name(i32 %5)
%7 = call i8* @X509_NAME_oneline(i32 %6, i8* %4, i32 256)
%8 = icmp eq i8* %7, null
%9 = icmp eq i32 %0, 0
br i1 %8, label %19, label %10
10: ; preds = %2
br i1 %9, label %14, label %11
11: ; preds = %10
%12 = call i32 @X509_STORE_CTX_get_error_depth(i32* %1)
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %4)
br label %28
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @X509_STORE_CTX_get_error_depth(i32* %1)
%17 = call i32 @X509_STORE_CTX_get_error(i32* %1)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17, i8* %4)
br label %20
19: ; preds = %2
br i1 %9, label %20, label %28
20: ; preds = %14, %19
%21 = call i32 @X509_STORE_CTX_get_error(i32* %1)
%22 = add i32 %21, -128
%23 = icmp ult i32 %22, 3
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i8* @X509_verify_cert_error_string(i32 %21)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %11, %24, %20, %19
%29 = phi i32 [ %0, %19 ], [ 0, %24 ], [ 1, %20 ], [ %0, %11 ]
ret i32 %29
}