char *helper_extract_dirname(const char *path) {
  char *result, *position;
  result = helper_strdup(path,
                         "/scratch/repos/new/home/jordi_armengol_estape/"
                         "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                         "aweeraman/debian-copyfs/refs/heads/master/helper.c",
                         322, __func__);
  position = rindex(result, '/');
  if (position)
    *position = '\0';
  else
    *result = '\0';
  return helper_realloc(result, strlen(result) + 1,
                        "/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/aweeraman/"
                        "debian-copyfs/refs/heads/master/helper.c",
                        328, __func__);
}


x86 assembly (clang, -O0):
<helper_extract_dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x142,%edx
lea    0xf2a(%rip),%rcx
mov    $0x0,%al
call   1050 <helper_strdup@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <rindex@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <helper_extract_dirname+0x59>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11a0 <helper_extract_dirname+0x60>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
lea    0xe3d(%rip),%rdx
mov    $0x148,%ecx
lea    0xebe(%rip),%r8
mov    $0x0,%al
call   1040 <helper_realloc@plt>
cltq
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<helper_extract_dirname>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%r15
lea    0xf3a(%rip),%r14
mov    %r15,%rsi
mov    $0x142,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <helper_strdup@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <rindex@plt>
test   %rax,%rax
cmove  %rbx,%rax
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    $0x148,%ecx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <helper_realloc@plt>
cltq
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/aweeraman/debian-copyfs/refs/heads/master/helper.c\00"
@__func__.helper_extract_dirname = [23 x i8] c"helper_extract_dirname\00"
define i8* @helper_extract_dirname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 (i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @helper_strdup to i32 (i8*, i8*, i32, i8*, ...)*)(i8* %5, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 322, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.helper_extract_dirname, i64 0, i64 0))
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @rindex(i8* %9, i32 47)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i8*, i8** %4
store i8 0, i8* %14
br label %17
15: ; preds = %1
%16 = load i8*, i8** %3
store i8 0, i8* %16
br label %17
17: ; preds = %15, %13
%18 = load i8*, i8** %3
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = add i64 %20, 1
%22 = call i32 (i8*, i64, i8*, i32, i8*, ...) bitcast (i32 (...)* @helper_realloc to i32 (i8*, i64, i8*, i32, i8*, ...)*)(i8* %18, i64 %21, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 328, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.helper_extract_dirname, i64 0, i64 0))
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
ret i8* %24
}

LLVM IR (-O2):
@.str = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/aweeraman/debian-copyfs/refs/heads/master/helper.c\00"
@__func__.helper_extract_dirname = [23 x i8] c"helper_extract_dirname\00"
define i8* @helper_extract_dirname(i8* %0) {
%2 = tail call i32 (i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @helper_strdup to i32 (i8*, i8*, i32, i8*, ...)*)(i8* %0, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 322, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.helper_extract_dirname, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = inttoptr i64 %3 to i8*
%5 = tail call i8* @rindex(i8* %4, i32 47)
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* %4, i8* %5
store i8 0, i8* %7
%8 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%9 = add i64 %8, 1
%10 = tail call i32 (i8*, i64, i8*, i32, i8*, ...) bitcast (i32 (...)* @helper_realloc to i32 (i8*, i64, i8*, i32, i8*, ...)*)(i8* %4, i64 %9, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 328, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.helper_extract_dirname, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
ret i8* %12
}