#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int top;
  char **err_data;
  int *err_data_flags;
};
typedef TYPE_1__ ERR_STATE;

/* Variables and functions */
int ERR_NUM_ERRORS;
int ERR_TXT_MALLOCED;
TYPE_1__ *ERR_get_state();
int /*<<< orphan*/ OPENSSL_free(char *);
void ERR_set_error_data(char *data, int flags) {
  ERR_STATE *es;
  int i;
  es = ERR_get_state();
  i = es->top;
  if (i == 0)
    i = ERR_NUM_ERRORS - 1;
  do {
    if (((es)->err_data[i] != NULL) &&
        (es)->err_data_flags[i] & ERR_TXT_MALLOCED) {
      OPENSSL_free((es)->err_data[i]);
      (es)->err_data[i] = NULL;
    }
    (es)->err_data_flags[i] = 0;
  } while (0);
  es->err_data[i] = data;
  es->err_data_flags[i] = flags;
}


x86 assembly (clang, -O0):
<ERR_set_error_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <ERR_get_state@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    115c <ERR_set_error_data+0x3c>
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <ERR_set_error_data+0x41>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c2 <ERR_set_error_data+0xa2>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    0x2e42(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11c2 <ERR_set_error_data+0xa2>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <OPENSSL_free@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ERR_set_error_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <ERR_get_state@plt>
mov    %rax,%rbp
mov    (%rax),%eax
mov    0x2eb0(%rip),%rcx
mov    (%rcx),%ecx
add    $0xffffffff,%ecx
test   %eax,%eax
cmovne %eax,%ecx
mov    0x8(%rbp),%rax
movslq %ecx,%rbx
mov    (%rax,%rbx,8),%rdi
test   %rdi,%rdi
je     1181 <ERR_set_error_data+0x61>
mov    0x10(%rbp),%rcx
mov    0x2e6b(%rip),%rdx
mov    (%rdx),%edx
test   %edx,(%rcx,%rbx,4)
je     1181 <ERR_set_error_data+0x61>
call   1040 <OPENSSL_free@plt>
mov    0x8(%rbp),%rax
movq   $0x0,(%rax,%rbx,8)
mov    0x8(%rbp),%rax
mov    0x10(%rbp),%rcx
movl   $0x0,(%rcx,%rbx,4)
mov    %r15,(%rax,%rbx,8)
mov    0x10(%rbp),%rax
mov    %r14d,(%rax,%rbx,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8**, i32* }
@ERR_NUM_ERRORS = global i32 0
@ERR_TXT_MALLOCED = global i32 0
define void @ERR_set_error_data(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call %struct.TYPE_3__* (...) @ERR_get_state()
store %struct.TYPE_3__* %7, %struct.TYPE_3__** %5
%8 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @ERR_NUM_ERRORS
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %6
br label %16
16: ; preds = %13, %2
br label %17
17: ; preds = %16
%18 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 1
%20 = load i8**, i8*** %19
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %52
26: ; preds = %17
%27 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %27, i32 0, i32 2
%29 = load i32*, i32** %28
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* @ERR_TXT_MALLOCED
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %52
37: ; preds = %26
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 1
%40 = load i8**, i8*** %39
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @OPENSSL_free(i8* %44)
%46 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 1
%48 = load i8**, i8*** %47
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* null, i8** %51
br label %52
52: ; preds = %37, %26, %17
%53 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%54 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %53, i32 0, i32 2
%55 = load i32*, i32** %54
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
store i32 0, i32* %58
br label %59
59: ; preds = %52
%60 = load i8*, i8** %3
%61 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %61, i32 0, i32 1
%63 = load i8**, i8*** %62
%64 = load i32, i32* %6
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
store i8* %60, i8** %66
%67 = load i32, i32* %4
%68 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%69 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %68, i32 0, i32 2
%70 = load i32*, i32** %69
%71 = load i32, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
store i32 %67, i32* %73
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8**, i32* }
@ERR_NUM_ERRORS = global i32 0
@ERR_TXT_MALLOCED = global i32 0
define void @ERR_set_error_data(i8* %0, i32 %1) {
%3 = tail call %struct.TYPE_3__* (...) @ERR_get_state()
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
%7 = load i32, i32* @ERR_NUM_ERRORS
%8 = add nsw i32 %7, -1
%9 = select i1 %6, i32 %8, i32 %5
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 1
%11 = load i8**, i8*** %10
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds i8*, i8** %11, i64 %12
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %29, label %16
16: ; preds = %2
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 2
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 %12
%20 = load i32, i32* %19
%21 = load i32, i32* @ERR_TXT_MALLOCED
%22 = and i32 %21, %20
%23 = icmp eq i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %16
%25 = tail call i32 @OPENSSL_free(i8* %14)
%26 = load i8**, i8*** %10
%27 = getelementptr inbounds i8*, i8** %26, i64 %12
store i8* null, i8** %27
%28 = load i8**, i8*** %10
br label %29
29: ; preds = %24, %16, %2
%30 = phi i8** [ %28, %24 ], [ %11, %16 ], [ %11, %2 ]
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 2
%32 = load i32*, i32** %31
%33 = getelementptr inbounds i32, i32* %32, i64 %12
store i32 0, i32* %33
%34 = getelementptr inbounds i8*, i8** %30, i64 %12
store i8* %0, i8** %34
%35 = load i32*, i32** %31
%36 = getelementptr inbounds i32, i32* %35, i64 %12
store i32 %1, i32* %36
ret void
}