#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;
void *dlopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, size_t const, char *, char const *,
                            char const *);
size_t strlen(char const *);
void *plugin_common_dlopen(const char *dir, const char *name) {
  const size_t path_len = strlen(name) + strlen(dir) + sizeof(".so");
  char path[path_len];
  snprintf(path, path_len, "%s%s.so", dir, name);
  return dlopen(path, RTLD_LAZY);
}


x86 assembly (clang, -O0):
<plugin_common_dlopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
lea    0x4(%rax,%rcx,1),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe60(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
call   1050 <dlopen@plt>
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plugin_common_dlopen>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%rsi
add    $0x4,%rsi
add    %rbx,%rax
add    $0x13,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8a(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <dlopen@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s%s.so\00"
@RTLD_LAZY = global i32 0
define i8* @plugin_common_dlopen(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = add i64 %9, %11
%13 = add i64 %12, 4
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
%17 = load i64, i64* %5
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = call i32 @snprintf(i8* %16, i64 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
%21 = load i32, i32* @RTLD_LAZY
%22 = call i8* @dlopen(i8* %16, i32 %21)
%23 = load i8*, i8** %6
ret i8* %22
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s%s.so\00"
@RTLD_LAZY = global i32 0
define i8* @plugin_common_dlopen(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add i64 %3, 4
%6 = add i64 %5, %4
%7 = alloca i8, i64 %6
%8 = call i32 @snprintf(i8* %7, i64 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = load i32, i32* @RTLD_LAZY
%10 = call i8* @dlopen(i8* %7, i32 %9)
ret i8* %10
}