#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*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char const *, int);
unsigned long CRYPTO_thread_id();
int ERR_TXT_STRING;
int /*<<< orphan*/ ERR_error_string(unsigned long, char *);
unsigned long ERR_get_error_line_data(char const **, int *, char const **,
                                      int *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned long, int /*<<< orphan*/,
                           char const *, int);
scalar_t__ strlen(char const *);
void ERR_print_errors(BIO *bp) {
  unsigned long l;
  char buf[256];
  char buf2[256];
  const char *file, *data;
  int line, flags;
  unsigned long es;
  es = CRYPTO_thread_id();
  while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
    sprintf(buf2, "%lu:%s:%s:%d:", es, ERR_error_string(l, buf), file, line);
    BIO_write(bp, buf2, (int)strlen(buf2));
    if (flags & ERR_TXT_STRING)
      BIO_write(bp, data, (int)strlen(data));
    BIO_write(bp, "\n", 1);
  }
}


x86 assembly (clang, -O0):
<ERR_print_errors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <CRYPTO_thread_id@plt>
mov    %rax,-0x230(%rbp)
lea    -0x218(%rbp),%rdi
lea    -0x224(%rbp),%rsi
lea    -0x220(%rbp),%rdx
lea    -0x228(%rbp),%rcx
call   1060 <ERR_get_error_line_data@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     12a8 <ERR_print_errors+0x148>
lea    -0x210(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x230(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1040 <ERR_error_string@plt>
mov    -0x250(%rbp),%rdi
mov    -0x248(%rbp),%rdx
mov    %eax,%ecx
mov    -0x218(%rbp),%r8
mov    -0x224(%rbp),%r9d
lea    0xe03(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x240(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x238(%rbp)
lea    -0x210(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x240(%rbp),%rdi
mov    -0x238(%rbp),%rsi
mov    %eax,%edx
call   1080 <BIO_write@plt>
mov    -0x228(%rbp),%eax
mov    0x2daf(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     128e <ERR_print_errors+0x12e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    -0x220(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0x220(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x260(%rbp),%rdi
mov    -0x258(%rbp),%rsi
mov    %eax,%edx
call   1080 <BIO_write@plt>
mov    -0x8(%rbp),%rdi
lea    0xd75(%rip),%rsi
mov    $0x1,%edx
call   1080 <BIO_write@plt>
jmp    117d <ERR_print_errors+0x1d>
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ERR_print_errors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <CRYPTO_thread_id@plt>
mov    %rax,%r14
lea    0x18(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1060 <ERR_get_error_line_data@plt>
test   %rax,%rax
je     125f <ERR_print_errors+0xff>
lea    0x20(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%r15
jmp    11ee <ERR_print_errors+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe44(%rip),%rsi
mov    $0x1,%edx
call   1080 <BIO_write@plt>
lea    0x18(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1060 <ERR_get_error_line_data@plt>
test   %rax,%rax
je     125f <ERR_print_errors+0xff>
mov    %rax,%rdi
lea    0x120(%rsp),%rsi
call   1040 <ERR_error_string@plt>
mov    0x18(%rsp),%r8
mov    0xc(%rsp),%r9d
mov    %r13,%rdi
lea    0xdee(%rip),%rsi
mov    %r14,%rdx
mov    %eax,%ecx
call   1070 <sprintf@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1080 <BIO_write@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
test   %eax,0x8(%rsp)
je     11c0 <ERR_print_errors+0x60>
mov    0x10(%rsp),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1080 <BIO_write@plt>
jmp    11c0 <ERR_print_errors+0x60>
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"%lu:%s:%s:%d:\00"
@ERR_TXT_STRING = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define void @ERR_print_errors(i32* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = bitcast i8** %4 to i8*
%11 = bitcast i8** %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = tail call i64 (...) @CRYPTO_thread_id()
%15 = call i64 @ERR_get_error_line_data(i8** %4, i32* %6, i8** %5, i32* %7)
%16 = icmp eq i64 %15, 0
br i1 %16, label %39, label %17
17: ; preds = %1, %35
%18 = phi i64 [ %37, %35 ], [ %15, %1 ]
%19 = call i32 @ERR_error_string(i64 %18, i8* %8)
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %19, i8* %20, i32 %21)
%23 = call i64 @strlen(i8* %9)
%24 = trunc i64 %23 to i32
%25 = call i32 @BIO_write(i32* %0, i8* %9, i32 %24)
%26 = load i32, i32* %7
%27 = load i32, i32* @ERR_TXT_STRING
%28 = and i32 %27, %26
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %17
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* dereferenceable(1) %31)
%33 = trunc i64 %32 to i32
%34 = call i32 @BIO_write(i32* %0, i8* %31, i32 %33)
br label %35
35: ; preds = %30, %17
%36 = call i32 @BIO_write(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%37 = call i64 @ERR_get_error_line_data(i8** %4, i32* %6, i8** %5, i32* %7)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %17
39: ; preds = %35, %1
ret void
}