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

/* Variables and functions */
unsigned long ERR_GET_FUNC(unsigned long);
unsigned long ERR_GET_LIB(unsigned long);
unsigned long ERR_GET_REASON(unsigned long);
char *ERR_func_error_string(unsigned long);
char *ERR_lib_error_string(unsigned long);
char *ERR_reason_error_string(unsigned long);
int /*<<< orphan*/ sprintf(char *, char *, ...);
size_t strlen(char *);
char *ERR_error_string(unsigned long e, char *ret) {
  static char buf[256];
  const char *ls, *fs, *rs;
  unsigned long l, f, r;
  size_t i;
  l = ERR_GET_LIB(e);
  f = ERR_GET_FUNC(e);
  r = ERR_GET_REASON(e);
  ls = ERR_lib_error_string(e);
  fs = ERR_func_error_string(e);
  rs = ERR_reason_error_string(e);
  if (ret == NULL)
    ret = buf;
  sprintf(&(ret[0]), "error:%08lX:", e);
  i = strlen(ret);
  if (ls == NULL)
    sprintf(&(ret[i]), ":lib(%lu) ", l);
  else
    sprintf(&(ret[i]), "%s", ls);
  i = strlen(ret);
  if (fs == NULL)
    sprintf(&(ret[i]), ":func(%lu) ", f);
  else
    sprintf(&(ret[i]), ":%s", fs);
  i = strlen(ret);
  if (rs == NULL)
    sprintf(&(ret[i]), ":reason(%lu)", r);
  else
    sprintf(&(ret[i]), ":%s", rs);
  return (ret);
}


