#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 *append_trail_slash(char *);
int /*<<< orphan*/ s_internal(char *, char *, char *, int);
int strlen(char *);
char *subseq(char *, int /*<<< orphan*/, int);
char *pathname_directory(char *path) {
  int i;
  char *ret;
  for (i = strlen(path) - 1; i >= 0 && path[i] != "/"[0]; --i)
    ;
  ret = (i >= 0) ? subseq(path, 0, i + 1) : append_trail_slash(".");
  (s_internal(path, "path",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/roswell/roswell/refs/heads/master/src/"
              "util-dir.c",
              96));
  return ret;
}


x86 assembly (clang, -O0):
<pathname_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x19(%rbp)
jl     1185 <pathname_directory+0x45>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xe83(%rip),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1195 <pathname_directory+0x55>
jmp    11a8 <pathname_directory+0x68>
jmp    119a <pathname_directory+0x5a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <pathname_directory+0x1b>
cmpl   $0x0,-0xc(%rbp)
jl     11cc <pathname_directory+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1060 <subseq@plt>
mov    %rax,-0x28(%rbp)
jmp    11dc <pathname_directory+0x9c>
lea    0xe2f(%rip),%rdi
call   1050 <append_trail_slash@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe15(%rip),%rsi
lea    0xe13(%rip),%rdx
mov    $0x60,%ecx
call   1030 <s_internal@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathname_directory>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%eax
xchg   %ax,%ax
test   %eax,%eax
jle    1171 <pathname_directory+0x31>
lea    -0x1(%rax),%rdx
cmpb   $0x2f,-0x1(%rbx,%rax,1)
mov    %rdx,%rax
jne    1150 <pathname_directory+0x10>
add    $0x1,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <subseq@plt>
jmp    117d <pathname_directory+0x3d>
lea    0xe88(%rip),%rdi
call   1050 <append_trail_slash@plt>
mov    %rax,%r14
lea    0xe7b(%rip),%rsi
lea    0xe79(%rip),%rdx
mov    %rbx,%rdi
mov    $0x60,%ecx
call   1030 <s_internal@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [5 x i8] c"path\00"
@.str.3 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/roswell/roswell/refs/heads/master/src/util-dir.c\00"
define i8* @pathname_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %3
br label %8
8: ; preds = %24, %1
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br label %21
21: ; preds = %11, %8
%22 = phi i1 [ false, %8 ], [ %20, %11 ]
br i1 %22, label %23, label %27
23: ; preds = %21
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
store i32 %26, i32* %3
br label %8
27: ; preds = %21
%28 = load i32, i32* %3
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
%34 = call i8* @subseq(i8* %31, i32 0, i32 %33)
br label %37
35: ; preds = %27
%36 = call i8* @append_trail_slash(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = phi i8* [ %34, %30 ], [ %36, %35 ]
store i8* %38, i8** %4
%39 = load i8*, i8** %2
%40 = call i32 @s_internal(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.3, i64 0, i64 0), i32 96)
%41 = load i8*, i8** %4
ret i8* %41
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c".\00"
@.str.2 = [5 x i8] c"path\00"
@.str.3 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/roswell/roswell/refs/heads/master/src/util-dir.c\00"
define i8* @pathname_directory(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
br label %4
4: ; preds = %9, %1
%5 = phi i64 [ %6, %9 ], [ %3, %1 ]
%6 = add nsw i64 %5, -1
%7 = trunc i64 %5 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %4
13: ; preds = %9
%14 = trunc i64 %5 to i32
%15 = tail call i8* @subseq(i8* %0, i32 0, i32 %14)
br label %18
16: ; preds = %4
%17 = tail call i8* @append_trail_slash(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = phi i8* [ %15, %13 ], [ %17, %16 ]
%20 = tail call i32 @s_internal(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.3, i64 0, i64 0), i32 96)
ret i8* %19
}