#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*/ LIBM_SO;
int /*<<< orphan*/ RTLD_LAZY;
int /*<<< orphan*/ RTLD_NOW;
int /*<<< orphan*/ dlclose(void *);
int /*<<< orphan*/ dlerror();
void *dlopen(int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  void *handle;
  handle = dlopen(LIBM_SO, RTLD_LAZY);
  (void)dlerror();
  if (handle)
    (void)dlclose(handle);
  handle = dlopen(LIBM_SO, RTLD_NOW);
  (void)dlerror();
  if (handle)
    (void)dlclose(handle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
cmpq   $0x0,-0x10(%rbp)
je     1175 <main+0x45>
mov    -0x10(%rbp),%rdi
call   1050 <dlclose@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ab <main+0x7b>
mov    -0x10(%rbp),%rdi
call   1050 <dlclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ead(%rip),%r14
mov    (%r14),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rbx,%rbx
je     1163 <main+0x33>
mov    %rbx,%rdi
call   1050 <dlclose@plt>
mov    (%r14),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rbx,%rbx
je     118b <main+0x5b>
mov    %rbx,%rdi
call   1050 <dlclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@LIBM_SO = global i32 0
@RTLD_LAZY = global i32 0
@RTLD_NOW = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = load i32, i32* @LIBM_SO
%4 = load i32, i32* @RTLD_LAZY
%5 = call i8* @dlopen(i32 %3, i32 %4)
store i8* %5, i8** %2
%6 = call i32 (...) @dlerror()
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = call i32 @dlclose(i8* %10)
br label %12
12: ; preds = %9, %0
%13 = load i32, i32* @LIBM_SO
%14 = load i32, i32* @RTLD_NOW
%15 = call i8* @dlopen(i32 %13, i32 %14)
store i8* %15, i8** %2
%16 = call i32 (...) @dlerror()
%17 = load i8*, i8** %2
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i8*, i8** %2
%21 = call i32 @dlclose(i8* %20)
br label %22
22: ; preds = %19, %12
ret i32 0
}

LLVM IR (-O2):
@LIBM_SO = global i32 0
@RTLD_LAZY = global i32 0
@RTLD_NOW = global i32 0
define i32 @main() {
%1 = load i32, i32* @LIBM_SO
%2 = load i32, i32* @RTLD_LAZY
%3 = tail call i8* @dlopen(i32 %1, i32 %2)
%4 = tail call i32 (...) @dlerror()
%5 = icmp eq i8* %3, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @dlclose(i8* %3)
br label %8
8: ; preds = %6, %0
%9 = load i32, i32* @LIBM_SO
%10 = load i32, i32* @RTLD_NOW
%11 = tail call i8* @dlopen(i32 %9, i32 %10)
%12 = tail call i32 (...) @dlerror()
%13 = icmp eq i8* %11, null
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = tail call i32 @dlclose(i8* %11)
br label %16
16: ; preds = %14, %8
ret i32 0
}