#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 xbf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
char *xbf_errmsg(struct xbf *);
scalar_t__ xbf_initialized(struct xbf *);
int xbf_opened(struct xbf *xbf) {
  const char *estr;
  do {
    assert(xbf != NULL && "xbf can't be NULL here");
    assert(xbf_initialized(xbf) != 0 && "xbf_initialized() must be called");
  } while (0);
  estr = xbf_errmsg(xbf);
  return (estr[0] == '\0');
}


x86 assembly (clang, -O0):
<xbf_opened>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1156 <xbf_opened+0x26>
mov    $0x1,%al
mov    %al,-0x11(%rbp)
jmp    1156 <xbf_opened+0x26>
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1050 <xbf_initialized@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x12(%rbp)
je     1188 <xbf_opened+0x58>
mov    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    1188 <xbf_opened+0x58>
mov    -0x12(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <xbf_errmsg@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xbf_opened>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1050 <xbf_initialized@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1040 <xbf_errmsg@plt>
xor    %ecx,%ecx
cmpb   $0x0,(%rax)
sete   %cl
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.xbf = type { i32 }
@.str = [23 x i8] c"xbf can't be NULL here\00"
@.str.1 = [33 x i8] c"xbf_initialized() must be called\00"
define i32 @xbf_opened(%struct.xbf* %0) {
%2 = alloca %struct.xbf*
%3 = alloca i8*
store %struct.xbf* %0, %struct.xbf** %2
br label %4
4: ; preds = %1
%5 = load %struct.xbf*, %struct.xbf** %2
%6 = icmp ne %struct.xbf* %5, null
br i1 %6, label %7, label %8
7: ; preds = %4
br label %8
8: ; preds = %7, %4
%9 = phi i1 [ false, %4 ], [ true, %7 ]
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load %struct.xbf*, %struct.xbf** %2
%13 = call i64 @xbf_initialized(%struct.xbf* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
br label %16
16: ; preds = %15, %8
%17 = phi i1 [ false, %8 ], [ true, %15 ]
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
br label %20
20: ; preds = %16
%21 = load %struct.xbf*, %struct.xbf** %2
%22 = call i8* @xbf_errmsg(%struct.xbf* %21)
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
%struct.xbf = type { i32 }
define i32 @xbf_opened(%struct.xbf* %0) {
%2 = icmp ne %struct.xbf* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i64 @xbf_initialized(%struct.xbf* %0)
%6 = icmp ne i64 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i8* @xbf_errmsg(%struct.xbf* %0)
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
%12 = zext i1 %11 to i32
ret i32 %12
}