#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  char *name;
};
typedef TYPE_1__ lt_dlinfo;
typedef int /*<<< orphan*/ lt_dlhandle;

/* Variables and functions */
TYPE_1__ *lt_dlgetinfo(int /*<<< orphan*/);
void *lt_dlsym(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
void *my_dlsym(lt_dlhandle handle, const char *name) {
  void *ptr;
  char newname[1024];
  const lt_dlinfo *info;
  info = lt_dlgetinfo(handle);
  snprintf(newname, 1024, "%s_%s", info->name, name);
  if ((ptr = lt_dlsym(handle, newname))) {
    printf("                         %s\n", newname);
    return (ptr);
  };
  snprintf(newname, 1024, "%s_LTX_%s", info->name, name);
  if ((ptr = lt_dlsym(handle, newname))) {
    printf("                         %s\n", newname);
    return (ptr);
  };
  if ((ptr = lt_dlsym(handle, name))) {
    printf("                         %s\n", name);
    return (ptr);
  };
  return (NULL);
}


x86 assembly (clang, -O0):
<my_dlsym>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <lt_dlgetinfo@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%r8
mov    $0x400,%esi
lea    0xe7e(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
call   1060 <lt_dlsym@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c4 <my_dlsym+0x84>
lea    -0x420(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1266 <my_dlsym+0x126>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%r8
mov    $0x400,%esi
lea    0xe3e(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
call   1060 <lt_dlsym@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1227 <my_dlsym+0xe7>
lea    -0x420(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1266 <my_dlsym+0x126>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <lt_dlsym@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     125e <my_dlsym+0x11e>
mov    -0x18(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1266 <my_dlsym+0x126>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_dlsym>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
call   1050 <lt_dlgetinfo@plt>
mov    %rax,%rbp
mov    (%rax),%rcx
lea    0xe9b(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1060 <lt_dlsym@plt>
test   %rax,%rax
jne    11b6 <my_dlsym+0x76>
mov    0x0(%rbp),%rcx
lea    0xe90(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1060 <lt_dlsym@plt>
test   %rax,%rax
je     11d9 <my_dlsym+0x99>
mov    %rax,%rbx
lea    0xe46(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%edi
mov    %r14,%rsi
call   1060 <lt_dlsym@plt>
test   %rax,%rax
je     11f8 <my_dlsym+0xb8>
mov    %rax,%rbx
lea    0xe13(%rip),%rdi
mov    %r14,%rsi
jmp    11c3 <my_dlsym+0x83>
xor    %ebx,%ebx
jmp    11c8 <my_dlsym+0x88>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i8* }
@.str = [6 x i8] c"%s_%s\00"
@.str.1 = [29 x i8] c" %s\0A\00"
@.str.2 = [10 x i8] c"%s_LTX_%s\00"
define i8* @my_dlsym(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca %struct.TYPE_3__*
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i32, i32* %4
%10 = call %struct.TYPE_3__* @lt_dlgetinfo(i32 %9)
store %struct.TYPE_3__* %10, %struct.TYPE_3__** %8
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = load %struct.TYPE_3__*, %struct.TYPE_3__** %8
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %12, i32 0, i32 0
%14 = load i8*, i8** %13
%15 = load i8*, i8** %5
%16 = call i32 @snprintf(i8* %11, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = load i32, i32* %4
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = call i8* @lt_dlsym(i32 %17, i8* %18)
store i8* %19, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %6
store i8* %24, i8** %3
br label %50
25: ; preds = %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = load %struct.TYPE_3__*, %struct.TYPE_3__** %8
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = load i8*, i8** %5
%31 = call i32 @snprintf(i8* %26, i32 1024, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %30)
%32 = load i32, i32* %4
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = call i8* @lt_dlsym(i32 %32, i8* %33)
store i8* %34, i8** %6
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %40
36: ; preds = %25
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %6
store i8* %39, i8** %3
br label %50
40: ; preds = %25
%41 = load i32, i32* %4
%42 = load i8*, i8** %5
%43 = call i8* @lt_dlsym(i32 %41, i8* %42)
store i8* %43, i8** %6
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %6
store i8* %48, i8** %3
br label %50
49: ; preds = %40
store i8* null, i8** %3
br label %50
50: ; preds = %49, %45, %36, %21
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i8* }
@.str = [6 x i8] c"%s_%s\00"
@.str.1 = [29 x i8] c" %s\0A\00"
@.str.2 = [10 x i8] c"%s_LTX_%s\00"
define i8* @my_dlsym(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call %struct.TYPE_3__* @lt_dlgetinfo(i32 %0)
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %1)
%9 = call i8* @lt_dlsym(i32 %0, i8* %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %25
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %14, i8* %1)
%16 = call i8* @lt_dlsym(i32 %0, i8* %4)
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %25
20: ; preds = %13
%21 = call i8* @lt_dlsym(i32 %0, i8* %1)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %25
25: ; preds = %20, %23, %18, %11
%26 = phi i8* [ %9, %11 ], [ %16, %18 ], [ %21, %23 ], [ null, %20 ]
ret i8* %26
}