#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 RTLD_GLOBAL;
int RTLD_LAZY;
int /*<<< orphan*/ dlopen(char *, int);
int /*<<< orphan*/ do_test(int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  dlopen("./lib.so", RTLD_LAZY | RTLD_GLOBAL);
  int i = 0;
  for (i = 0; i < 100; i++) {
    do_test(i);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    0x2e92(%rip),%rax
or     (%rax),%esi
lea    0xea1(%rip),%rdi
call   1030 <dlopen@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    119c <main+0x6c>
mov    -0x14(%rbp),%edi
call   1040 <do_test@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <main+0x42>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb6(%rip),%rdi
call   1030 <dlopen@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <do_test@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
add    $0x1,%ebx
cmp    $0x64,%ebx
jne    1160 <main+0x30>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"./lib.so\00"
@RTLD_LAZY = global i32 0
@RTLD_GLOBAL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @RTLD_LAZY
%8 = load i32, i32* @RTLD_GLOBAL
%9 = or i32 %7, %8
%10 = call i32 @dlopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 0, i32* %6
store i32 0, i32* %6
br label %11
11: ; preds = %18, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 100
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %6
%16 = call i32 @do_test(i32 %15)
%17 = call i32 @sleep(i32 1)
br label %18
18: ; preds = %14
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %11
21: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"./lib.so\00"
@RTLD_LAZY = global i32 0
@RTLD_GLOBAL = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @RTLD_LAZY
%4 = load i32, i32* @RTLD_GLOBAL
%5 = or i32 %4, %3
%6 = tail call i32 @dlopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %11, %7 ]
%9 = tail call i32 @do_test(i32 %8)
%10 = tail call i32 @sleep(i32 1)
%11 = add nuw nsw i32 %8, 1
%12 = icmp eq i32 %11, 100
br i1 %12, label %13, label %7
13: ; preds = %7
ret i32 0
}