#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 */
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ paths_exec_path();
char *strdup(int /*<<< orphan*/);
char *strrchr(char *, char);
const char *paths_prefix(void) {
  static char *prefix_buf;
  if (!prefix_buf) {
    char *pos;
    prefix_buf = strdup(paths_exec_path());
    pos = strrchr(prefix_buf, '/');
    prefix_buf[pos ? pos - prefix_buf : 0] = '\0';
    pos = strrchr(prefix_buf, '/');
    if (pos && memcmp(pos, "/bin", sizeof "/bin" - 1) == 0)
      *pos = '\0';
  }
  return prefix_buf;
}


x86 assembly (clang, -O0):
<paths_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpq   $0x0,0x2ef8(%rip)
jne    120f <paths_prefix+0xcf>
mov    $0x0,%al
call   1050 <paths_exec_path@plt>
mov    %eax,%edi
call   1060 <strdup@plt>
mov    %rax,0x2edd(%rip)
mov    0x2ed6(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x8(%rbp)
mov    0x2ec1(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ad <paths_prefix+0x6d>
mov    -0x8(%rbp),%rax
mov    0x2ea7(%rip),%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <paths_prefix+0x78>
xor    %eax,%eax
mov    %rax,-0x18(%rbp)
jmp    11b8 <paths_prefix+0x78>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e7d(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     120a <paths_prefix+0xca>
mov    -0x8(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    120a <paths_prefix+0xca>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    120f <paths_prefix+0xcf>
mov    0x2e32(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paths_prefix>:
push   %rbx
cmpq   $0x0,0x2eff(%rip)
je     1154 <paths_prefix+0x14>
mov    0x2ef6(%rip),%rax
pop    %rbx
ret
xor    %eax,%eax
call   1050 <paths_exec_path@plt>
mov    %eax,%edi
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,0x2edc(%rip)
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%rcx
sub    %rbx,%rcx
test   %rax,%rax
cmove  %rax,%rcx
movb   $0x0,(%rbx,%rcx,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     114b <paths_prefix+0xb>
mov    %rax,%rbx
lea    0xe5a(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    114b <paths_prefix+0xb>
movb   $0x0,(%rbx)
jmp    114b <paths_prefix+0xb>

LLVM IR (-O0):
@paths_prefix.prefix_buf = internal global i8* null
@.str = [5 x i8] c"/bin\00"
define i8* @paths_prefix() {
%1 = alloca i8*
%2 = load i8*, i8** @paths_prefix.prefix_buf
%3 = icmp ne i8* %2, null
br i1 %3, label %33, label %4
4: ; preds = %0
%5 = call i32 (...) @paths_exec_path()
%6 = call i8* @strdup(i32 %5)
store i8* %6, i8** @paths_prefix.prefix_buf
%7 = load i8*, i8** @paths_prefix.prefix_buf
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %1
%9 = load i8*, i8** @paths_prefix.prefix_buf
%10 = load i8*, i8** %1
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %4
%13 = load i8*, i8** %1
%14 = load i8*, i8** @paths_prefix.prefix_buf
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
br label %19
18: ; preds = %4
br label %19
19: ; preds = %18, %12
%20 = phi i64 [ %17, %12 ], [ 0, %18 ]
%21 = getelementptr inbounds i8, i8* %9, i64 %20
store i8 0, i8* %21
%22 = load i8*, i8** @paths_prefix.prefix_buf
%23 = call i8* @strrchr(i8* %22, i8 signext 47)
store i8* %23, i8** %1
%24 = load i8*, i8** %1
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = load i8*, i8** %1
%28 = call i64 @memcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i8*, i8** %1
store i8 0, i8* %31
br label %32
32: ; preds = %30, %26, %19
br label %33
33: ; preds = %32, %0
%34 = load i8*, i8** @paths_prefix.prefix_buf
ret i8* %34
}

LLVM IR (-O2):
@paths_prefix.prefix_buf = internal unnamed_addr global i8* null
@.str = [5 x i8] c"/bin\00"
define i8* @paths_prefix() {
%1 = load i8*, i8** @paths_prefix.prefix_buf
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %19
3: ; preds = %0
%4 = tail call i32 (...) @paths_exec_path()
%5 = tail call i8* @strdup(i32 %4)
store i8* %5, i8** @paths_prefix.prefix_buf
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 47)
%7 = icmp eq i8* %6, null
%8 = ptrtoint i8* %6 to i64
%9 = ptrtoint i8* %5 to i64
%10 = sub i64 %8, %9
%11 = select i1 %7, i64 0, i64 %10
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %3
%16 = tail call i64 @memcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i8 0, i8* %13
br label %19
19: ; preds = %3, %15, %18, %0
%20 = load i8*, i8** @paths_prefix.prefix_buf
ret i8* %20
}