#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 */
struct link_map {
  char *l_name;
  struct link_map *l_next;
  scalar_t__ l_addr;
};

/* Variables and functions */
int /*<<< orphan*/ RTLD_LAZY;
int /*<<< orphan*/ dlinfo(int /*<<< orphan*/, int, struct link_map **);
int /*<<< orphan*/ dlopen(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, void *, char *);
scalar_t__ strlen(char *);
void dlinfo_check(void) {
  struct link_map *lm;
  dlinfo(dlopen(NULL, RTLD_LAZY), 2, &lm);
  while (lm != NULL) {
    if (strlen(lm->l_name) > 0)
      printf("%p %s\n", (void *)lm->l_addr, lm->l_name);
    lm = lm->l_next;
  }
}


x86 assembly (clang, -O0):
<dlinfo_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <dlopen@plt>
mov    %eax,%edi
mov    $0x2,%esi
lea    -0x8(%rbp),%rdx
call   1030 <dlinfo@plt>
cmpq   $0x0,-0x8(%rbp)
je     11b7 <dlinfo_check+0x77>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11a6 <dlinfo_check+0x66>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    116a <dlinfo_check+0x2a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlinfo_check>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1060 <dlopen@plt>
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    $0x2,%esi
call   1030 <dlinfo@plt>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11b4 <dlinfo_check+0x74>
lea    0xe85(%rip),%r14
jmp    118e <dlinfo_check+0x4e>
nopl   (%rax)
mov    0x8(%rbx),%rbx
mov    %rbx,0x8(%rsp)
test   %rbx,%rbx
je     11b4 <dlinfo_check+0x74>
mov    (%rbx),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    1180 <dlinfo_check+0x40>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1050 <printf@plt>
mov    0x8(%rsp),%rbx
jmp    1180 <dlinfo_check+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.link_map = type { i8*, %struct.link_map*, i64 }
@RTLD_LAZY = global i32 0
@.str = [7 x i8] c"%p %s\0A\00"
define void @dlinfo_check() {
%1 = alloca %struct.link_map*
%2 = load i32, i32* @RTLD_LAZY
%3 = call i32 @dlopen(i32* null, i32 %2)
%4 = call i32 @dlinfo(i32 %3, i32 2, %struct.link_map** %1)
br label %5
5: ; preds = %23, %0
%6 = load %struct.link_map*, %struct.link_map** %1
%7 = icmp ne %struct.link_map* %6, null
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load %struct.link_map*, %struct.link_map** %1
%10 = getelementptr inbounds %struct.link_map, %struct.link_map* %9, i32 0, i32 0
%11 = load i8*, i8** %10
%12 = call i64 @strlen(i8* %11)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %8
%15 = load %struct.link_map*, %struct.link_map** %1
%16 = getelementptr inbounds %struct.link_map, %struct.link_map* %15, i32 0, i32 2
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i8*
%19 = load %struct.link_map*, %struct.link_map** %1
%20 = getelementptr inbounds %struct.link_map, %struct.link_map* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %21)
br label %23
23: ; preds = %14, %8
%24 = load %struct.link_map*, %struct.link_map** %1
%25 = getelementptr inbounds %struct.link_map, %struct.link_map* %24, i32 0, i32 1
%26 = load %struct.link_map*, %struct.link_map** %25
store %struct.link_map* %26, %struct.link_map** %1
br label %5
27: ; preds = %5
ret void
}

LLVM IR (-O2):
%struct.link_map = type { i8*, %struct.link_map*, i64 }
@RTLD_LAZY = global i32 0
@.str = [7 x i8] c"%p %s\0A\00"
define void @dlinfo_check() {
%1 = alloca %struct.link_map*
%2 = bitcast %struct.link_map** %1 to i8*
%3 = load i32, i32* @RTLD_LAZY
%4 = tail call i32 @dlopen(i32* null, i32 %3)
%5 = call i32 @dlinfo(i32 %4, i32 2, %struct.link_map** %1)
%6 = load %struct.link_map*, %struct.link_map** %1
%7 = icmp eq %struct.link_map* %6, null
br i1 %7, label %25, label %8
8: ; preds = %0, %20
%9 = phi %struct.link_map* [ %23, %20 ], [ %6, %0 ]
%10 = getelementptr inbounds %struct.link_map, %struct.link_map* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = call i64 @strlen(i8* dereferenceable(1) %11)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = getelementptr inbounds %struct.link_map, %struct.link_map* %9, i64 0, i32 2
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to i8*
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %11)
%19 = load %struct.link_map*, %struct.link_map** %1
br label %20
20: ; preds = %14, %8
%21 = phi %struct.link_map* [ %19, %14 ], [ %9, %8 ]
%22 = getelementptr inbounds %struct.link_map, %struct.link_map* %21, i64 0, i32 1
%23 = load %struct.link_map*, %struct.link_map** %22
store %struct.link_map* %23, %struct.link_map** %1
%24 = icmp eq %struct.link_map* %23, null
br i1 %24, label %25, label %8
25: ; preds = %20, %0
ret void
}