#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 */
int /*<<< orphan*/ FAIL(char *);
int /*<<< orphan*/ RTLD_NOLOAD;
scalar_t__ bazInitialized();
int /*<<< orphan*/ dlopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void myInit() {
  if (bazInitialized()) {
    FAIL("dlopen-RTLD_NOLOAD-in-initializer baz initialized too early");
    exit(0);
  }
  dlopen("libbaz.dylib", RTLD_NOLOAD);
  if (bazInitialized()) {
    FAIL("dlopen-RTLD_NOLOAD-in-initializer baz initialized by dlopen");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<myInit>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1040 <bazInitialized@plt>
cmp    $0x0,%rax
je     1168 <myInit+0x28>
lea    0xea4(%rip),%rdi
call   1060 <FAIL@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0xec4(%rip),%rdi
call   1030 <dlopen@plt>
mov    $0x0,%al
call   1040 <bazInitialized@plt>
cmp    $0x0,%rax
je     11a1 <myInit+0x61>
lea    0xeb4(%rip),%rdi
call   1060 <FAIL@plt>
xor    %edi,%edi
call   1050 <exit@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<myInit>:
push   %rax
xor    %eax,%eax
call   1040 <bazInitialized@plt>
test   %rax,%rax
jne    1170 <myInit+0x30>
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xedf(%rip),%rdi
call   1030 <dlopen@plt>
xor    %eax,%eax
call   1040 <bazInitialized@plt>
test   %rax,%rax
jne    1179 <myInit+0x39>
pop    %rax
ret
lea    0xe89(%rip),%rdi
jmp    1180 <myInit+0x40>
lea    0xec9(%rip),%rdi
call   1060 <FAIL@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"dlopen-RTLD_NOLOAD-in-initializer baz initialized too early\00"
@.str.1 = [13 x i8] c"libbaz.dylib\00"
@RTLD_NOLOAD = global i32 0
@.str.2 = [60 x i8] c"dlopen-RTLD_NOLOAD-in-initializer baz initialized by dlopen\00"
define void @myInit() {
%1 = call i64 (...) @bazInitialized()
%2 = icmp ne i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = call i32 @FAIL(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @exit(i32 0)
unreachable
6: ; preds = %0
%7 = load i32, i32* @RTLD_NOLOAD
%8 = call i32 @dlopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i64 (...) @bazInitialized()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = call i32 @FAIL(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"dlopen-RTLD_NOLOAD-in-initializer baz initialized too early\00"
@.str.1 = [13 x i8] c"libbaz.dylib\00"
@RTLD_NOLOAD = global i32 0
@.str.2 = [60 x i8] c"dlopen-RTLD_NOLOAD-in-initializer baz initialized by dlopen\00"
define void @myInit() {
%1 = tail call i64 (...) @bazInitialized()
%2 = icmp eq i64 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 @FAIL(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 0)
unreachable
6: ; preds = %0
%7 = load i32, i32* @RTLD_NOLOAD
%8 = tail call i32 @dlopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i64 (...) @bazInitialized()
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i32 @FAIL(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %6
ret void
}