#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*/ strcpy(char *, char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
char *strrchr(char *, char);
int get_dirs(char *d, char *p, char *r) {
  char *t, *t2;
  char buf[300];
  strcpy(buf, d);
  t = strrchr(buf, '/');
  if (!t) {
    strcpy(r, buf);
    strcpy(p, "??");
    return 0;
  } else
    t++;
  if (!strncasecmp(t, "cd", 2) || !strncasecmp(t, "disc", 4) ||
      !strncasecmp(t, "sample", 6) || !strncasecmp(t, "cover", 5)) {
    *(t - 1) = 0;
    t2 = strrchr(buf, '/') + 1;
    *(t - 1) = '/';
    t = t2;
  }
  *(t - 1) = 0;
  t2 = strrchr(buf, '/') + 1;
  strcpy(p, t2);
  strcpy(r, t);
  return 1;
}


x86 assembly (clang, -O0):
<get_dirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x160(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x160(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a3 <get_dirs+0x73>
mov    -0x20(%rbp),%rdi
lea    -0x160(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    129a <get_dirs+0x16a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe49(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%eax
je     1227 <get_dirs+0xf7>
mov    -0x28(%rbp),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x4,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%eax
je     1227 <get_dirs+0xf7>
mov    -0x28(%rbp),%rdi
lea    0xe15(%rip),%rsi
mov    $0x6,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%eax
je     1227 <get_dirs+0xf7>
mov    -0x28(%rbp),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1258 <get_dirs+0x128>
mov    -0x28(%rbp),%rax
movb   $0x0,-0x1(%rax)
lea    -0x160(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x2f,-0x1(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,-0x1(%rax)
lea    -0x160(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dirs>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     121c <get_dirs+0xec>
mov    %rax,%r12
lea    0x1(%rax),%rbx
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1050 <strncasecmp@plt>
test   %eax,%eax
je     11cf <get_dirs+0x9f>
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <strncasecmp@plt>
test   %eax,%eax
je     11cf <get_dirs+0x9f>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1050 <strncasecmp@plt>
test   %eax,%eax
je     11cf <get_dirs+0x9f>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1050 <strncasecmp@plt>
test   %eax,%eax
jne    11ed <get_dirs+0xbd>
movb   $0x0,(%r12)
mov    %rsp,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x2f,(%r12)
movb   $0x0,-0x1(%rbx)
mov    %rsp,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%eax
jmp    1238 <get_dirs+0x108>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xdd2(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"??\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [5 x i8] c"disc\00"
@.str.3 = [7 x i8] c"sample\00"
@.str.4 = [6 x i8] c"cover\00"
define i32 @get_dirs(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [300 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%15 = call i8* @strrchr(i8* %14, i8 signext 47)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %6
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %64
24: ; preds = %3
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %8
br label %27
27: ; preds = %24
%28 = load i8*, i8** %8
%29 = call i32 @strncasecmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i8*, i8** %8
%33 = call i32 @strncasecmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %31
%36 = load i8*, i8** %8
%37 = call i32 @strncasecmp(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i8*, i8** %8
%41 = call i32 @strncasecmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%42 = icmp ne i32 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %39, %35, %31, %27
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 -1
store i8 0, i8* %45
%46 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%47 = call i8* @strrchr(i8* %46, i8 signext 47)
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %9
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i64 -1
store i8 47, i8* %50
%51 = load i8*, i8** %9
store i8* %51, i8** %8
br label %52
52: ; preds = %43, %39
%53 = load i8*, i8** %8
%54 = getelementptr inbounds i8, i8* %53, i64 -1
store i8 0, i8* %54
%55 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%56 = call i8* @strrchr(i8* %55, i8 signext 47)
%57 = getelementptr inbounds i8, i8* %56, i64 1
store i8* %57, i8** %9
%58 = load i8*, i8** %6
%59 = load i8*, i8** %9
%60 = call i32 @strcpy(i8* %58, i8* %59)
%61 = load i8*, i8** %7
%62 = load i8*, i8** %8
%63 = call i32 @strcpy(i8* %61, i8* %62)
store i32 1, i32* %4
br label %64
64: ; preds = %52, %18
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"??\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [5 x i8] c"disc\00"
@.str.3 = [7 x i8] c"sample\00"
@.str.4 = [6 x i8] c"cover\00"
define i32 @get_dirs(i8* %0, i8* %1, i8* %2) {
%4 = alloca [300 x i8]
%5 = getelementptr inbounds [300 x i8], [300 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = call i8* @strrchr(i8* %5, i8 signext 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = call i32 @strcpy(i8* %2, i8* %5)
%11 = call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %35
12: ; preds = %3
%13 = getelementptr inbounds i8, i8* %7, i64 1
%14 = call i32 @strncasecmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%15 = icmp eq i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = call i32 @strncasecmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = call i32 @strncasecmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = call i32 @strncasecmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22, %19, %16, %12
store i8 0, i8* %7
%26 = call i8* @strrchr(i8* %5, i8 signext 47)
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8 47, i8* %7
br label %28
28: ; preds = %25, %22
%29 = phi i8* [ %13, %22 ], [ %27, %25 ]
%30 = getelementptr inbounds i8, i8* %29, i64 -1
store i8 0, i8* %30
%31 = call i8* @strrchr(i8* %5, i8 signext 47)
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = call i32 @strcpy(i8* %1, i8* %32)
%34 = call i32 @strcpy(i8* %2, i8* %29)
br label %35
35: ; preds = %28, %9
%36 = phi i32 [ 1, %28 ], [ 0, %9 ]
ret i32 %36
}