#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 *, ...);
int /*<<< orphan*/ stderr;
int look_for_symbol(void *handle, char *symbol) {
  void *symbol_ptr = NULL;
  char *error = NULL;
  fprintf(stderr, "extrae-loader: Looking for '%s'... ", symbol);
  symbol_ptr = dlsym(handle, symbol);
  if ((error = dlerror()) != NULL) {
    fprintf(stderr, "no (%s)\n", error);
    return 0;
  } else {
    fprintf(stderr, "yes\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<look_for_symbol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe9c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11b8 <look_for_symbol+0x88>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <look_for_symbol+0xa6>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<look_for_symbol>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x2e9c(%rip),%r15
mov    (%r15),%edi
lea    0xeb2(%rip),%rsi
xor    %r14d,%r14d
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <dlsym@plt>
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    (%r15),%edi
test   %rax,%rax
je     1188 <look_for_symbol+0x58>
lea    0xea8(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    119c <look_for_symbol+0x6c>
lea    0xe9e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"extrae-loader: Looking for '%s'... \00"
@.str.1 = [9 x i8] c"no (%s)\0A\00"
@.str.2 = [5 x i8] c"yes\0A\00"
define i32 @look_for_symbol(i8* %0, i8* %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = tail call i8* @dlsym(i8* %0, i8* %1)
%6 = tail call i8* (...) @dlerror()
%7 = icmp eq i8* %6, null
%8 = load i32, i32* @stderr
br i1 %7, label %11, label %9
9: ; preds = %2
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %13
11: ; preds = %2
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ 0, %9 ], [ 1, %11 ]
ret i32 %14
}