#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 /*<<< orphan*/ RTLD_LAZY;
void *dlopen(char *, int /*<<< orphan*/);
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "checksym: needs two arguments, library and symbol name\n");
    return 1;
  }
  char *libname = argv[1];
  char *symname = argv[2];
  void *handle = dlopen(libname, RTLD_LAZY);
  if (dlsym(handle, symname))
    return 0;
  return 1;
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    1171 <main+0x41>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <dlsym@plt>
cmp    $0x0,%rax
je     11c2 <main+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <main+0x99>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jg     1152 <main+0x22>
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
lea    0xeba(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbx
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <dlsym@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"checksym: needs two arguments, library and symbol name\0A\00"
@RTLD_LAZY = 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*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %30
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = load i32, i32* @RTLD_LAZY
%23 = call i8* @dlopen(i8* %21, i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i8*, i8** %7
%26 = call i64 @dlsym(i8* %24, i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %14
store i32 0, i32* %3
br label %30
29: ; preds = %14
store i32 1, i32* %3
br label %30
30: ; preds = %29, %28, %11
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"checksym: needs two arguments, library and symbol name\0A\00"
@RTLD_LAZY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = load i32, i32* @RTLD_LAZY
%13 = tail call i8* @dlopen(i8* %9, i32 %12)
%14 = tail call i64 @dlsym(i8* %13, i8* %11)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %7, %4
%18 = phi i32 [ 1, %4 ], [ %16, %7 ]
ret i32 %18
}