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

/* Variables and functions */
int /*<<< orphan*/ CRYPTO_THREADID_current(int /*<<< orphan*/ *);
unsigned long CRYPTO_THREADID_hash(int /*<<< orphan*/ *);
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 *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long, char *,
                            char const *, int, char const *);
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;
  unsigned long es;
  CRYPTO_THREADID cur;
  CRYPTO_THREADID_current(&cur);
  es = CRYPTO_THREADID_hash(&cur);
  while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
    ERR_error_string_n(l, buf, sizeof buf);
    (void)snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, 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)
lea    -0x1144(%rbp),%rdi
call   1030 <CRYPTO_THREADID_current@plt>
lea    -0x1144(%rbp),%rdi
call   1070 <CRYPTO_THREADID_hash@plt>
mov    %rax,-0x1140(%rbp)
lea    -0x1128(%rbp),%rdi
lea    -0x1134(%rbp),%rsi
lea    -0x1130(%rbp),%rdx
lea    -0x1138(%rbp),%rcx
call   1080 <ERR_get_error_line_data@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12eb <ERR_print_errors_cb+0x18b>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <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,-0x1148(%rbp)
mov    -0x1138(%rbp),%eax
mov    0x2dd1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1245 <ERR_print_errors_cb+0xe5>
mov    -0x1130(%rbp),%rax
mov    %rax,-0x1170(%rbp)
jmp    1258 <ERR_print_errors_cb+0xf8>
lea    0xdc4(%rip),%rax
mov    %rax,-0x1170(%rbp)
jmp    1258 <ERR_print_errors_cb+0xf8>
mov    -0x1148(%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    0xd72(%rip),%rdx
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x1178(%rbp)
lea    -0x1120(%rbp),%rax
mov    %rax,-0x1180(%rbp)
lea    -0x1120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1180(%rbp),%rdi
mov    %rax,%rsi
mov    -0x1178(%rbp),%rax
mov    -0x10(%rbp),%rdx
call   *%rax
cmp    $0x0,%eax
jg     12e6 <ERR_print_errors_cb+0x186>
jmp    12eb <ERR_print_errors_cb+0x18b>
jmp    1192 <ERR_print_errors_cb+0x32>
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
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <CRYPTO_THREADID_current@plt>
mov    %rbx,%rdi
call   1070 <CRYPTO_THREADID_hash@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%r13
lea    0x120(%rsp),%r12
jmp    11e1 <ERR_print_errors_cb+0x81>
xchg   %ax,%ax
mov    0x10(%rsp),%r9
mov    0x4(%rsp),%ebp
mov    %r12,%rdi
mov    $0x1000,%esi
lea    0xe48(%rip),%rdx
mov    %rbx,%rcx
mov    %r13,%r8
push   %rax
push   %rbp
call   1050 <snprintf@plt>
add    $0x10,%rsp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   *%r15
test   %eax,%eax
jle    1230 <ERR_print_errors_cb+0xd0>
lea    0x10(%rsp),%rdi
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
call   1080 <ERR_get_error_line_data@plt>
test   %rax,%rax
je     1230 <ERR_print_errors_cb+0xd0>
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x100,%edx
call   1060 <ERR_error_string_n@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%ecx
lea    0xdf3(%rip),%rax
and    (%rsp),%ecx
je     11a0 <ERR_print_errors_cb+0x40>
mov    0x8(%rsp),%rax
jmp    11a0 <ERR_print_errors_cb+0x40>
add    $0x1128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.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 i64
%13 = alloca i32
store i32 (i8*, i64, i8*)* %0, i32 (i8*, i64, i8*)** %3
store i8* %1, i8** %4
%14 = call i32 @CRYPTO_THREADID_current(i32* %13)
%15 = call i64 @CRYPTO_THREADID_hash(i32* %13)
store i64 %15, i64* %12
br label %16
16: ; preds = %46, %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 %47
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 = load i64, i64* %12
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %8
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = load i32, i32* @ERR_TXT_STRING
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %19
%33 = load i8*, i8** %9
br label %35
34: ; preds = %19
br label %35
35: ; preds = %34, %32
%36 = phi i8* [ %33, %32 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %34 ]
%37 = call i32 @snprintf(i8* %23, i32 4096, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %24, i8* %25, i8* %26, i32 %27, i8* %36)
%38 = load i32 (i8*, i64, i8*)*, i32 (i8*, i64, i8*)** %3
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%41 = call i64 @strlen(i8* %40)
%42 = load i8*, i8** %4
%43 = call i32 %38(i8* %39, i64 %41, i8* %42)
%44 = icmp sle i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %35
br label %47
46: ; preds = %35
br label %16
47: ; preds = %45, %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 = alloca i32
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%12 = bitcast i8** %5 to i8*
%13 = bitcast i8** %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = call i32 @CRYPTO_THREADID_current(i32* %9)
%18 = call i64 @CRYPTO_THREADID_hash(i32* %9)
br label %19
19: ; preds = %22, %2
%20 = call i64 @ERR_get_error_line_data(i8** %5, i32* %7, i8** %6, i32* %8)
%21 = icmp eq i64 %20, 0
br i1 %21, label %36, label %22
22: ; preds = %19
%23 = call i32 @ERR_error_string_n(i64 %20, i8* %10, i32 256)
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = load i32, i32* @ERR_TXT_STRING
%28 = and i32 %27, %26
%29 = icmp eq i32 %28, 0
%30 = load i8*, i8** %6
%31 = select i1 %29, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %30
%32 = call i32 @snprintf(i8* %11, i32 4096, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %18, i8* %10, i8* %24, i32 %25, i8* %31)
%33 = call i64 @strlen(i8* %11)
%34 = call i32 %0(i8* %11, i64 %33, i8* %1)
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %19
36: ; preds = %22, %19
ret void
}