#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 *astrcpy(char const *);
char *astrmid(char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ mu__free(char *, int, char *);
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
scalar_t__ strxequals(char *, char *);
scalar_t__ strxnullorempty(char const *);
char *strxreplace(char *, char, char);
char *abasename(const char *path) {
  char *result = NULL;
  char *tmp = NULL;
  size_t ii;
  if (strxnullorempty(path)) {
    result = astrcpy(".");
  } else {
    tmp = strxreplace(astrcpy(path), '\\', '/');
    if (strchr(tmp, '/') == NULL) {
      result = astrcpy(path);
    } else if (strxequals(tmp, "/") || strxequals(tmp, ".") ||
               strxequals(tmp, "..")) {
      result = astrcpy(tmp);
    } else {
      if (tmp[strlen(tmp) - 1] == '/')
        tmp[strlen(tmp) - 1] = '\0';
      ii = strlen(tmp);
      while (ii >= 0) {
        if (tmp[ii] == '/') {
          result = astrmid(tmp, ii + 1, 0);
          break;
        }
        ii--;
      }
    }
  }
  mu__free(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c",
      296, tmp);
  return result;
}


x86 assembly (clang, -O0):
<abasename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strxnullorempty@plt>
cmp    $0x0,%rax
je     11c4 <abasename+0x44>
lea    0xe4d(%rip),%rdi
call   1070 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    1323 <abasename+0x1a3>
mov    -0x8(%rbp),%rdi
call   1070 <astrcpy@plt>
mov    %rax,%rdi
mov    $0x5c,%esi
mov    $0x2f,%edx
call   1030 <strxreplace@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
jne    120d <abasename+0x8d>
mov    -0x8(%rbp),%rdi
call   1070 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    131e <abasename+0x19e>
mov    -0x18(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1090 <strxequals@plt>
cmp    $0x0,%rax
jne    125b <abasename+0xdb>
mov    -0x18(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1090 <strxequals@plt>
cmp    $0x0,%rax
jne    125b <abasename+0xdb>
mov    -0x18(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1090 <strxequals@plt>
cmp    $0x0,%rax
je     126d <abasename+0xed>
mov    -0x18(%rbp),%rdi
call   1070 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    1319 <abasename+0x199>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    12b8 <abasename+0x138>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jb     1314 <abasename+0x194>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1303 <abasename+0x183>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
xor    %edx,%edx
call   1080 <astrmid@plt>
mov    %rax,-0x10(%rbp)
jmp    1314 <abasename+0x194>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    12c7 <abasename+0x147>
jmp    1319 <abasename+0x199>
jmp    131e <abasename+0x19e>
jmp    1323 <abasename+0x1a3>
mov    -0x18(%rbp),%rdx
lea    0xcd7(%rip),%rdi
mov    $0x128,%esi
call   10a0 <mu__free@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abasename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strxnullorempty@plt>
test   %rax,%rax
je     11a5 <abasename+0x25>
lea    0xe6b(%rip),%rdi
call   1070 <astrcpy@plt>
mov    %rax,%rbx
xor    %r14d,%r14d
jmp    1220 <abasename+0xa0>
mov    %rbx,%rdi
call   1070 <astrcpy@plt>
mov    %rax,%rdi
mov    $0x5c,%esi
mov    $0x2f,%edx
call   1030 <strxreplace@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1215 <abasename+0x95>
lea    0xe25(%rip),%rsi
mov    %r14,%rdi
call   1090 <strxequals@plt>
test   %rax,%rax
jne    1210 <abasename+0x90>
lea    0xe14(%rip),%rsi
mov    %r14,%rdi
call   1090 <strxequals@plt>
test   %rax,%rax
jne    1210 <abasename+0x90>
lea    0xdff(%rip),%rsi
mov    %r14,%rdi
call   1090 <strxequals@plt>
test   %rax,%rax
je     123f <abasename+0xbf>
mov    %r14,%rdi
jmp    1218 <abasename+0x98>
mov    %rbx,%rdi
call   1070 <astrcpy@plt>
mov    %rax,%rbx
lea    0xdde(%rip),%rdi
mov    $0x128,%esi
mov    %r14,%rdx
call   10a0 <mu__free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r14,1)
jne    1261 <abasename+0xe1>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    $0x2,%rsi
cmpb   $0x2f,-0x2(%r14,%rsi,1)
lea    -0x1(%rsi),%rsi
jne    1270 <abasename+0xf0>
mov    %r14,%rdi
xor    %edx,%edx
call   1080 <astrmid@plt>
jmp    121d <abasename+0x9d>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c\00"
define i8* @abasename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
store i8* null, i8** %4
%6 = load i8*, i8** %2
%7 = call i64 @strxnullorempty(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i8* @astrcpy(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %3
br label %78
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i8* @astrcpy(i8* %12)
%14 = call i8* @strxreplace(i8* %13, i8 signext 92, i8 signext 47)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = call i32* @strchr(i8* %15, i8 signext 47)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i8*, i8** %2
%20 = call i8* @astrcpy(i8* %19)
store i8* %20, i8** %3
br label %77
21: ; preds = %11
%22 = load i8*, i8** %4
%23 = call i64 @strxequals(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call i64 @strxequals(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = call i64 @strxequals(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29, %25, %21
%34 = load i8*, i8** %4
%35 = call i8* @astrcpy(i8* %34)
store i8* %35, i8** %3
br label %76
36: ; preds = %29
%37 = load i8*, i8** %4
%38 = load i8*, i8** %4
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 47
br i1 %45, label %46, label %53
46: ; preds = %36
%47 = load i8*, i8** %4
%48 = load i8*, i8** %4
%49 = call i32 @strlen(i8* %48)
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %47, i64 %51
store i8 0, i8* %52
br label %53
53: ; preds = %46, %36
%54 = load i8*, i8** %4
%55 = call i32 @strlen(i8* %54)
%56 = sext i32 %55 to i64
store i64 %56, i64* %5
br label %57
57: ; preds = %72, %53
%58 = load i64, i64* %5
%59 = icmp uge i64 %58, 0
br i1 %59, label %60, label %75
60: ; preds = %57
%61 = load i8*, i8** %4
%62 = load i64, i64* %5
%63 = getelementptr inbounds i8, i8* %61, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 47
br i1 %66, label %67, label %72
67: ; preds = %60
%68 = load i8*, i8** %4
%69 = load i64, i64* %5
%70 = add i64 %69, 1
%71 = call i8* @astrmid(i8* %68, i64 %70, i32 0)
store i8* %71, i8** %3
br label %75
72: ; preds = %60
%73 = load i64, i64* %5
%74 = add i64 %73, -1
store i64 %74, i64* %5
br label %57
75: ; preds = %67, %57
br label %76
76: ; preds = %75, %33
br label %77
77: ; preds = %76, %18
br label %78
78: ; preds = %77, %9
%79 = load i8*, i8** %4
%80 = call i32 @mu__free(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.3, i64 0, i64 0), i32 296, i8* %79)
%81 = load i8*, i8** %3
ret i8* %81
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c\00"
define i8* @abasename(i8* %0) {
%2 = tail call i64 @strxnullorempty(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i8* @astrcpy(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %48
6: ; preds = %1
%7 = tail call i8* @astrcpy(i8* %0)
%8 = tail call i8* @strxreplace(i8* %7, i8 signext 92, i8 signext 47)
%9 = tail call i32* @strchr(i8* %8, i8 signext 47)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i8* @astrcpy(i8* %0)
br label %48
13: ; preds = %6
%14 = tail call i64 @strxequals(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = tail call i64 @strxequals(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i64 @strxequals(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19, %16, %13
%23 = tail call i8* @astrcpy(i8* %8)
br label %48
24: ; preds = %19
%25 = tail call i32 @strlen(i8* %8)
%26 = add nsw i32 %25, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %8, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 47
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = tail call i32 @strlen(i8* %8)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %8, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %31, %24
%37 = tail call i32 @strlen(i8* %8)
%38 = sext i32 %37 to i64
br label %39
39: ; preds = %39, %36
%40 = phi i64 [ %38, %36 ], [ %44, %39 ]
%41 = getelementptr inbounds i8, i8* %8, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 47
%44 = add i64 %40, -1
br i1 %43, label %45, label %39
45: ; preds = %39
%46 = add i64 %40, 1
%47 = tail call i8* @astrmid(i8* %8, i64 %46, i32 0)
br label %48
48: ; preds = %11, %45, %22, %4
%49 = phi i8* [ %5, %4 ], [ %12, %11 ], [ %23, %22 ], [ %47, %45 ]
%50 = phi i8* [ null, %4 ], [ %8, %11 ], [ %8, %22 ], [ %8, %45 ]
%51 = tail call i32 @mu__free(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.3, i64 0, i64 0), i32 296, i8* %50)
ret i8* %49
}