#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memmove(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strrchr(char *, char);
void add_dotlibs(char *buffer) {
  char *name = strrchr(buffer, '/');
  if (!name) {
    if (!buffer[0]) {
      strcpy(buffer, ".libs/");
      return;
    }
    name = buffer;
  } else {
    name++;
  }
  memmove(name + 6, name, strlen(name));
  memcpy(name, ".libs/", 6);
}


x86 assembly (clang, -O0):
<add_dotlibs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <add_dotlibs+0x58>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119b <add_dotlibs+0x4b>
mov    -0x8(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f5 <add_dotlibs+0xa5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11b4 <add_dotlibs+0x64>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1070 <memmove@plt>
mov    -0x10(%rbp),%rdi
lea    0xe15(%rip),%rsi
mov    $0x6,%edx
call   1060 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_dotlibs>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     116f <add_dotlibs+0x1f>
add    $0x1,%rax
mov    %rax,%rbx
jmp    1174 <add_dotlibs+0x24>
cmpb   $0x0,(%rbx)
je     11a8 <add_dotlibs+0x58>
lea    0x6(%rbx),%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <memmove@plt>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <memcpy@plt>
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [7 x i8] c".libs/\00"
define void @add_dotlibs(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strrchr(i8* %4, i8 signext 47)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %30
16: ; preds = %8
%17 = load i8*, i8** %2
store i8* %17, i8** %3
br label %21
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %21
21: ; preds = %18, %16
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 6
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @memmove(i8* %23, i8* %24, i32 %26)
%28 = load i8*, i8** %3
%29 = call i32 @memcpy(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
br label %30
30: ; preds = %21, %13
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c".libs/\00"
define void @add_dotlibs(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
9: ; preds = %1
%10 = getelementptr inbounds i8, i8* %2, i64 1
br label %11
11: ; preds = %4, %9
%12 = phi i8* [ %10, %9 ], [ %0, %4 ]
%13 = getelementptr inbounds i8, i8* %12, i64 6
%14 = tail call i32 @strlen(i8* %12)
%15 = tail call i32 @memmove(i8* %13, i8* %12, i32 %14)
%16 = tail call i32 @memcpy(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
br label %17
17: ; preds = %11, %7
ret void
}