int get_parent_directory(char *fname) {
  char *cp;
  int at_end = 1;
  (void)({
    if (__builtin_expect(!!(!(fname)), 0)) {
      tor_assertion_failed_(("/scratch/repos/new/home/jordi_armengol_estape/"
                             "c-scraper/outputs/2022-01-22/02-19-57/repos/5mil/"
                             "lulz/refs/heads/master/src/tor/compat.c"),
                            1854, __func__, "fname");
      abort();
    }
  });
  cp = fname + strlen(fname);
  at_end = 1;
  while (--cp >= fname) {
    int is_sep = (*cp == '/');
    if (is_sep) {
      if (cp == fname) {
        cp[1] = '\0';
        return 0;
      }
      *cp = '\0';
      if (!at_end)
        return 0;
    } else {
      at_end = 0;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_parent_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cltq
cmp    $0x0,%rax
je     1188 <get_parent_directory+0x58>
lea    0xe97(%rip),%rdi
mov    $0x73e,%esi
lea    0xf12(%rip),%rdx
lea    0xf20(%rip),%rcx
mov    $0x0,%al
call   1030 <tor_assertion_failed_@plt>
call   1040 <abort@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmp    -0x10(%rbp),%rax
jb     1233 <get_parent_directory+0x103>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1227 <get_parent_directory+0xf7>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1205 <get_parent_directory+0xd5>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x0,-0x4(%rbp)
jmp    123a <get_parent_directory+0x10a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x1c(%rbp)
jne    1222 <get_parent_directory+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    123a <get_parent_directory+0x10a>
jmp    122e <get_parent_directory+0xfe>
movl   $0x0,-0x1c(%rbp)
jmp    11ae <get_parent_directory+0x7e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_parent_directory>:
push   %rbx
test   %rdi,%rdi
je     1198 <get_parent_directory+0x68>
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %rax,%rcx
lea    (%rbx,%rax,1),%rdx
add    $0xffffffffffffffff,%rdx
mov    $0xffffffff,%eax
cmp    %rbx,%rdx
jae    1155 <get_parent_directory+0x25>
pop    %rbx
ret
add    $0xffffffffffffffff,%rcx
mov    $0x1,%edx
jmp    1173 <get_parent_directory+0x43>
lea    (%rbx,%rcx,1),%rdi
add    $0xffffffffffffffff,%rdi
add    $0xffffffffffffffff,%rcx
mov    %esi,%edx
cmp    %rbx,%rdi
jb     1153 <get_parent_directory+0x23>
xor    %esi,%esi
cmpb   $0x2f,(%rbx,%rcx,1)
jne    1160 <get_parent_directory+0x30>
test   %rcx,%rcx
je     118f <get_parent_directory+0x5f>
movb   $0x0,(%rbx,%rcx,1)
mov    $0x1,%esi
test   %edx,%edx
jne    1160 <get_parent_directory+0x30>
jmp    1194 <get_parent_directory+0x64>
movb   $0x0,0x1(%rbx,%rcx,1)
xor    %eax,%eax
pop    %rbx
ret
lea    0xe61(%rip),%rdi
lea    0xee1(%rip),%rdx
lea    0xeef(%rip),%rcx
mov    $0x73e,%esi
xor    %eax,%eax
call   1030 <tor_assertion_failed_@plt>
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/5mil/lulz/refs/heads/master/src/tor/compat.c\00"
@__func__.get_parent_directory = [21 x i8] c"get_parent_directory\00"
@.str.1 = [6 x i8] c"fname\00"
define i32 @get_parent_directory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 1, i32* %5
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
%9 = xor i1 %8, true
%10 = xor i1 %9, true
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 (i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @tor_assertion_failed_ to i32 (i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 1854, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @__func__.get_parent_directory, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
unreachable
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8* %21, i8** %4
store i32 1, i32* %5
br label %22
22: ; preds = %49, %17
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %4
%25 = load i8*, i8** %3
%26 = icmp uge i8* %24, %25
br i1 %26, label %27, label %50
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 47
%32 = zext i1 %31 to i32
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %27
%36 = load i8*, i8** %4
%37 = load i8*, i8** %3
%38 = icmp eq i8* %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8 0, i8* %41
store i32 0, i32* %2
br label %51
42: ; preds = %35
%43 = load i8*, i8** %4
store i8 0, i8* %43
%44 = load i32, i32* %5
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %42
store i32 0, i32* %2
br label %51
47: ; preds = %42
br label %49
48: ; preds = %27
store i32 0, i32* %5
br label %49
49: ; preds = %48, %47
br label %22
50: ; preds = %22
store i32 -1, i32* %2
br label %51
51: ; preds = %50, %46, %39
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
@.str = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/5mil/lulz/refs/heads/master/src/tor/compat.c\00"
@__func__.get_parent_directory = [21 x i8] c"get_parent_directory\00"
@.str.1 = [6 x i8] c"fname\00"
define i32 @get_parent_directory(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @tor_assertion_failed_ to i32 (i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 1854, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @__func__.get_parent_directory, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
tail call void @abort()
unreachable
5: ; preds = %1
%6 = tail call i64 @strlen(i8* %0)
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp ult i8* %8, %0
br i1 %9, label %25, label %10
10: ; preds = %5, %21
%11 = phi i8* [ %23, %21 ], [ %8, %5 ]
%12 = phi i32 [ %22, %21 ], [ 1, %5 ]
%13 = phi i8* [ %11, %21 ], [ %7, %5 ]
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = icmp eq i8* %11, %0
br i1 %17, label %18, label %19
18: ; preds = %16
store i8 0, i8* %13
br label %25
19: ; preds = %16
store i8 0, i8* %11
%20 = icmp eq i32 %12, 0
br i1 %20, label %25, label %21
21: ; preds = %19, %10
%22 = phi i32 [ 1, %19 ], [ 0, %10 ]
%23 = getelementptr inbounds i8, i8* %11, i64 -1
%24 = icmp ult i8* %23, %0
br i1 %24, label %25, label %10
25: ; preds = %21, %19, %5, %18
%26 = phi i32 [ 0, %18 ], [ -1, %5 ], [ -1, %21 ], [ 0, %19 ]
ret i32 %26
}