#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 EXIT_SUCCESS;
int /*<<< orphan*/ FAIL(char *, char const *);
int /*<<< orphan*/ PASS(char *);
int /*<<< orphan*/ RTLD_GLOBAL;
int /*<<< orphan*/ RTLD_NOW;
void *dlopen(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int main(int argc, const char *argv[]) {
  void *handle = dlopen(argv[1], RTLD_GLOBAL);
  if (handle == NULL) {
    FAIL("dlopen(\"%s\") failed", argv[1]);
    exit(1);
  }
  void *handle2 = dlopen(argv[2], RTLD_NOW);
  if (handle2 == NULL) {
    FAIL("dlopen(\"%s\") failed", argv[2]);
    exit(1);
  }
  PASS("dlopen-RTLD_GLOBAL");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1199 <main+0x59>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe76(%rip),%rdi
call   1060 <FAIL@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11dc <main+0x9c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe33(%rip),%rdi
call   1060 <FAIL@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe31(%rip),%rdi
call   1040 <PASS@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
test   %rax,%rax
je     1189 <main+0x49>
mov    0x10(%rbx),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
test   %rax,%rax
je     118f <main+0x4f>
lea    0xe9b(%rip),%rdi
call   1040 <PASS@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x8(%rbx),%rsi
jmp    1193 <main+0x53>
mov    0x10(%rbx),%rsi
lea    0xe66(%rip),%rdi
call   1060 <FAIL@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@RTLD_GLOBAL = global i32 0
@.str = [20 x i8] c"dlopen(\22%s\22) failed\00"
@RTLD_NOW = global i32 0
@.str.1 = [19 x i8] c"dlopen-RTLD_GLOBAL\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @RTLD_GLOBAL
%12 = call i8* @dlopen(i8* %10, i32 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @FAIL(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @RTLD_NOW
%26 = call i8* @dlopen(i8* %24, i32 %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %21
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @FAIL(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %21
%36 = call i32 @PASS(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}

LLVM IR (-O2):
@RTLD_GLOBAL = global i32 0
@.str = [20 x i8] c"dlopen(\22%s\22) failed\00"
@RTLD_NOW = global i32 0
@.str.1 = [19 x i8] c"dlopen-RTLD_GLOBAL\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @RTLD_GLOBAL
%6 = tail call i8* @dlopen(i8* %4, i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = tail call i32 @FAIL(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = load i32, i32* @RTLD_NOW
%16 = tail call i8* @dlopen(i8* %14, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i8*, i8** %13
%20 = tail call i32 @FAIL(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %12
%23 = tail call i32 @PASS(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}