#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 */
struct t_gui_completion {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gui_completion_list_add(struct t_gui_completion *, char *,
                                           int /*<<< orphan*/, char *);
char *strdup(char const *);
char *string_strndup(char const *, int);
char *strrchr(char const *, char);
void completion_list_add_plugins_installed_exec_cb(void *data,
                                                   const char *filename) {
  struct t_gui_completion *completion;
  const char *pos, *pos2;
  char *name;
  completion = (struct t_gui_completion *)data;
  pos = strrchr(filename, '/');
  if (pos)
    pos++;
  else
    pos = filename;
  pos2 = strrchr(pos, '.');
  if (pos2)
    name = string_strndup(pos, pos2 - pos);
  else
    name = strdup(pos);
  if (name) {
    gui_completion_list_add(completion, name, 0, "sort");
    free(name);
  }
}


x86 assembly (clang, -O0):
<completion_list_add_plugins_installed_exec_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1196 <completion_list_add_plugins_installed_exec_cb+0x46>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119e <completion_list_add_plugins_installed_exec_cb+0x4e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11da <completion_list_add_plugins_installed_exec_cb+0x8a>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1060 <string_strndup@plt>
mov    %rax,-0x30(%rbp)
jmp    11e7 <completion_list_add_plugins_installed_exec_cb+0x97>
mov    -0x20(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1211 <completion_list_add_plugins_installed_exec_cb+0xc1>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
lea    0xdfd(%rip),%rcx
call   1040 <gui_completion_list_add@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<completion_list_add_plugins_installed_exec_cb>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1193 <completion_list_add_plugins_installed_exec_cb+0x43>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <string_strndup@plt>
jmp    119b <completion_list_add_plugins_installed_exec_cb+0x4b>
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c4 <completion_list_add_plugins_installed_exec_cb+0x74>
lea    0xe56(%rip),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <gui_completion_list_add@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.t_gui_completion = type { i32 }
@.str = [5 x i8] c"sort\00"
define void @completion_list_add_plugins_installed_exec_cb(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.t_gui_completion*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to %struct.t_gui_completion*
store %struct.t_gui_completion* %10, %struct.t_gui_completion** %5
%11 = load i8*, i8** %4
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %6
br label %20
18: ; preds = %2
%19 = load i8*, i8** %4
store i8* %19, i8** %6
br label %20
20: ; preds = %18, %15
%21 = load i8*, i8** %6
%22 = call i8* @strrchr(i8* %21, i8 signext 46)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = load i8*, i8** %6
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
%33 = call i8* @string_strndup(i8* %26, i32 %32)
store i8* %33, i8** %8
br label %37
34: ; preds = %20
%35 = load i8*, i8** %6
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %8
br label %37
37: ; preds = %34, %25
%38 = load i8*, i8** %8
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load %struct.t_gui_completion*, %struct.t_gui_completion** %5
%42 = load i8*, i8** %8
%43 = call i32 @gui_completion_list_add(%struct.t_gui_completion* %41, i8* %42, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %40, %37
ret void
}

LLVM IR (-O2):
%struct.t_gui_completion = type { i32 }
@.str = [5 x i8] c"sort\00"
define void @completion_list_add_plugins_installed_exec_cb(i8* %0, i8* %1) {
%3 = bitcast i8* %0 to %struct.t_gui_completion*
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = getelementptr inbounds i8, i8* %4, i64 1
%7 = select i1 %5, i8* %1, i8* %6
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %7, i8 signext 46)
%9 = icmp eq i8* %8, null
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = ptrtoint i8* %8 to i64
%12 = ptrtoint i8* %7 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = tail call i8* @string_strndup(i8* %7, i32 %14)
br label %18
16: ; preds = %2
%17 = tail call i8* @strdup(i8* %7)
br label %18
18: ; preds = %16, %10
%19 = phi i8* [ %15, %10 ], [ %17, %16 ]
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @gui_completion_list_add(%struct.t_gui_completion* %3, i8* %19, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @free(i8* %19)
br label %24
24: ; preds = %21, %18
ret void
}