#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_NOW;
scalar_t__ dlclose(void *);
char *dlerror();
void *dlopen(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  int i;
  void *h1, *h2;
  mtrace();
  for (i = 0; i < 3; i++) {
    h1 = dlopen("reldep4mod1.so", RTLD_NOW | RTLD_GLOBAL);
    if (h1 == NULL) {
      printf("cannot open reldep4mod1.so: %s\n", dlerror());
      exit(1);
    }
    h2 = dlopen("reldep4mod2.so", RTLD_NOW | RTLD_GLOBAL);
    if (h2 == NULL) {
      printf("cannot open reldep4mod2.so: %s\n", dlerror());
      exit(1);
    }
    if (dlclose(h1) != 0) {
      printf("closing h1 failed: %s\n", dlerror());
      exit(1);
    }
    if (dlclose(h2) != 0) {
      printf("closing h2 failed: %s\n", dlerror());
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <mtrace@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    129a <main+0x13a>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e51(%rip),%rax
or     (%rax),%esi
lea    0xe60(%rip),%rdi
call   1050 <dlopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d4 <main+0x74>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    0x2e04(%rip),%rax
or     (%rax),%esi
lea    0xe42(%rip),%rdi
call   1050 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1221 <main+0xc1>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1080 <dlclose@plt>
cmp    $0x0,%rax
je     1254 <main+0xf4>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1080 <dlclose@plt>
cmp    $0x0,%rax
je     1287 <main+0x127>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    128c <main+0x12c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <mtrace@plt>
mov    0x2e6a(%rip),%r15
mov    0x2e6b(%rip),%r12
mov    (%r12),%esi
or     (%r15),%esi
lea    0xe75(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     129b <main+0x13b>
mov    %rax,%r14
mov    (%r12),%esi
or     (%r15),%esi
lea    0xe85(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     12ab <main+0x14b>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <dlclose@plt>
test   %rax,%rax
jne    12bb <main+0x15b>
mov    %rbx,%rdi
call   1080 <dlclose@plt>
test   %rax,%rax
jne    12cb <main+0x16b>
mov    (%r12),%esi
or     (%r15),%esi
lea    0xe15(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     129b <main+0x13b>
mov    %rax,%r14
mov    (%r12),%esi
or     (%r15),%esi
lea    0xe25(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     12ab <main+0x14b>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <dlclose@plt>
test   %rax,%rax
jne    12bb <main+0x15b>
mov    %rbx,%rdi
call   1080 <dlclose@plt>
test   %rax,%rax
jne    12cb <main+0x16b>
mov    (%r12),%esi
or     (%r15),%esi
lea    0xdb5(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     129b <main+0x13b>
mov    %rax,%r14
mov    (%r12),%esi
or     (%r15),%esi
lea    0xdc9(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     12ab <main+0x14b>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <dlclose@plt>
test   %rax,%rax
jne    12bb <main+0x15b>
mov    %rbx,%rdi
call   1080 <dlclose@plt>
test   %rax,%rax
jne    12cb <main+0x16b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xd66(%rip),%rdi
jmp    12d9 <main+0x179>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xd85(%rip),%rdi
jmp    12d9 <main+0x179>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xd95(%rip),%rdi
jmp    12d9 <main+0x179>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xd9c(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"reldep4mod1.so\00"
@RTLD_NOW = global i32 0
@RTLD_GLOBAL = global i32 0
@.str.1 = [32 x i8] c"cannot open reldep4mod1.so: %s\0A\00"
@.str.2 = [15 x i8] c"reldep4mod2.so\00"
@.str.3 = [32 x i8] c"cannot open reldep4mod2.so: %s\0A\00"
@.str.4 = [23 x i8] c"closing h1 failed: %s\0A\00"
@.str.5 = [23 x i8] c"closing h2 failed: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 (...) @mtrace()
store i32 0, i32* %2
br label %6
6: ; preds = %48, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %51
9: ; preds = %6
%10 = load i32, i32* @RTLD_NOW
%11 = load i32, i32* @RTLD_GLOBAL
%12 = or i32 %10, %11
%13 = call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = call i8* (...) @dlerror()
%18 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %9
%21 = load i32, i32* @RTLD_NOW
%22 = load i32, i32* @RTLD_GLOBAL
%23 = or i32 %21, %22
%24 = call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = call i8* (...) @dlerror()
%29 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %20
%32 = load i8*, i8** %3
%33 = call i64 @dlclose(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = call i8* (...) @dlerror()
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i8*, i8** %4
%41 = call i64 @dlclose(i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = call i8* (...) @dlerror()
%45 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
br label %48
48: ; preds = %47
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
br label %6
51: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"reldep4mod1.so\00"
@RTLD_NOW = global i32 0
@RTLD_GLOBAL = global i32 0
@.str.1 = [32 x i8] c"cannot open reldep4mod1.so: %s\0A\00"
@.str.2 = [15 x i8] c"reldep4mod2.so\00"
@.str.3 = [32 x i8] c"cannot open reldep4mod2.so: %s\0A\00"
@.str.4 = [23 x i8] c"closing h1 failed: %s\0A\00"
@.str.5 = [23 x i8] c"closing h2 failed: %s\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @mtrace()
%2 = load i32, i32* @RTLD_NOW
%3 = load i32, i32* @RTLD_GLOBAL
%4 = or i32 %3, %2
%5 = tail call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %44, label %48
7: ; preds = %65
%8 = load i32, i32* @RTLD_NOW
%9 = load i32, i32* @RTLD_GLOBAL
%10 = or i32 %9, %8
%11 = tail call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %44, label %13
13: ; preds = %7
%14 = load i32, i32* @RTLD_NOW
%15 = load i32, i32* @RTLD_GLOBAL
%16 = or i32 %15, %14
%17 = tail call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %54, label %19
19: ; preds = %13
%20 = tail call i64 @dlclose(i8* %11)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %61
22: ; preds = %19
%23 = tail call i64 @dlclose(i8* %17)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %68
25: ; preds = %22
%26 = load i32, i32* @RTLD_NOW
%27 = load i32, i32* @RTLD_GLOBAL
%28 = or i32 %27, %26
%29 = tail call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = icmp eq i8* %29, null
br i1 %30, label %44, label %31
31: ; preds = %25
%32 = load i32, i32* @RTLD_NOW
%33 = load i32, i32* @RTLD_GLOBAL
%34 = or i32 %33, %32
%35 = tail call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = icmp eq i8* %35, null
br i1 %36, label %54, label %37
37: ; preds = %31
%38 = tail call i64 @dlclose(i8* %29)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %61
40: ; preds = %37
%41 = tail call i64 @dlclose(i8* %35)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %68
43: ; preds = %40
ret i32 0
44: ; preds = %25, %7, %0
%45 = tail call i8* (...) @dlerror()
%46 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %0
%49 = load i32, i32* @RTLD_NOW
%50 = load i32, i32* @RTLD_GLOBAL
%51 = or i32 %50, %49
%52 = tail call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %58
54: ; preds = %31, %13, %48
%55 = tail call i8* (...) @dlerror()
%56 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %48
%59 = tail call i64 @dlclose(i8* %5)
%60 = icmp eq i64 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %37, %19, %58
%62 = tail call i8* (...) @dlerror()
%63 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %62)
%64 = tail call i32 @exit(i32 1)
unreachable
65: ; preds = %58
%66 = tail call i64 @dlclose(i8* %52)
%67 = icmp eq i64 %66, 0
br i1 %67, label %7, label %68
68: ; preds = %40, %22, %65
%69 = tail call i8* (...) @dlerror()
%70 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = tail call i32 @exit(i32 1)
unreachable
}