#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_DEEPBIND;
int RTLD_LOCAL;
int RTLD_NOW;
char *dlerror();
scalar_t__ dlopen(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write_test_conclusion();
int main() {
  if (dlopen("./libc.so", RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND)) {
    write_test_conclusion();
    return 0;
  } else {
    fprintf(stderr, "%s\n", dlerror());
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2e61(%rip),%rax
or     (%rax),%esi
mov    0x2e80(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1040 <dlopen@plt>
cmp    $0x0,%rax
je     1193 <main+0x53>
mov    $0x0,%al
call   1060 <write_test_conclusion@plt>
movl   $0x0,-0x4(%rbp)
jmp    11bf <main+0x7f>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e98(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e8e(%rip),%rax
or     (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1040 <dlopen@plt>
test   %rax,%rax
je     1178 <main+0x38>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <write_test_conclusion@plt>
jmp    119e <main+0x5e>
mov    0x2e51(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe7b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"./libc.so\00"
@RTLD_NOW = global i32 0
@RTLD_LOCAL = global i32 0
@RTLD_DEEPBIND = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @RTLD_NOW
%3 = load i32, i32* @RTLD_LOCAL
%4 = or i32 %2, %3
%5 = load i32, i32* @RTLD_DEEPBIND
%6 = or i32 %4, %5
%7 = call i64 @dlopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (...) @write_test_conclusion()
store i32 0, i32* %1
br label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i8* (...) @dlerror()
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 1, i32* %1
br label %15
15: ; preds = %11, %9
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [10 x i8] c"./libc.so\00"
@RTLD_NOW = global i32 0
@RTLD_LOCAL = global i32 0
@RTLD_DEEPBIND = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = load i32, i32* @RTLD_NOW
%2 = load i32, i32* @RTLD_LOCAL
%3 = or i32 %2, %1
%4 = load i32, i32* @RTLD_DEEPBIND
%5 = or i32 %3, %4
%6 = tail call i64 @dlopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = tail call i32 (...) @write_test_conclusion()
br label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i8* (...) @dlerror()
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %8
%15 = phi i32 [ 0, %8 ], [ 1, %10 ]
ret i32 %15
}