#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_LOCAL;
int /*<<< orphan*/ RTLD_NOW;
int /*<<< orphan*/ XFAIL(char *, char const *, char const *);
char *dlerror();
void *dlopen(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ *strstr(char const *, char *);
int main(int argc, const char *argv[]) {
  void *handle = dlopen(argv[1], RTLD_LOCAL);
  if (handle == NULL) {
    const char *msg = dlerror();
    if (strstr(msg, "RTLD_LOCAL") != NULL)
      XFAIL("dlopen(\"%s\", RTLD_LOCAL) failed: %s", argv[1], msg);
    else
      FAIL("dlopen(\"%s\", RTLD_LOCAL) failed: %s", argv[1], msg);
    return EXIT_SUCCESS;
  }
  void *handle2 = dlopen(argv[2], RTLD_NOW);
  if (handle2 != NULL) {
    FAIL("dlopen(\"%s\") succeeded but foo should have been not found",
         argv[2]);
    return EXIT_SUCCESS;
  }
  const char *msg = dlerror();
  if (strstr(msg, "foo") == NULL) {
    FAIL("dlopen(\"%s\") correctly failed, but foo was not in error mesage: %s",
         argv[2], msg);
    return EXIT_SUCCESS;
  }
  PASS("dlopen-RTLD_LOCAL");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1208 <main+0xa8>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xefb(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     11dd <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe2d(%rip),%rdi
call   1060 <XFAIL@plt>
jmp    11f7 <main+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1070 <FAIL@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12bc <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1254 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1070 <FAIL@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12bc <main+0x15c>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
jne    12a4 <main+0x144>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <FAIL@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12bc <main+0x15c>
lea    0xdfa(%rip),%rdi
call   1050 <PASS@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
test   %rax,%rax
je     11a9 <main+0x49>
mov    0x10(%rbx),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
test   %rax,%rax
je     11dc <main+0x7c>
mov    0x10(%rbx),%rsi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1070 <FAIL@plt>
jmp    121d <main+0xbd>
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %rax,%r14
lea    0xef2(%rip),%rsi
mov    %rax,%rdi
call   1080 <strstr@plt>
mov    0x8(%rbx),%rsi
lea    0xe33(%rip),%rdi
test   %rax,%rax
je     1213 <main+0xb3>
mov    %r14,%rdx
call   1060 <XFAIL@plt>
jmp    121d <main+0xbd>
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %rax,%r14
lea    0xe71(%rip),%rsi
mov    %rax,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     1208 <main+0xa8>
lea    0xea4(%rip),%rdi
call   1050 <PASS@plt>
jmp    121d <main+0xbd>
mov    0x10(%rbx),%rsi
lea    0xe4f(%rip),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <FAIL@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RTLD_LOCAL = global i32 0
@.str = [11 x i8] c"RTLD_LOCAL\00"
@.str.1 = [36 x i8] c"dlopen(\22%s\22, RTLD_LOCAL) failed: %s\00"
@EXIT_SUCCESS = global i32 0
@RTLD_NOW = global i32 0
@.str.2 = [58 x i8] c"dlopen(\22%s\22) succeeded but foo should have been not found\00"
@.str.3 = [4 x i8] c"foo\00"
@.str.4 = [67 x i8] c"dlopen(\22%s\22) correctly failed, but foo was not in error mesage: %s\00"
@.str.5 = [18 x i8] c"dlopen-RTLD_LOCAL\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @RTLD_LOCAL
%14 = call i8* @dlopen(i8* %12, i32 %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %36
17: ; preds = %2
%18 = call i8* (...) @dlerror()
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = call i32* @strstr(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8*, i8** %7
%27 = call i32 @XFAIL(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %26)
br label %34
28: ; preds = %17
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i8*, i8** %7
%33 = call i32 (i8*, i8*, ...) @FAIL(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32)
br label %34
34: ; preds = %28, %22
%35 = load i32, i32* @EXIT_SUCCESS
store i32 %35, i32* %3
br label %65
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = load i32, i32* @RTLD_NOW
%41 = call i8* @dlopen(i8* %39, i32 %40)
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %50
44: ; preds = %36
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 (i8*, i8*, ...) @FAIL(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_SUCCESS
store i32 %49, i32* %3
br label %65
50: ; preds = %36
%51 = call i8* (...) @dlerror()
store i8* %51, i8** %9
%52 = load i8*, i8** %9
%53 = call i32* @strstr(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %62
55: ; preds = %50
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = load i8*, i8** %9
%60 = call i32 (i8*, i8*, ...) @FAIL(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i8* %58, i8* %59)
%61 = load i32, i32* @EXIT_SUCCESS
store i32 %61, i32* %3
br label %65
62: ; preds = %50
%63 = call i32 @PASS(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* @EXIT_SUCCESS
store i32 %64, i32* %3
br label %65
65: ; preds = %62, %55, %44, %34
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@RTLD_LOCAL = global i32 0
@.str = [11 x i8] c"RTLD_LOCAL\00"
@.str.1 = [36 x i8] c"dlopen(\22%s\22, RTLD_LOCAL) failed: %s\00"
@EXIT_SUCCESS = global i32 0
@RTLD_NOW = global i32 0
@.str.2 = [58 x i8] c"dlopen(\22%s\22) succeeded but foo should have been not found\00"
@.str.3 = [4 x i8] c"foo\00"
@.str.4 = [67 x i8] c"dlopen(\22%s\22) correctly failed, but foo was not in error mesage: %s\00"
@.str.5 = [18 x i8] c"dlopen-RTLD_LOCAL\00"
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_LOCAL
%6 = tail call i8* @dlopen(i8* %4, i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = tail call i8* (...) @dlerror()
%10 = tail call i32* @strstr(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
%12 = load i8*, i8** %3
br i1 %11, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @XFAIL(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %9)
br label %35
15: ; preds = %8
%16 = tail call i32 (i8*, i8*, ...) @FAIL(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %9)
br label %35
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = load i32, i32* @RTLD_NOW
%21 = tail call i8* @dlopen(i8* %19, i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = load i8*, i8** %18
%25 = tail call i32 (i8*, i8*, ...) @FAIL(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %35
26: ; preds = %17
%27 = tail call i8* (...) @dlerror()
%28 = tail call i32* @strstr(i8* dereferenceable(1) %27, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %18
%32 = tail call i32 (i8*, i8*, ...) @FAIL(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i8* %31, i8* %27)
br label %35
33: ; preds = %26
%34 = tail call i32 @PASS(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %23, %33, %30, %13, %15
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}