#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 */
typedef int /*<<< orphan*/ target;

/* Variables and functions */
scalar_t__ strcmp(char const *, char const *);
size_t strlen(char const *);
char *la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag) {
  const char target[] = "tst-audit12mod2.so";
  size_t namelen = strlen(name);
  if (namelen >= sizeof(target) - 1 &&
      strcmp(name + namelen - (sizeof(target) - 1), target) == 0) {
    return (char *)"$ORIGIN/tst-audit12mod3.so";
  }
  return (char *)name;
}


x86 assembly (clang, -O0):
<la_objsearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0xec6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec0(%rip),%ax
mov    %ax,-0x20(%rbp)
mov    0xeb8(%rip),%al
mov    %al,-0x1e(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x12,-0x38(%rbp)
jb     11a4 <la_objsearch+0x84>
mov    -0x10(%rbp),%rdi
add    -0x38(%rbp),%rdi
add    $0xffffffffffffffee,%rdi
lea    -0x30(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a4 <la_objsearch+0x84>
lea    0xe78(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ac <la_objsearch+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<la_objsearch>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movaps 0xed1(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x6f732e,0xf(%rsp)
call   1030 <strlen@plt>
cmp    $0x12,%rax
jb     1162 <la_objsearch+0x42>
lea    (%rbx,%rax,1),%rdi
add    $0xffffffffffffffee,%rdi
mov    %rsp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1162 <la_objsearch+0x42>
lea    0xeb1(%rip),%rbx
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.la_objsearch.target = [19 x i8] c"tst-audit12mod2.so\00"
@.str = [27 x i8] c"$ORIGIN/tst-audit12mod3.so\00"
define i8* @la_objsearch(i8* %0, i64* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca [19 x i8]
%9 = alloca i64
store i8* %0, i8** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
%10 = bitcast [19 x i8]* %8 to i8*
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %9
%13 = load i64, i64* %9
%14 = icmp uge i64 %13, 18
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i64, i64* %9
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -18
%20 = getelementptr inbounds [19 x i8], [19 x i8]* %8, i64 0, i64 0
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %4
br label %26
24: ; preds = %15, %3
%25 = load i8*, i8** %5
store i8* %25, i8** %4
br label %26
26: ; preds = %24, %23
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
@__const.la_objsearch.target = [19 x i8] c"tst-audit12mod2.so\00"
@.str = [27 x i8] c"$ORIGIN/tst-audit12mod3.so\00"
define i8* @la_objsearch(i8* %0, i64* nocapture readnone %1, i32 %2) {
%4 = alloca [19 x i8]
%5 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = icmp ugt i64 %6, 17
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %0, i64 %6
%10 = getelementptr inbounds i8, i8* %9, i64 -18
%11 = call i64 @strcmp(i8* %10, i8* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %8, %3
br label %14
14: ; preds = %8, %13
%15 = phi i8* [ %0, %13 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %8 ]
ret i8* %15
}