x86 assembly (clang, -O0):
<ERR_error_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ERR_GET_LIB@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <ERR_GET_FUNC@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <ERR_GET_REASON@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <ERR_lib_error_string@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <ERR_func_error_string@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ERR_reason_error_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f4 <ERR_error_string+0x74>
lea    0x2e80(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1241 <ERR_error_string+0xc1>
mov    -0x10(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    125b <ERR_error_string+0xdb>
mov    -0x10(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1292 <ERR_error_string+0x112>
mov    -0x10(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    12ac <ERR_error_string+0x12c>
mov    -0x10(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12e3 <ERR_error_string+0x163>
mov    -0x10(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    12fd <ERR_error_string+0x17d>
mov    -0x10(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd2e(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ERR_error_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
call   1070 <ERR_GET_LIB@plt>
mov    %rax,(%rsp)
mov    %r14,%rdi
call   1090 <ERR_GET_FUNC@plt>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   10b0 <ERR_GET_REASON@plt>
mov    %rax,0x10(%rsp)
mov    %r14,%rdi
call   1060 <ERR_lib_error_string@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1080 <ERR_func_error_string@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1050 <ERR_reason_error_string@plt>
mov    %rax,%r15
test   %rbp,%rbp
lea    0x2e8e(%rip),%rbx
cmovne %rbp,%rbx
lea    0xe03(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rbx,%rax
test   %r12,%r12
je     1227 <ERR_error_string+0x97>
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
jmp    123c <ERR_error_string+0xac>
lea    0xddf(%rip),%rsi
mov    %rax,%rdi
mov    (%rsp),%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rbx,%rax
test   %r13,%r13
je     125b <ERR_error_string+0xcb>
lea    0xdd1(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
jmp    126a <ERR_error_string+0xda>
lea    0xdb6(%rip),%rsi
mov    %rax,%rdi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rbx,%rax
test   %r15,%r15
je     1290 <ERR_error_string+0x100>
lea    0xd9c(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
jmp    129f <ERR_error_string+0x10f>
lea    0xd91(%rip),%rsi
mov    %rax,%rdi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERR_error_string.buf = internal global [256 x i8] zeroinitializer
@.str = [13 x i8] c"error:%08lX:\00"
@.str.1 = [11 x i8] c":lib(%lu) \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c":func(%lu) \00"
@.str.4 = [4 x i8] c":%s\00"
@.str.5 = [13 x i8] c":reason(%lu)\00"
define i8* @ERR_error_string(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
%12 = load i64, i64* %3
%13 = call i64 @ERR_GET_LIB(i64 %12)
store i64 %13, i64* %8
%14 = load i64, i64* %3
%15 = call i64 @ERR_GET_FUNC(i64 %14)
store i64 %15, i64* %9
%16 = load i64, i64* %3
%17 = call i64 @ERR_GET_REASON(i64 %16)
store i64 %17, i64* %10
%18 = load i64, i64* %3
%19 = call i8* @ERR_lib_error_string(i64 %18)
store i8* %19, i8** %5
%20 = load i64, i64* %3
%21 = call i8* @ERR_func_error_string(i64 %20)
store i8* %21, i8** %6
%22 = load i64, i64* %3
%23 = call i8* @ERR_reason_error_string(i64 %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %4
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %2
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @ERR_error_string.buf, i64 0, i64 0), i8** %4
br label %27
27: ; preds = %26, %2
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i64, i64* %3
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %30)
%32 = load i8*, i8** %4
%33 = call i64 @strlen(i8* %32)
store i64 %33, i64* %11
%34 = load i8*, i8** %5
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %42
36: ; preds = %27
%37 = load i8*, i8** %4
%38 = load i64, i64* %11
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i64, i64* %8
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %40)
br label %48
42: ; preds = %27
%43 = load i8*, i8** %4
%44 = load i64, i64* %11
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8*, i8** %5
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %42, %36
%49 = load i8*, i8** %4
%50 = call i64 @strlen(i8* %49)
store i64 %50, i64* %11
%51 = load i8*, i8** %6
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i8*, i8** %4
%55 = load i64, i64* %11
%56 = getelementptr inbounds i8, i8* %54, i64 %55
%57 = load i64, i64* %9
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %56, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %57)
br label %65
59: ; preds = %48
%60 = load i8*, i8** %4
%61 = load i64, i64* %11
%62 = getelementptr inbounds i8, i8* %60, i64 %61
%63 = load i8*, i8** %6
%64 = call i32 (i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %59, %53
%66 = load i8*, i8** %4
%67 = call i64 @strlen(i8* %66)
store i64 %67, i64* %11
%68 = load i8*, i8** %7
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %76
70: ; preds = %65
%71 = load i8*, i8** %4
%72 = load i64, i64* %11
%73 = getelementptr inbounds i8, i8* %71, i64 %72
%74 = load i64, i64* %10
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %74)
br label %82
76: ; preds = %65
%77 = load i8*, i8** %4
%78 = load i64, i64* %11
%79 = getelementptr inbounds i8, i8* %77, i64 %78
%80 = load i8*, i8** %7
%81 = call i32 (i8*, i8*, ...) @sprintf(i8* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %76, %70
%83 = load i8*, i8** %4
ret i8* %83
}

LLVM IR (-O2):
@ERR_error_string.buf = internal global [256 x i8] zeroinitializer
@.str = [13 x i8] c"error:%08lX:\00"
@.str.1 = [11 x i8] c":lib(%lu) \00"
@.str.3 = [12 x i8] c":func(%lu) \00"
@.str.4 = [4 x i8] c":%s\00"
@.str.5 = [13 x i8] c":reason(%lu)\00"
define i8* @ERR_error_string(i64 %0, i8* %1) {
%3 = tail call i64 @ERR_GET_LIB(i64 %0)
%4 = tail call i64 @ERR_GET_FUNC(i64 %0)
%5 = tail call i64 @ERR_GET_REASON(i64 %0)
%6 = tail call i8* @ERR_lib_error_string(i64 %0)
%7 = tail call i8* @ERR_func_error_string(i64 %0)
%8 = tail call i8* @ERR_reason_error_string(i64 %0)
%9 = icmp eq i8* %1, null
%10 = select i1 %9, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @ERR_error_string.buf, i64 0, i64 0), i8* %1
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %0)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%13 = icmp eq i8* %6, null
%14 = getelementptr inbounds i8, i8* %10, i64 %12
br i1 %13, label %15, label %17
15: ; preds = %2
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %3)
br label %19
17: ; preds = %2
%18 = tail call i8* @strcpy(i8* dereferenceable(1) %14, i8* %6)
br label %19
19: ; preds = %17, %15
%20 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%21 = icmp eq i8* %7, null
%22 = getelementptr inbounds i8, i8* %10, i64 %20
br i1 %21, label %23, label %25
23: ; preds = %19
%24 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %4)
br label %27
25: ; preds = %19
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %7)
br label %27
27: ; preds = %25, %23
%28 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%29 = icmp eq i8* %8, null
%30 = getelementptr inbounds i8, i8* %10, i64 %28
br i1 %29, label %31, label %33
31: ; preds = %27
%32 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %30, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %5)
br label %35
33: ; preds = %27
%34 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %30, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %8)
br label %35
35: ; preds = %33, %31
ret i8* %10
}