#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 */
char *dlerror();
void *dlsym(void *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int libgps_load_sym(void **func, void *handle, char *symbol) {
  char *sym_error;
  *func = dlsym(handle, symbol);
  if ((sym_error = dlerror()) != NULL) {
    fprintf(stderr, "%s\n", sym_error);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<libgps_load_sym>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <dlsym@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1195 <libgps_load_sym+0x65>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <libgps_load_sym+0x6c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libgps_load_sym>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1050 <dlsym@plt>
mov    %rax,(%rbx)
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
je     116d <libgps_load_sym+0x3d>
mov    0x2e89(%rip),%rcx
mov    (%rcx),%edi
lea    0xea0(%rip),%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @libgps_load_sym(i8** %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = load i8*, i8** %7
%11 = call i8* @dlsym(i8* %9, i8* %10)
%12 = load i8**, i8*** %5
store i8* %11, i8** %12
%13 = call i8* (...) @dlerror()
store i8* %13, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %8
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %4
br label %20
19: ; preds = %3
store i32 0, i32* %4
br label %20
20: ; preds = %19, %15
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @libgps_load_sym(i8** nocapture writeonly %0, i8* %1, i8* %2) {
%4 = tail call i8* @dlsym(i8* %1, i8* %2)
store i8* %4, i8** %0
%5 = tail call i8* (...) @dlerror()
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %10
10: ; preds = %3, %7
%11 = phi i32 [ -1, %7 ], [ 0, %3 ]
ret i32 %11
}