#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__ {
  size_t bottom;
  size_t top;
  int *err_flags;
  int *err_data_flags;
  int *err_line;
  int /*<<< orphan*/ **err_file;
  int /*<<< orphan*/ **err_data;
  scalar_t__ *err_buffer;
};
typedef TYPE_1__ ERR_STATE;

/* Variables and functions */
int ERR_FLAG_MARK;
int ERR_NUM_ERRORS;
int ERR_TXT_MALLOCED;
TYPE_1__ *ERR_get_state();
int /*<<< orphan*/ OPENSSL_free(int /*<<< orphan*/ *);
int ERR_pop_to_mark(void) {
  ERR_STATE *es;
  es = ERR_get_state();
  while (es->bottom != es->top &&
         (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) {
    do {
      (es)->err_flags[es->top] = 0;
      (es)->err_buffer[es->top] = 0;
      do {
        if (((es)->err_data[es->top] != NULL) &&
            (es)->err_data_flags[es->top] & ERR_TXT_MALLOCED) {
          OPENSSL_free((es)->err_data[es->top]);
          (es)->err_data[es->top] = NULL;
        }
        (es)->err_data_flags[es->top] = 0;
      } while (0);
      (es)->err_file[es->top] = NULL;
      (es)->err_line[es->top] = -1;
    } while (0);
    es->top -= 1;
    if (es->top == -1)
      es->top = ERR_NUM_ERRORS - 1;
  }
  if (es->bottom == es->top)
    return 0;
  es->err_flags[es->top] &= ~ERR_FLAG_MARK;
  return 1;
}


x86 assembly (clang, -O0):
<ERR_pop_to_mark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <ERR_get_state@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
cmp    0x8(%rdx),%rcx
mov    %al,-0x11(%rbp)
je     1172 <ERR_pop_to_mark+0x52>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    (%rax,%rcx,4),%eax
mov    0x2e89(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1182 <ERR_pop_to_mark+0x62>
jmp    12a8 <ERR_pop_to_mark+0x188>
jmp    1187 <ERR_pop_to_mark+0x67>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1227 <ERR_pop_to_mark+0x107>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    (%rax,%rcx,4),%eax
mov    0x2ddd(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1227 <ERR_pop_to_mark+0x107>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <OPENSSL_free@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0xffffffffffffffff,0x8(%rax)
jne    12a3 <ERR_pop_to_mark+0x183>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1133 <ERR_pop_to_mark+0x13>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    12c9 <ERR_pop_to_mark+0x1a9>
movl   $0x0,-0x4(%rbp)
jmp    12f2 <ERR_pop_to_mark+0x1d2>
mov    0x2d20(%rip),%rax
mov    (%rax),%edx
xor    $0xffffffff,%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
and    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ERR_pop_to_mark>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <ERR_get_state@plt>
mov    %rax,%rbx
mov    0x8(%rax),%rax
cmp    %rax,(%rbx)
je     120e <ERR_pop_to_mark+0xee>
mov    0x2ea7(%rip),%rbp
mov    0x2e98(%rip),%r15
mov    0x2e71(%rip),%r12
jmp    1169 <ERR_pop_to_mark+0x49>
nopl   0x0(%rax)
cmp    %rax,(%rbx)
je     120e <ERR_pop_to_mark+0xee>
mov    0x10(%rbx),%rcx
mov    (%rcx,%rax,4),%edx
mov    0x0(%rbp),%esi
test   %edx,%esi
jne    1201 <ERR_pop_to_mark+0xe1>
movl   $0x0,(%rcx,%rax,4)
mov    0x38(%rbx),%rcx
movq   $0x0,(%rcx,%rax,8)
mov    0x8(%rbx),%rax
mov    0x30(%rbx),%rcx
mov    (%rcx,%rax,8),%rdi
test   %rdi,%rdi
je     11c1 <ERR_pop_to_mark+0xa1>
mov    0x18(%rbx),%rcx
mov    (%r12),%edx
test   %edx,(%rcx,%rax,4)
je     11c1 <ERR_pop_to_mark+0xa1>
call   1040 <OPENSSL_free@plt>
mov    0x8(%rbx),%rax
mov    0x30(%rbx),%rcx
movq   $0x0,(%rcx,%rax,8)
mov    0x18(%rbx),%rcx
movl   $0x0,(%rcx,%rax,4)
mov    0x28(%rbx),%rcx
movq   $0x0,(%rcx,%rax,8)
mov    0x20(%rbx),%rcx
movl   $0xffffffff,(%rcx,%rax,4)
sub    $0x1,%rax
mov    %rax,0x8(%rbx)
jae    1160 <ERR_pop_to_mark+0x40>
movslq (%r15),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%rbx)
jmp    1160 <ERR_pop_to_mark+0x40>
not    %esi
and    %esi,%edx
mov    %edx,(%rcx,%rax,4)
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64, i32*, i32*, i32*, i32**, i32**, i64* }
@ERR_FLAG_MARK = global i32 0
@ERR_TXT_MALLOCED = global i32 0
@ERR_NUM_ERRORS = global i32 0
define i32 @ERR_pop_to_mark() {
%1 = alloca i32
%2 = alloca %struct.TYPE_3__*
%3 = call %struct.TYPE_3__* (...) @ERR_get_state()
store %struct.TYPE_3__* %3, %struct.TYPE_3__** %2
br label %4
4: ; preds = %119, %0
%5 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
%7 = load i64, i64* %6
%8 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 1
%10 = load i64, i64* %9
%11 = icmp ne i64 %7, %10
br i1 %11, label %12, label %24
12: ; preds = %4
%13 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 2
%15 = load i32*, i32** %14
%16 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = getelementptr inbounds i32, i32* %15, i64 %18
%20 = load i32, i32* %19
%21 = load i32, i32* @ERR_FLAG_MARK
%22 = and i32 %20, %21
%23 = icmp eq i32 %22, 0
br label %24
24: ; preds = %12, %4
%25 = phi i1 [ false, %4 ], [ %23, %12 ]
br i1 %25, label %26, label %120
26: ; preds = %24
br label %27
27: ; preds = %26
%28 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 2
%30 = load i32*, i32** %29
%31 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 1
%33 = load i64, i64* %32
%34 = getelementptr inbounds i32, i32* %30, i64 %33
store i32 0, i32* %34
%35 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 7
%37 = load i64*, i64** %36
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 1
%40 = load i64, i64* %39
%41 = getelementptr inbounds i64, i64* %37, i64 %40
store i64 0, i64* %41
br label %42
42: ; preds = %27
%43 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i32 0, i32 6
%45 = load i32**, i32*** %44
%46 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 1
%48 = load i64, i64* %47
%49 = getelementptr inbounds i32*, i32** %45, i64 %48
%50 = load i32*, i32** %49
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %81
52: ; preds = %42
%53 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%54 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %53, i32 0, i32 3
%55 = load i32*, i32** %54
%56 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %56, i32 0, i32 1
%58 = load i64, i64* %57
%59 = getelementptr inbounds i32, i32* %55, i64 %58
%60 = load i32, i32* %59
%61 = load i32, i32* @ERR_TXT_MALLOCED
%62 = and i32 %60, %61
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %81
64: ; preds = %52
%65 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%66 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %65, i32 0, i32 6
%67 = load i32**, i32*** %66
%68 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%69 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %68, i32 0, i32 1
%70 = load i64, i64* %69
%71 = getelementptr inbounds i32*, i32** %67, i64 %70
%72 = load i32*, i32** %71
%73 = call i32 @OPENSSL_free(i32* %72)
%74 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%75 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %74, i32 0, i32 6
%76 = load i32**, i32*** %75
%77 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%78 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %77, i32 0, i32 1
%79 = load i64, i64* %78
%80 = getelementptr inbounds i32*, i32** %76, i64 %79
store i32* null, i32** %80
br label %81
81: ; preds = %64, %52, %42
%82 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%83 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %82, i32 0, i32 3
%84 = load i32*, i32** %83
%85 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%86 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %85, i32 0, i32 1
%87 = load i64, i64* %86
%88 = getelementptr inbounds i32, i32* %84, i64 %87
store i32 0, i32* %88
br label %89
89: ; preds = %81
%90 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%91 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %90, i32 0, i32 5
%92 = load i32**, i32*** %91
%93 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%94 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %93, i32 0, i32 1
%95 = load i64, i64* %94
%96 = getelementptr inbounds i32*, i32** %92, i64 %95
store i32* null, i32** %96
%97 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%98 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %97, i32 0, i32 4
%99 = load i32*, i32** %98
%100 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%101 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %100, i32 0, i32 1
%102 = load i64, i64* %101
%103 = getelementptr inbounds i32, i32* %99, i64 %102
store i32 -1, i32* %103
br label %104
104: ; preds = %89
%105 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%106 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %105, i32 0, i32 1
%107 = load i64, i64* %106
%108 = sub i64 %107, 1
store i64 %108, i64* %106
%109 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%110 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %109, i32 0, i32 1
%111 = load i64, i64* %110
%112 = icmp eq i64 %111, -1
br i1 %112, label %113, label %119
113: ; preds = %104
%114 = load i32, i32* @ERR_NUM_ERRORS
%115 = sub nsw i32 %114, 1
%116 = sext i32 %115 to i64
%117 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%118 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %117, i32 0, i32 1
store i64 %116, i64* %118
br label %119
119: ; preds = %113, %104
br label %4
120: ; preds = %24
%121 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%122 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %121, i32 0, i32 0
%123 = load i64, i64* %122
%124 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%125 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %124, i32 0, i32 1
%126 = load i64, i64* %125
%127 = icmp eq i64 %123, %126
br i1 %127, label %128, label %129
128: ; preds = %120
store i32 0, i32* %1
br label %141
129: ; preds = %120
%130 = load i32, i32* @ERR_FLAG_MARK
%131 = xor i32 %130, -1
%132 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%133 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %132, i32 0, i32 2
%134 = load i32*, i32** %133
%135 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%136 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %135, i32 0, i32 1
%137 = load i64, i64* %136
%138 = getelementptr inbounds i32, i32* %134, i64 %137
%139 = load i32, i32* %138
%140 = and i32 %139, %131
store i32 %140, i32* %138
store i32 1, i32* %1
br label %141
141: ; preds = %129, %128
%142 = load i32, i32* %1
ret i32 %142
}

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