#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 /*<<< orphan*/ RTLD_NOW;
int /*<<< orphan*/ dlclose(void *);
char *dlerror();
void *dlopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i;
  for (i = 1; i < argc; ++i) {
    void *handle = dlopen(argv[i], RTLD_NOW);
    if (!handle) {
      fprintf(stderr, "%s", dlerror());
      return 1;
    } else {
      dlclose(handle);
    }
  }
  return 0;
}


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   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11df <main+0x9f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c3 <main+0x83>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <main+0xa6>
mov    -0x20(%rbp),%rdi
call   1060 <dlclose@plt>
jmp    11d1 <main+0x91>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
cmp    $0x2,%edi
jl     11bc <main+0x7c>
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1,%ebx
mov    0x2e87(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    (%r12),%esi
call   1040 <dlopen@plt>
test   %rax,%rax
je     1195 <main+0x55>
mov    %rax,%rdi
call   1060 <dlclose@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <main+0x30>
jmp    11bc <main+0x7c>
mov    0x2e3c(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe54(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RTLD_NOW = global i32 0
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
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 1, i32* %6
br label %8
8: ; preds = %30, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = load i32, i32* @RTLD_NOW
%19 = call i8* @dlopen(i8* %17, i32 %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %12
%23 = load i32, i32* @stderr
%24 = call i8* (...) @dlerror()
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %34
26: ; preds = %12
%27 = load i8*, i8** %7
%28 = call i32 @dlclose(i8* %27)
br label %29
29: ; preds = %26
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %8
33: ; preds = %8
store i32 0, i32* %3
br label %34
34: ; preds = %33, %22
%35 = load i32, i32* %3
ret i32 %35
}

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