#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int RTLD_GLOBAL;
int RTLD_NOW;
char *dlerror();
void *dlopen(char const *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, const char *argv[]) {
  int i = 0;
  void *ptr = NULL;
  if (argc < 2) {
    fprintf(stderr, "specify a library\n");
    return EXIT_FAILURE;
  }
  for (i = 1; i < argc; ++i) {
    ptr = dlopen(argv[i], RTLD_NOW | RTLD_GLOBAL);
    if (!ptr) {
      fprintf(stderr, "%s\n", dlerror());
      continue;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1187 <main+0x57>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <main+0xe7>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120b <main+0xdb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    0x2e32(%rip),%rax
or     (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f8 <main+0xc8>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11fd <main+0xcd>
jmp    11fd <main+0xcd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118e <main+0x5e>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jge    1160 <main+0x30>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xeb0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e6a(%rip),%rax
jmp    11ca <main+0x9a>
mov    %rsi,%r15
mov    %edi,%r13d
mov    $0x1,%ebx
mov    0x2e6e(%rip),%r12
mov    0x2e6f(%rip),%r14
jmp    1189 <main+0x59>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     11c3 <main+0x93>
mov    (%r15,%rbx,8),%rdi
mov    (%r14),%esi
or     (%r12),%esi
call   1040 <dlopen@plt>
test   %rax,%rax
jne    1180 <main+0x50>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %ebp,%edi
lea    0xe5c(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1180 <main+0x50>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"specify a library\0A\00"
@EXIT_FAILURE = global i32 0
@RTLD_NOW = global i32 0
@RTLD_GLOBAL = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %41
14: ; preds = %2
store i32 1, i32* %6
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = load i32, i32* @RTLD_NOW
%26 = load i32, i32* @RTLD_GLOBAL
%27 = or i32 %25, %26
%28 = call i8* @dlopen(i8* %24, i32 %27)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %35, label %31
31: ; preds = %19
%32 = load i32, i32* @stderr
%33 = call i8* (...) @dlerror()
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %36
35: ; preds = %19
br label %36
36: ; preds = %35, %31
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %15
39: ; preds = %15
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %3
br label %41
41: ; preds = %39, %10
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"specify a library\0A\00"
@EXIT_FAILURE = global i32 0
@RTLD_NOW = global i32 0
@RTLD_GLOBAL = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %25
9: ; preds = %4, %22
%10 = phi i64 [ 1, %4 ], [ %23, %22 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = load i32, i32* @RTLD_NOW
%14 = load i32, i32* @RTLD_GLOBAL
%15 = or i32 %14, %13
%16 = tail call i8* @dlopen(i8* %12, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %9
%19 = load i32, i32* @stderr
%20 = tail call i8* (...) @dlerror()
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %9, %18
%23 = add nuw nsw i64 %10, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %9
25: ; preds = %22, %6
%26 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_SUCCESS, %22 ]
%27 = load i32, i32* %26
ret i32 %27
}