#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 RTLD_LAZY;
int RTLD_NOLOAD;
scalar_t__ dlclose(void *);
char *dlerror();
int /*<<< orphan*/ *dlopen(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int main(void) {
  int result = 0;
  if (dlopen("testobj1.so", RTLD_LAZY | RTLD_NOLOAD) == NULL) {
    printf("cannot open \"testobj1.so\": %s\n", dlerror());
    result = 1;
  } else
    puts("loading \"testobj1.so\" succeeded, OK");
  if (dlopen("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) != NULL) {
    puts("succeeded in loading \"testobj5.so\"");
    result = 1;
  } else {
    void *p;
    puts("\"testobj5.so\" wasn't loaded and RTLD_NOLOAD prevented it, OK");
    p = dlopen("testobj5.so", RTLD_LAZY);
    if (p == NULL) {
      printf("cannot open \"testobj5.so\" without RTLD_NOLOAD: %s\n",
             dlerror());
      result = 1;
    } else {
      puts("loading \"testobj5.so\" succeeded, OK");
      if (dlopen("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) == NULL) {
        printf("cannot open \"testobj5.so\": %s\n", dlerror());
        result = 1;
      } else
        puts("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
      if (dlclose(p) != 0) {
        printf("cannot close \"testobj5.so\": %s\n", dlerror());
        result = 1;
      } else
        puts("closing \"testobj5.so\" succeeded, OK");
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <dlopen@plt>
cmp    $0x0,%rax
jne    11b0 <main+0x60>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    11bc <main+0x6c>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    0x2e0c(%rip),%rax
or     (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1060 <dlopen@plt>
cmp    $0x0,%rax
je     11fc <main+0xac>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    12fb <main+0x1ab>
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
call   1060 <dlopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    124e <main+0xfe>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    12f6 <main+0x1a6>
lea    0xe99(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
mov    0x2d6e(%rip),%rax
or     (%rax),%esi
lea    0xddc(%rip),%rdi
call   1060 <dlopen@plt>
cmp    $0x0,%rax
jne    12a4 <main+0x154>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe7f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    12b0 <main+0x160>
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1070 <dlclose@plt>
cmp    $0x0,%rax
je     12e5 <main+0x195>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    12f1 <main+0x1a1>
lea    0xe9a(%rip),%rdi
call   1040 <puts@plt>
jmp    12f6 <main+0x1a6>
jmp    12fb <main+0x1ab>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e81(%rip),%r15
mov    0x2e72(%rip),%r12
mov    (%r12),%esi
or     (%r15),%esi
lea    0xe8c(%rip),%rdi
call   1060 <dlopen@plt>
test   %rax,%rax
je     118e <main+0x3e>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    11a9 <main+0x59>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe70(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    (%r12),%esi
or     (%r15),%esi
lea    0xe98(%rip),%rdi
call   1060 <dlopen@plt>
test   %rax,%rax
je     11d7 <main+0x87>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    128d <main+0x13d>
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
mov    (%r15),%esi
lea    0xe62(%rip),%rdi
call   1060 <dlopen@plt>
test   %rax,%rax
je     122c <main+0xdc>
mov    %rax,%r14
lea    0xeed(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%esi
or     (%r15),%esi
lea    0xe3b(%rip),%rdi
call   1060 <dlopen@plt>
test   %rax,%rax
je     123c <main+0xec>
lea    0xf0c(%rip),%rdi
call   1040 <puts@plt>
jmp    1257 <main+0x107>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe81(%rip),%rdi
jmp    1272 <main+0x122>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xec8(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1070 <dlclose@plt>
test   %rax,%rax
je     1281 <main+0x131>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xef4(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    $0x1,%ebx
jmp    128d <main+0x13d>
lea    0xefe(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"testobj1.so\00"
@RTLD_LAZY = global i32 0
@RTLD_NOLOAD = global i32 0
@.str.1 = [31 x i8] c"cannot open \22testobj1.so\22: %s\0A\00"
@.str.2 = [36 x i8] c"loading \22testobj1.so\22 succeeded, OK\00"
@.str.3 = [12 x i8] c"testobj5.so\00"
@.str.4 = [35 x i8] c"succeeded in loading \22testobj5.so\22\00"
@.str.5 = [61 x i8] c"\22testobj5.so\22 wasn't loaded and RTLD_NOLOAD prevented it, OK\00"
@.str.6 = [51 x i8] c"cannot open \22testobj5.so\22 without RTLD_NOLOAD: %s\0A\00"
@.str.7 = [36 x i8] c"loading \22testobj5.so\22 succeeded, OK\00"
@.str.8 = [31 x i8] c"cannot open \22testobj5.so\22: %s\0A\00"
@.str.9 = [53 x i8] c"loading \22testobj5.so\22 with RTLD_NOLOAD succeeded, OK\00"
@.str.10 = [32 x i8] c"cannot close \22testobj5.so\22: %s\0A\00"
@.str.11 = [36 x i8] c"closing \22testobj5.so\22 succeeded, OK\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
%4 = load i32, i32* @RTLD_LAZY
%5 = load i32, i32* @RTLD_NOLOAD
%6 = or i32 %4, %5
%7 = call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i8* (...) @dlerror()
%11 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %10)
store i32 1, i32* %2
br label %14
12: ; preds = %0
%13 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = load i32, i32* @RTLD_LAZY
%16 = load i32, i32* @RTLD_NOLOAD
%17 = or i32 %15, %16
%18 = call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %55
22: ; preds = %14
%23 = call i32 @puts(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32, i32* @RTLD_LAZY
%25 = call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = bitcast i32* %25 to i8*
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = call i8* (...) @dlerror()
%31 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* %30)
store i32 1, i32* %2
br label %54
32: ; preds = %22
%33 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
%34 = load i32, i32* @RTLD_LAZY
%35 = load i32, i32* @RTLD_NOLOAD
%36 = or i32 %34, %35
%37 = call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = call i8* (...) @dlerror()
%41 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %40)
store i32 1, i32* %2
br label %44
42: ; preds = %32
%43 = call i32 @puts(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
%45 = load i8*, i8** %3
%46 = call i64 @dlclose(i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i8* (...) @dlerror()
%50 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %49)
store i32 1, i32* %2
br label %53
51: ; preds = %44
%52 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
br label %54
54: ; preds = %53, %29
br label %55
55: ; preds = %54, %20
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@.str = [12 x i8] c"testobj1.so\00"
@RTLD_LAZY = global i32 0
@RTLD_NOLOAD = global i32 0
@.str.1 = [31 x i8] c"cannot open \22testobj1.so\22: %s\0A\00"
@.str.2 = [36 x i8] c"loading \22testobj1.so\22 succeeded, OK\00"
@.str.3 = [12 x i8] c"testobj5.so\00"
@.str.4 = [35 x i8] c"succeeded in loading \22testobj5.so\22\00"
@.str.5 = [61 x i8] c"\22testobj5.so\22 wasn't loaded and RTLD_NOLOAD prevented it, OK\00"
@.str.6 = [51 x i8] c"cannot open \22testobj5.so\22 without RTLD_NOLOAD: %s\0A\00"
@.str.7 = [36 x i8] c"loading \22testobj5.so\22 succeeded, OK\00"
@.str.8 = [31 x i8] c"cannot open \22testobj5.so\22: %s\0A\00"
@.str.9 = [53 x i8] c"loading \22testobj5.so\22 with RTLD_NOLOAD succeeded, OK\00"
@.str.10 = [32 x i8] c"cannot close \22testobj5.so\22: %s\0A\00"
@.str.11 = [36 x i8] c"closing \22testobj5.so\22 succeeded, OK\00"
define i32 @main() {
%1 = load i32, i32* @RTLD_LAZY
%2 = load i32, i32* @RTLD_NOLOAD
%3 = or i32 %2, %1
%4 = tail call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i8* (...) @dlerror()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ 1, %6 ], [ 0, %9 ]
%13 = load i32, i32* @RTLD_LAZY
%14 = load i32, i32* @RTLD_NOLOAD
%15 = or i32 %14, %13
%16 = tail call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %50
20: ; preds = %11
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0))
%22 = load i32, i32* @RTLD_LAZY
%23 = tail call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = bitcast i32* %23 to i8*
%25 = icmp eq i32* %23, null
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = tail call i8* (...) @dlerror()
%28 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* %27)
br label %50
29: ; preds = %20
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
%31 = load i32, i32* @RTLD_LAZY
%32 = load i32, i32* @RTLD_NOLOAD
%33 = or i32 %32, %31
%34 = tail call i32* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = tail call i8* (...) @dlerror()
%38 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %37)
br label %41
39: ; preds = %29
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = phi i32 [ 1, %36 ], [ %12, %39 ]
%43 = tail call i64 @dlclose(i8* %24)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = tail call i8* (...) @dlerror()
%47 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %46)
br label %50
48: ; preds = %41
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
br label %50
50: ; preds = %26, %48, %45, %18
%51 = phi i32 [ 1, %18 ], [ 1, %26 ], [ 1, %45 ], [ %42, %48 ]
ret i32 %51
}