#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 *astrleft(char *, size_t);
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 *adirname(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(".");
    } 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] == '/') {
        if (ii == 0) {
          result = astrcpy("/");
        } else {
          result = astrleft(tmp, ii);
        }
        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",
      257, tmp);
  return result;
}


x86 assembly (clang, -O0):
<adirname>:
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 <adirname+0x44>
lea    0xe4d(%rip),%rdi
call   1080 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    1340 <adirname+0x1c0>
mov    -0x8(%rbp),%rdi
call   1080 <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    1210 <adirname+0x90>
lea    0xe01(%rip),%rdi
call   1080 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    12c5 <adirname+0x145>
mov    -0x18(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1090 <strxequals@plt>
cmp    $0x0,%rax
jne    125e <adirname+0xde>
mov    -0x18(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   1090 <strxequals@plt>
cmp    $0x0,%rax
jne    125e <adirname+0xde>
mov    -0x18(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   1090 <strxequals@plt>
cmp    $0x0,%rax
je     1270 <adirname+0xf0>
mov    -0x18(%rbp),%rdi
call   1080 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    12c0 <adirname+0x140>
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    12bb <adirname+0x13b>
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)
jmp    12c0 <adirname+0x140>
jmp    12c5 <adirname+0x145>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jb     133b <adirname+0x1bb>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    132a <adirname+0x1aa>
cmpq   $0x0,-0x20(%rbp)
jne    1314 <adirname+0x194>
lea    0xcfa(%rip),%rdi
call   1080 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    1325 <adirname+0x1a5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <astrleft@plt>
mov    %rax,-0x10(%rbp)
jmp    133b <adirname+0x1bb>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    12d4 <adirname+0x154>
jmp    1340 <adirname+0x1c0>
mov    -0x18(%rbp),%rdx
lea    0xcba(%rip),%rdi
mov    $0x101,%esi
call   10a0 <mu__free@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adirname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strxnullorempty@plt>
test   %rax,%rax
je     11a7 <adirname+0x27>
lea    0xe6b(%rip),%rdi
call   1080 <astrcpy@plt>
mov    %rax,%r14
xor    %ebx,%ebx
jmp    1269 <adirname+0xe9>
mov    %rbx,%rdi
call   1080 <astrcpy@plt>
mov    %rax,%rdi
mov    $0x5c,%esi
mov    $0x2f,%edx
call   1030 <strxreplace@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1217 <adirname+0x97>
lea    0xe23(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strxequals@plt>
test   %rax,%rax
jne    1212 <adirname+0x92>
lea    0xe12(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strxequals@plt>
test   %rax,%rax
jne    1212 <adirname+0x92>
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strxequals@plt>
test   %rax,%rax
je     1288 <adirname+0x108>
mov    %rbx,%rdi
jmp    121e <adirname+0x9e>
lea    0xde5(%rip),%rdi
call   1080 <astrcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    $0x1,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x2f,-0x1(%rbx,%rsi,1)
lea    -0x1(%rsi),%rsi
jne    1240 <adirname+0xc0>
test   %rsi,%rsi
je     125a <adirname+0xda>
mov    %rbx,%rdi
call   1070 <astrleft@plt>
jmp    1266 <adirname+0xe6>
lea    0xd9f(%rip),%rdi
call   1080 <astrcpy@plt>
mov    %rax,%r14
lea    0xd95(%rip),%rdi
mov    $0x101,%esi
mov    %rbx,%rdx
call   10a0 <mu__free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1223 <adirname+0xa3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    1223 <adirname+0xa3>

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* @adirname(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 %82
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 %20
18: ; preds = %11
%19 = call i8* @astrcpy(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %3
br label %54
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = call i64 @strxequals(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = call i64 @strxequals(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = call i64 @strxequals(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28, %24, %20
%33 = load i8*, i8** %4
%34 = call i8* @astrcpy(i8* %33)
store i8* %34, i8** %3
br label %53
35: ; preds = %28
%36 = load i8*, i8** %4
%37 = load i8*, i8** %4
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 47
br i1 %44, label %45, label %52
45: ; preds = %35
%46 = load i8*, i8** %4
%47 = load i8*, i8** %4
%48 = call i32 @strlen(i8* %47)
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %46, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %45, %35
br label %53
53: ; preds = %52, %32
br label %54
54: ; preds = %53, %18
%55 = load i8*, i8** %4
%56 = call i32 @strlen(i8* %55)
%57 = sext i32 %56 to i64
store i64 %57, i64* %5
br label %58
58: ; preds = %78, %54
%59 = load i64, i64* %5
%60 = icmp uge i64 %59, 0
br i1 %60, label %61, label %81
61: ; preds = %58
%62 = load i8*, i8** %4
%63 = load i64, i64* %5
%64 = getelementptr inbounds i8, i8* %62, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 47
br i1 %67, label %68, label %78
68: ; preds = %61
%69 = load i64, i64* %5
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i8* @astrcpy(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %72, i8** %3
br label %77
73: ; preds = %68
%74 = load i8*, i8** %4
%75 = load i64, i64* %5
%76 = call i8* @astrleft(i8* %74, i64 %75)
store i8* %76, i8** %3
br label %77
77: ; preds = %73, %71
br label %81
78: ; preds = %61
%79 = load i64, i64* %5
%80 = add i64 %79, -1
store i64 %80, i64* %5
br label %58
81: ; preds = %77, %58
br label %82
82: ; preds = %81, %9
%83 = load i8*, i8** %4
%84 = call i32 @mu__free(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.3, i64 0, i64 0), i32 257, i8* %83)
%85 = load i8*, i8** %3
ret i8* %85
}

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* @adirname(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 %51
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* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %36
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 %36
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 = %22, %31, %24, %11
%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 = icmp eq i64 %40, 0
br i1 %46, label %47, label %49
47: ; preds = %45
%48 = tail call i8* @astrcpy(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %51
49: ; preds = %45
%50 = tail call i8* @astrleft(i8* %8, i64 %40)
br label %51
51: ; preds = %49, %47, %4
%52 = phi i8* [ %5, %4 ], [ %48, %47 ], [ %50, %49 ]
%53 = phi i8* [ null, %4 ], [ %8, %47 ], [ %8, %49 ]
%54 = tail call i32 @mu__free(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.3, i64 0, i64 0), i32 257, i8* %53)
ret i8* %52
}