#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 */
char const *bt_get_basename(char *);
const char *get_batch_name(char *path) {
  char *p = (char *)bt_get_basename(path) - 1;
  for (; p > path && (*p == '/' || *p == '\\'); p--)
    *p = 0;
  if (p <= path)
    return "BATCH_DIR";
  return bt_get_basename(path);
}


x86 assembly (clang, -O0):
<get_batch_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <bt_get_basename@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x19(%rbp)
jbe    116b <get_batch_name+0x5b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2f,%ecx
mov    %al,-0x1a(%rbp)
je     1165 <get_batch_name+0x55>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117b <get_batch_name+0x6b>
jmp    1193 <get_batch_name+0x83>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112d <get_batch_name+0x1d>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     11b1 <get_batch_name+0xa1>
lea    0xe58(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11be <get_batch_name+0xae>
mov    -0x10(%rbp),%rdi
call   1030 <bt_get_basename@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_batch_name>:
push   %rbx
mov    %rdi,%rbx
call   1030 <bt_get_basename@plt>
jmp    1123 <get_batch_name+0x13>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    1142 <get_batch_name+0x32>
movzbl (%rax),%ecx
cmp    $0x5c,%cl
je     1120 <get_batch_name+0x10>
cmp    $0x2f,%cl
je     1120 <get_batch_name+0x10>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <bt_get_basename@plt>
lea    0xeb7(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"BATCH_DIR\00"
define i8* @get_batch_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @bt_get_basename(i8* %5)
%7 = getelementptr inbounds i8, i8* %6, i64 -1
store i8* %7, i8** %4
br label %8
8: ; preds = %28, %1
%9 = load i8*, i8** %4
%10 = load i8*, i8** %3
%11 = icmp ugt i8* %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 47
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 92
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ true, %12 ], [ %21, %17 ]
br label %24
24: ; preds = %22, %8
%25 = phi i1 [ false, %8 ], [ %23, %22 ]
br i1 %25, label %26, label %31
26: ; preds = %24
%27 = load i8*, i8** %4
store i8 0, i8* %27
br label %28
28: ; preds = %26
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %4
br label %8
31: ; preds = %24
%32 = load i8*, i8** %4
%33 = load i8*, i8** %3
%34 = icmp ule i8* %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
br label %39
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = call i8* @bt_get_basename(i8* %37)
store i8* %38, i8** %2
br label %39
39: ; preds = %36, %35
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"BATCH_DIR\00"
define i8* @get_batch_name(i8* %0) {
%2 = tail call i8* @bt_get_basename(i8* %0)
%3 = getelementptr inbounds i8, i8* %2, i64 -1
%4 = icmp ugt i8* %3, %0
br i1 %4, label %5, label %13
5: ; preds = %1, %8
%6 = phi i8* [ %9, %8 ], [ %3, %1 ]
%7 = load i8, i8* %6
switch i8 %7, label %11 [
i8 47, label %8
i8 92, label %8
]
8: ; preds = %5, %5
store i8 0, i8* %6
%9 = getelementptr inbounds i8, i8* %6, i64 -1
%10 = icmp ugt i8* %9, %0
br i1 %10, label %5, label %13
11: ; preds = %5
%12 = tail call i8* @bt_get_basename(i8* %0)
br label %13
13: ; preds = %8, %1, %11
%14 = phi i8* [ %12, %11 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %8 ]
ret i8* %14
}