#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*/ dir_sep();
scalar_t__ ends_with(char const *, int /*<<< orphan*/);
char *slice_str(int, int, char const *);
int strlen(char const *);
char *pkg_name_from_fname(const char *root, const char *name) {
  int len_root, start;
  if (root != NULL) {
    len_root = strlen(root);
    start = (ends_with(root, dir_sep())) ? len_root : len_root + 1;
  } else {
    start = 0;
  }
  return slice_str(start, (strlen(name) - 2), name);
}


x86 assembly (clang, -O0):
<pkg_name_from_fname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11aa <pkg_name_from_fname+0x6a>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <dir_sep@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1060 <ends_with@plt>
cmp    $0x0,%rax
je     1196 <pkg_name_from_fname+0x56>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    119f <pkg_name_from_fname+0x5f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11b1 <pkg_name_from_fname+0x71>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
sub    $0x2,%esi
mov    -0x10(%rbp),%rdx
call   1030 <slice_str@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkg_name_from_fname>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1170 <pkg_name_from_fname+0x30>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <dir_sep@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <ends_with@plt>
cmp    $0x1,%rax
adc    $0x0,%ebp
jmp    1172 <pkg_name_from_fname+0x32>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    -0x2(%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <slice_str@plt>

LLVM IR (-O0):
define i8* @pkg_name_from_fname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
%12 = load i8*, i8** %3
%13 = call i32 (...) @dir_sep()
%14 = call i64 @ends_with(i8* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = load i32, i32* %5
br label %21
18: ; preds = %9
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
br label %21
21: ; preds = %18, %16
%22 = phi i32 [ %17, %16 ], [ %20, %18 ]
store i32 %22, i32* %6
br label %24
23: ; preds = %2
store i32 0, i32* %6
br label %24
24: ; preds = %23, %21
%25 = load i32, i32* %6
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 2
%29 = load i8*, i8** %4
%30 = call i8* @slice_str(i32 %25, i32 %28, i8* %29)
ret i8* %30
}

LLVM IR (-O2):
define i8* @pkg_name_from_fname(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 (...) @dir_sep()
%7 = tail call i64 @ends_with(i8* %0, i32 %6)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = add nsw i32 %5, %9
br label %11
11: ; preds = %2, %4
%12 = phi i32 [ %10, %4 ], [ 0, %2 ]
%13 = tail call i32 @strlen(i8* %1)
%14 = add nsw i32 %13, -2
%15 = tail call i8* @slice_str(i32 %12, i32 %14, i8* %1)
ret i8* %15
}