#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 */
struct pe_as_rd {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ pe_as_rd_close_ids(struct pe_as_rd *);
int /*<<< orphan*/ pe_as_rd_close_nodes(struct pe_as_rd *);
int /*<<< orphan*/ pe_as_rd_is_open(struct pe_as_rd *);
int pe_as_rd_open_ids(struct pe_as_rd *, char const *);
int pe_as_rd_open_nodes(struct pe_as_rd *, char const *);
int pe_as_rd_open_strs(struct pe_as_rd *, char const *);
int pe_as_rd_data(struct pe_as_rd *rd, char const *data_prefix) {
  int err;
  assert(!pe_as_rd_is_open(rd));
  err = pe_as_rd_open_nodes(rd, data_prefix);
  if (err)
    goto could_not_open_nodes;
  err = pe_as_rd_open_ids(rd, data_prefix);
  if (err)
    goto could_not_open_ids;
  err = pe_as_rd_open_strs(rd, data_prefix);
  if (err)
    goto could_not_open_strs;
  return err;
could_not_open_strs:
  pe_as_rd_close_ids(rd);
could_not_open_ids:
  pe_as_rd_close_nodes(rd);
could_not_open_nodes:
  return err;
}


x86 assembly (clang, -O0):
<pe_as_rd_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pe_as_rd_is_open@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <pe_as_rd_open_nodes@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11ba <pe_as_rd_data+0x4a>
jmp    1215 <pe_as_rd_data+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <pe_as_rd_open_ids@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d9 <pe_as_rd_data+0x69>
jmp    120c <pe_as_rd_data+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <pe_as_rd_open_strs@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f8 <pe_as_rd_data+0x88>
jmp    1203 <pe_as_rd_data+0x93>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121b <pe_as_rd_data+0xab>
mov    -0x10(%rbp),%rdi
call   1090 <pe_as_rd_close_ids@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pe_as_rd_close_nodes@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pe_as_rd_data>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <pe_as_rd_is_open@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <pe_as_rd_open_nodes@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11cf <pe_as_rd_data+0x5f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <pe_as_rd_open_ids@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11c7 <pe_as_rd_data+0x57>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <pe_as_rd_open_strs@plt>
test   %eax,%eax
je     11d6 <pe_as_rd_data+0x66>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <pe_as_rd_close_ids@plt>
mov    %rbx,%rdi
call   1050 <pe_as_rd_close_nodes@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11cf <pe_as_rd_data+0x5f>

LLVM IR (-O0):
%struct.pe_as_rd = type { i32 }
define i32 @pe_as_rd_data(%struct.pe_as_rd* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.pe_as_rd*
%5 = alloca i8*
%6 = alloca i32
store %struct.pe_as_rd* %0, %struct.pe_as_rd** %4
store i8* %1, i8** %5
%7 = load %struct.pe_as_rd*, %struct.pe_as_rd** %4
%8 = call i32 @pe_as_rd_is_open(%struct.pe_as_rd* %7)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load %struct.pe_as_rd*, %struct.pe_as_rd** %4
%14 = load i8*, i8** %5
%15 = call i32 @pe_as_rd_open_nodes(%struct.pe_as_rd* %13, i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
br label %41
19: ; preds = %2
%20 = load %struct.pe_as_rd*, %struct.pe_as_rd** %4
%21 = load i8*, i8** %5
%22 = call i32 @pe_as_rd_open_ids(%struct.pe_as_rd* %20, i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %38
26: ; preds = %19
%27 = load %struct.pe_as_rd*, %struct.pe_as_rd** %4
%28 = load i8*, i8** %5
%29 = call i32 @pe_as_rd_open_strs(%struct.pe_as_rd* %27, i8* %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
br label %35
33: ; preds = %26
%34 = load i32, i32* %6
store i32 %34, i32* %3
br label %43
35: ; preds = %32
%36 = load %struct.pe_as_rd*, %struct.pe_as_rd** %4
%37 = call i32 @pe_as_rd_close_ids(%struct.pe_as_rd* %36)
br label %38
38: ; preds = %35, %25
%39 = load %struct.pe_as_rd*, %struct.pe_as_rd** %4
%40 = call i32 @pe_as_rd_close_nodes(%struct.pe_as_rd* %39)
br label %41
41: ; preds = %38, %18
%42 = load i32, i32* %6
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %33
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.pe_as_rd = type { i32 }
define i32 @pe_as_rd_data(%struct.pe_as_rd* %0, i8* %1) {
%3 = tail call i32 @pe_as_rd_is_open(%struct.pe_as_rd* %0)
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @pe_as_rd_open_nodes(%struct.pe_as_rd* %0, i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = tail call i32 @pe_as_rd_open_ids(%struct.pe_as_rd* %0, i8* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = tail call i32 @pe_as_rd_open_strs(%struct.pe_as_rd* %0, i8* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = tail call i32 @pe_as_rd_close_ids(%struct.pe_as_rd* %0)
br label %17
17: ; preds = %9, %15
%18 = phi i32 [ %10, %9 ], [ %13, %15 ]
%19 = tail call i32 @pe_as_rd_close_nodes(%struct.pe_as_rd* %0)
br label %20
20: ; preds = %17, %2, %12
%21 = phi i32 [ 0, %12 ], [ %7, %2 ], [ %18, %17 ]
ret i32 %21
}