#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 strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strpbrk(char const *, char *);
char *xmalloc(int);
char *extract_decoder_name(const char *filename) {
  int len;
  const char *ptr;
  char *result;
  if (!strncmp(filename, "lib", 3))
    filename += 3;
  len = strlen(filename);
  ptr = strpbrk(filename, "_.-");
  if (ptr)
    len = ptr - filename;
  result = xmalloc(len + 1);
  strncpy(result, filename, len);
  result[len] = 0x00;
  return result;
}


x86 assembly (clang, -O0):
<extract_decoder_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1186 <extract_decoder_name+0x36>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <strpbrk@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bf <extract_decoder_name+0x6f>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1060 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_decoder_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,2),%rbx
add    %r14,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strpbrk@plt>
mov    %eax,%ebp
sub    %ebx,%ebp
test   %rax,%rax
cmove  %r14d,%ebp
lea    0x1(%rbp),%edi
call   1060 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"lib\00"
@.str.1 = [4 x i8] c"_.-\00"
define i8* @extract_decoder_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 3
store i8* %11, i8** %2
br label %12
12: ; preds = %9, %1
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %3
%15 = load i8*, i8** %2
%16 = call i8* @strpbrk(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = load i8*, i8** %2
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %3
br label %26
26: ; preds = %19, %12
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
%29 = call i8* @xmalloc(i32 %28)
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = call i32 @strncpy(i8* %30, i8* %31, i32 %32)
%34 = load i8*, i8** %5
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
@.str = [4 x i8] c"lib\00"
@.str.1 = [4 x i8] c"_.-\00"
define i8* @extract_decoder_name(i8* %0) {
%2 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%3 = icmp eq i32 %2, 0
%4 = select i1 %3, i64 3, i64 0
%5 = getelementptr i8, i8* %0, i64 %4
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i8* @strpbrk(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %5 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = select i1 %8, i32 %6, i32 %12
%14 = add nsw i32 %13, 1
%15 = tail call i8* @xmalloc(i32 %14)
%16 = tail call i32 @strncpy(i8* %15, i8* %5, i32 %13)
%17 = sext i32 %13 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
ret i8* %15
}