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

/* Variables and functions */
int /*<<< orphan*/ BIO_snprintf(char *, int, char *, unsigned long, char *,
                                char const *, int, char const *);
int /*<<< orphan*/ CRYPTO_THREAD_get_current_id();
int ERR_TXT_STRING;
int /*<<< orphan*/ ERR_error_string_n(unsigned long, char *, int);
unsigned long ERR_get_error_line_data(char const **, int *, char const **,
                                      int *);
size_t strlen(char *);
void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
                         void *u) {
  unsigned long l;
  char buf[256];
  char buf2[4096];
  const char *file, *data;
  int line, flags;
  union {
    CRYPTO_THREAD_ID tid;
    unsigned long ltid;
  } tid;
  tid.ltid = 0;
  tid.tid = CRYPTO_THREAD_get_current_id();
  while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
    ERR_error_string_n(l, buf, sizeof buf);
    BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf, file,
                 line, (flags & ERR_TXT_STRING) ? data : "");
    if (cb(buf2, strlen(buf2), u) <= 0)
      break;
  }
}


x86 assembly (clang, -O0):
<ERR_print_errors_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1190,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x1140(%rbp)
mov    $0x0,%al
call   1040 <CRYPTO_THREAD_get_current_id@plt>
mov    %eax,-0x1140(%rbp)
lea    -0x1128(%rbp),%rdi
lea    -0x1134(%rbp),%rsi
lea    -0x1130(%rbp),%rdx
lea    -0x1138(%rbp),%rcx
call   1070 <ERR_get_error_line_data@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12d4 <ERR_print_errors_cb+0x184>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1050 <ERR_error_string_n@plt>
lea    -0x1120(%rbp),%rax
mov    %rax,-0x1168(%rbp)
mov    -0x1140(%rbp),%rax
mov    %rax,-0x1160(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x1158(%rbp)
mov    -0x1128(%rbp),%rax
mov    %rax,-0x1150(%rbp)
mov    -0x1134(%rbp),%eax
mov    %eax,-0x1144(%rbp)
mov    -0x1138(%rbp),%eax
mov    0x2de8(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     122e <ERR_print_errors_cb+0xde>
mov    -0x1130(%rbp),%rax
mov    %rax,-0x1170(%rbp)
jmp    1241 <ERR_print_errors_cb+0xf1>
lea    0xddb(%rip),%rax
mov    %rax,-0x1170(%rbp)
jmp    1241 <ERR_print_errors_cb+0xf1>
mov    -0x1144(%rbp),%r10d
mov    -0x1150(%rbp),%r9
mov    -0x1158(%rbp),%r8
mov    -0x1160(%rbp),%rcx
mov    -0x1168(%rbp),%rdi
mov    -0x1170(%rbp),%rax
mov    $0x1000,%esi
lea    0xd89(%rip),%rdx
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <BIO_snprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x1178(%rbp)
lea    -0x1120(%rbp),%rax
mov    %rax,-0x1180(%rbp)
lea    -0x1120(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1180(%rbp),%rdi
mov    %rax,%rsi
mov    -0x1178(%rbp),%rax
mov    -0x10(%rbp),%rdx
call   *%rax
cmp    $0x0,%eax
jg     12cf <ERR_print_errors_cb+0x17f>
jmp    12d4 <ERR_print_errors_cb+0x184>
jmp    117b <ERR_print_errors_cb+0x2b>
add    $0x1190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ERR_print_errors_cb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1128,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <CRYPTO_THREAD_get_current_id@plt>
mov    %eax,%ebx
lea    0x20(%rsp),%r13
lea    0x120(%rsp),%r12
jmp    11c1 <ERR_print_errors_cb+0x71>
nop
mov    0x18(%rsp),%r9
mov    0xc(%rsp),%ebp
mov    %r12,%rdi
mov    $0x1000,%esi
lea    0xe68(%rip),%rdx
mov    %rbx,%rcx
mov    %r13,%r8
push   %rax
push   %rbp
call   1060 <BIO_snprintf@plt>
add    $0x10,%rsp
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   *%r15
test   %eax,%eax
jle    1213 <ERR_print_errors_cb+0xc3>
lea    0x18(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1070 <ERR_get_error_line_data@plt>
test   %rax,%rax
je     1213 <ERR_print_errors_cb+0xc3>
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x100,%edx
call   1050 <ERR_error_string_n@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%ecx
lea    0xe11(%rip),%rax
and    0x8(%rsp),%ecx
je     1180 <ERR_print_errors_cb+0x30>
mov    0x10(%rsp),%rax
jmp    1180 <ERR_print_errors_cb+0x30>
add    $0x1128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.anon = type { i64 }
@.str = [17 x i8] c"%lu:%s:%s:%d:%s\0A\00"
@ERR_TXT_STRING = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define void @ERR_print_errors_cb(i32 (i8*, i64, i8*)* %0, i8* %1) {
%3 = alloca i32 (i8*, i64, i8*)*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [256 x i8]
%7 = alloca [4096 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca %union.anon
store i32 (i8*, i64, i8*)* %0, i32 (i8*, i64, i8*)** %3
store i8* %1, i8** %4
%13 = bitcast %union.anon* %12 to i64*
store i64 0, i64* %13
%14 = call i32 (...) @CRYPTO_THREAD_get_current_id()
%15 = bitcast %union.anon* %12 to i32*
store i32 %14, i32* %15
br label %16
16: ; preds = %47, %2
%17 = call i64 @ERR_get_error_line_data(i8** %8, i32* %10, i8** %9, i32* %11)
store i64 %17, i64* %5
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %48
19: ; preds = %16
%20 = load i64, i64* %5
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @ERR_error_string_n(i64 %20, i8* %21, i32 256)
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%24 = bitcast %union.anon* %12 to i64*
%25 = load i64, i64* %24
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %8
%28 = load i32, i32* %10
%29 = load i32, i32* %11
%30 = load i32, i32* @ERR_TXT_STRING
%31 = and i32 %29, %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %19
%34 = load i8*, i8** %9
br label %36
35: ; preds = %19
br label %36
36: ; preds = %35, %33
%37 = phi i8* [ %34, %33 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %35 ]
%38 = call i32 @BIO_snprintf(i8* %23, i32 4096, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %25, i8* %26, i8* %27, i32 %28, i8* %37)
%39 = load i32 (i8*, i64, i8*)*, i32 (i8*, i64, i8*)** %3
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = load i8*, i8** %4
%44 = call i32 %39(i8* %40, i64 %42, i8* %43)
%45 = icmp sle i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %36
br label %48
47: ; preds = %36
br label %16
48: ; preds = %46, %16
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"%lu:%s:%s:%d:%s\0A\00"
@ERR_TXT_STRING = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define void @ERR_print_errors_cb(i32 (i8*, i64, i8*)* nocapture %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [4096 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%11 = bitcast i8** %5 to i8*
%12 = bitcast i8** %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = tail call i32 (...) @CRYPTO_THREAD_get_current_id()
%16 = zext i32 %15 to i64
br label %17
17: ; preds = %20, %2
%18 = call i64 @ERR_get_error_line_data(i8** %5, i32* %7, i8** %6, i32* %8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %34, label %20
20: ; preds = %17
%21 = call i32 @ERR_error_string_n(i64 %18, i8* %9, i32 256)
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = load i32, i32* @ERR_TXT_STRING
%26 = and i32 %25, %24
%27 = icmp eq i32 %26, 0
%28 = load i8*, i8** %6
%29 = select i1 %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %28
%30 = call i32 @BIO_snprintf(i8* %10, i32 4096, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %16, i8* %9, i8* %22, i32 %23, i8* %29)
%31 = call i64 @strlen(i8* %10)
%32 = call i32 %0(i8* %10, i64 %31, i8* %1)
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %17
34: ; preds = %20, %17
ret void
}