#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*/ sprintf_neural_err(char *, char *, char *);
int _get_net_fn(void *net, char *fn_name, void **fn_ptr) {
  char *error;
  dlerror();
  *fn_ptr = dlsym(net, fn_name);
  error = dlerror();
  if (error) {
    sprintf_neural_err("Error resolving %s(): %s", fn_name, error);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_get_net_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <dlsym@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1198 <_get_net_fn+0x68>
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe79(%rip),%rdi
call   1040 <sprintf_neural_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <_get_net_fn+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_net_fn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <dlsym@plt>
mov    %rax,(%r15)
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
je     117a <_get_net_fn+0x4a>
lea    0xe96(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <sprintf_neural_err@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Error resolving %s(): %s\00"
define i32 @_get_net_fn(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 = call i8* (...) @dlerror()
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = call i8* @dlsym(i8* %10, i8* %11)
%13 = load i8**, i8*** %7
store i8* %12, i8** %13
%14 = call i8* (...) @dlerror()
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = load i8*, i8** %8
%20 = call i32 @sprintf_neural_err(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
store i32 -1, i32* %4
br label %22
21: ; preds = %3
store i32 0, i32* %4
br label %22
22: ; preds = %21, %17
%23 = load i32, i32* %4
ret i32 %23
}

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