#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_LAZY;
int /*<<< orphan*/ RTLD_NOW;
scalar_t__ load_dso(char const **, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int errors = 0;
  const char *loading[3];
  loading[0] = "circlemod1a.so";
  loading[1] = "circlemod2a.so";
  loading[2] = "circlemod3a.so";
  errors += load_dso(loading, 0, RTLD_LAZY);
  errors += load_dso(loading, 0, RTLD_NOW);
  loading[0] = "circlemod1.so";
  loading[1] = "circlemod2.so";
  loading[2] = "circlemod3.so";
  errors += load_dso(loading, 1, RTLD_LAZY);
  errors += load_dso(loading, 1, RTLD_NOW);
  if (errors != 0)
    printf("%d errors found\n", errors);
  return errors;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xecb(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <load_dso@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <load_dso@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1030 <load_dso@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1030 <load_dso@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     121b <main+0xfb>
mov    -0x8(%rbp),%esi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xecc(%rip),%rax
mov    %rax,(%rsp)
lea    0xed0(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xed3(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0x2e81(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <load_dso@plt>
mov    %rax,%r15
mov    0x2e76(%rip),%r12
mov    (%r12),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <load_dso@plt>
mov    %rax,%rbx
add    %r15d,%ebx
lea    0xea0(%rip),%rax
mov    %rax,(%rsp)
lea    0xea3(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xea5(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <load_dso@plt>
mov    %rax,%r15
add    %ebx,%r15d
mov    (%r12),%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <load_dso@plt>
mov    %rax,%rbx
add    %r15d,%ebx
je     11e7 <main+0xc7>
lea    0xe77(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"circlemod1a.so\00"
@.str.1 = [15 x i8] c"circlemod2a.so\00"
@.str.2 = [15 x i8] c"circlemod3a.so\00"
@RTLD_LAZY = global i32 0
@RTLD_NOW = global i32 0
@.str.3 = [14 x i8] c"circlemod1.so\00"
@.str.4 = [14 x i8] c"circlemod2.so\00"
@.str.5 = [14 x i8] c"circlemod3.so\00"
@.str.6 = [17 x i8] c"%d errors found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x i8*]
store i32 0, i32* %1
store i32 0, i32* %2
%4 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%8 = load i32, i32* @RTLD_LAZY
%9 = call i64 @load_dso(i8** %7, i32 0, i32 %8)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = add nsw i64 %11, %9
%13 = trunc i64 %12 to i32
store i32 %13, i32* %2
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%15 = load i32, i32* @RTLD_NOW
%16 = call i64 @load_dso(i8** %14, i32 0, i32 %15)
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %2
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%25 = load i32, i32* @RTLD_LAZY
%26 = call i64 @load_dso(i8** %24, i32 1, i32 %25)
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %2
%31 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%32 = load i32, i32* @RTLD_NOW
%33 = call i64 @load_dso(i8** %31, i32 1, i32 %32)
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %2
%38 = load i32, i32* %2
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %0
%41 = load i32, i32* %2
%42 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40, %0
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [15 x i8] c"circlemod1a.so\00"
@.str.1 = [15 x i8] c"circlemod2a.so\00"
@.str.2 = [15 x i8] c"circlemod3a.so\00"
@RTLD_LAZY = global i32 0
@RTLD_NOW = global i32 0
@.str.3 = [14 x i8] c"circlemod1.so\00"
@.str.4 = [14 x i8] c"circlemod2.so\00"
@.str.5 = [14 x i8] c"circlemod3.so\00"
@.str.6 = [17 x i8] c"%d errors found\0A\00"
define i32 @main() {
%1 = alloca [3 x i8*]
%2 = bitcast [3 x i8*]* %1 to i8*
%3 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %5
%6 = load i32, i32* @RTLD_LAZY
%7 = call i64 @load_dso(i8** %3, i32 0, i32 %6)
%8 = load i32, i32* @RTLD_NOW
%9 = call i64 @load_dso(i8** %3, i32 0, i32 %8)
%10 = add i64 %9, %7
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8** %5
%11 = load i32, i32* @RTLD_LAZY
%12 = call i64 @load_dso(i8** %3, i32 1, i32 %11)
%13 = add i64 %10, %12
%14 = load i32, i32* @RTLD_NOW
%15 = call i64 @load_dso(i8** %3, i32 1, i32 %14)
%16 = add i64 %13, %15
%17 = trunc i64 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %0
%20 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %17)
br label %21
21: ; preds = %19, %0
ret i32 %17
}