#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_LOCAL;
int RTLD_NOW;
int /*<<< orphan*/ dlclose(void *);
void *dlopen(char *, int);
int /*<<< orphan*/ *dlsym(void *, char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  void *handle = dlopen("libxcb.so.1", RTLD_NOW | RTLD_LOCAL);
  if (handle == NULL) {
    printf("Could not find libxcb\n");
    return -1;
  }
  if (dlsym(handle, "xcb_discard_reply64") == NULL) {
    printf("No xcb_discard_reply64 in libxcb\n");
    return -2;
  }
  printf("libxcb is recent enough. We can use it\n");
  dlclose(handle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
or     (%rax),%esi
lea    0xe98(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <main+0x54>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <main+0xa2>
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1050 <dlsym@plt>
cmp    $0x0,%rax
jne    11c6 <main+0x86>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11e2 <main+0xa2>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <dlclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea6(%rip),%rdi
call   1040 <dlopen@plt>
test   %rax,%rax
je     1193 <main+0x53>
mov    %rax,%rbx
lea    0xe9e(%rip),%rsi
mov    %rax,%rdi
call   1050 <dlsym@plt>
test   %rax,%rax
je     11a6 <main+0x66>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <dlclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"libxcb.so.1\00"
@RTLD_NOW = global i32 0
@RTLD_LOCAL = global i32 0
@.str.1 = [23 x i8] c"Could not find libxcb\0A\00"
@.str.2 = [20 x i8] c"xcb_discard_reply64\00"
@.str.3 = [34 x i8] c"No xcb_discard_reply64 in libxcb\0A\00"
@.str.4 = [40 x i8] c"libxcb is recent enough. We can use it\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = load i32, i32* @RTLD_NOW
%4 = load i32, i32* @RTLD_LOCAL
%5 = or i32 %3, %4
%6 = call i8* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %21
11: ; preds = %0
%12 = load i8*, i8** %2
%13 = call i32* @dlsym(i8* %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %1
br label %21
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = call i32 @dlclose(i8* %19)
store i32 0, i32* %1
br label %21
21: ; preds = %17, %15, %9
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [12 x i8] c"libxcb.so.1\00"
@RTLD_NOW = global i32 0
@RTLD_LOCAL = global i32 0
@.str.2 = [20 x i8] c"xcb_discard_reply64\00"
@str = [39 x i8] c"libxcb is recent enough. We can use it\00"
@str.5 = [33 x i8] c"No xcb_discard_reply64 in libxcb\00"
@str.6 = [22 x i8] c"Could not find libxcb\00"
define i32 @main() {
%1 = load i32, i32* @RTLD_NOW
%2 = load i32, i32* @RTLD_LOCAL
%3 = or i32 %2, %1
%4 = tail call i8* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
br label %16
8: ; preds = %0
%9 = tail call i32* @dlsym(i8* %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0))
br label %16
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @dlclose(i8* %4)
br label %16
16: ; preds = %13, %11, %6
%17 = phi i32 [ -1, %6 ], [ -2, %11 ], [ 0, %13 ]
ret i32 %17
}