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


x86 assembly (clang, -O0):
<file_namestring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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     116f <file_namestring+0x3f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117f <file_namestring+0x4f>
jmp    1192 <file_namestring+0x62>
jmp    1184 <file_namestring+0x54>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <file_namestring+0x1b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11dd <file_namestring+0xad>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
xor    %edx,%edx
call   1050 <subseq@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
lea    0xe37(%rip),%rdx
mov    $0x46,%ecx
call   1030 <s_internal@plt>
jmp    11e5 <file_namestring+0xb5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_namestring>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %esi,%esi
test   %eax,%eax
cmovs  %eax,%esi
lea    -0x1(%rsi),%eax
nopl   0x0(%rax,%rax,1)
test   %ecx,%ecx
jle    1165 <file_namestring+0x35>
add    $0xffffffffffffffff,%rcx
mov    %ecx,%edx
cmpb   $0x2f,(%rbx,%rdx,1)
jne    1150 <file_namestring+0x20>
lea    0x1(%rcx),%esi
mov    %ecx,%eax
cltq
cmpb   $0x2f,(%rbx,%rax,1)
jne    119a <file_namestring+0x6a>
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <subseq@plt>
mov    %rax,%r14
lea    0xe7f(%rip),%rsi
lea    0xe7d(%rip),%rdx
mov    %rbx,%rdi
mov    $0x46,%ecx
call   1030 <s_internal@plt>
mov    %r14,%rax
jmp    119d <file_namestring+0x6d>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"path\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/guicho271828/roswell/refs/heads/master/src/util_dir.c\00"
define i8* @file_namestring(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 = %22, %1
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %19
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 = icmp ne i32 %17, 47
br label %19
19: ; preds = %11, %8
%20 = phi i1 [ false, %8 ], [ %18, %11 ]
br i1 %20, label %21, label %25
21: ; preds = %19
br label %22
22: ; preds = %21
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
store i32 %24, i32* %3
br label %8
25: ; preds = %19
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %40
33: ; preds = %25
%34 = load i8*, i8** %2
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
%37 = call i8* @subseq(i8* %34, i32 %36, i32 0)
store i8* %37, i8** %4
%38 = load i8*, i8** %2
%39 = call i32 @s_internal(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 70)
br label %42
40: ; preds = %25
%41 = load i8*, i8** %2
store i8* %41, i8** %4
br label %42
42: ; preds = %40, %33
%43 = load i8*, i8** %4
ret i8* %43
}

LLVM IR (-O2):
@.str = [5 x i8] c"path\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/guicho271828/roswell/refs/heads/master/src/util_dir.c\00"
define i8* @file_namestring(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
%4 = call i32 @llvm.smin.i32(i32 %2, i32 0)
%5 = add i32 %4, -1
br label %6
6: ; preds = %11, %1
%7 = phi i64 [ %8, %11 ], [ %3, %1 ]
%8 = add nsw i64 %7, -1
%9 = trunc i64 %7 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = and i64 %8, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %6
16: ; preds = %11
%17 = trunc i64 %7 to i32
%18 = trunc i64 %8 to i32
br label %19
19: ; preds = %6, %16
%20 = phi i32 [ %17, %16 ], [ %4, %6 ]
%21 = phi i32 [ %18, %16 ], [ %5, %6 ]
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 47
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = tail call i8* @subseq(i8* %0, i32 %20, i32 0)
%28 = tail call i32 @s_internal(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 70)
br label %29
29: ; preds = %19, %26
%30 = phi i8* [ %27, %26 ], [ %0, %19 ]
ret i8* %30
}