#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*/ EXIT_FAILURE;
char *dlerror();
void *dlsym(void *, char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
void *dlsym_fail_on_error(void *handle, const char *symbol) {
  const char *err;
  void *symbol_handle = dlsym(handle, symbol);
  if (!symbol_handle || NULL != (err = dlerror())) {
    fprintf(stderr, "[libfakefile] unable to get \"%s\"-handle: %s\n", symbol,
            err);
    exit(EXIT_FAILURE);
  }
  return symbol_handle;
}


x86 assembly (clang, -O0):
<dlsym_fail_on_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1185 <dlsym_fail_on_error+0x45>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11b0 <dlsym_fail_on_error+0x70>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlsym_fail_on_error>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1050 <dlsym@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
jne    1166 <dlsym_fail_on_error+0x26>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e73(%rip),%rcx
mov    (%rcx),%edi
lea    0xe8a(%rip),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"[libfakefile] unable to get \22%s\22-handle: %s\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @dlsym_fail_on_error(i8* %0, i8* %1) {
%3 = tail call i8* @dlsym(i8* %0, i8* %1)
%4 = icmp ne i8* %3, null
tail call void @llvm.assume(i1 %4)
%5 = tail call i8* (...) @dlerror()
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %5)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
ret i8* %3
}