#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*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *get_dir(const char *abs_path) {
  static char dir[4096 + 1];
  size_t len, i;
  len = strlen(abs_path);
  strcpy(dir, abs_path);
  for (i = len - 1; i >= 0; i--) {
    if (dir[i] == '/') {
      dir[i + 1] = 0;
      break;
    }
  }
  return dir;
}


x86 assembly (clang, -O0):
<get_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x2efc(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jb     11a3 <get_dir+0x83>
mov    -0x18(%rbp),%rcx
lea    0x2ed5(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    118d <get_dir+0x6d>
mov    -0x18(%rbp),%rcx
lea    0x2ebd(%rip),%rax
movb   $0x0,0x1(%rax,%rcx,1)
jmp    11a3 <get_dir+0x83>
jmp    1192 <get_dir+0x72>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <get_dir+0x35>
lea    0x2e96(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dir>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%r14
lea    0x2f09(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    (%r14,%r15,1),%rax
add    $0x1,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x2f,-0x2(%rax)
lea    -0x1(%rax),%rax
jne    1150 <get_dir+0x30>
movb   $0x0,(%rax)
lea    0x2edc(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@get_dir.dir = internal global [4097 x i8] zeroinitializer
define i8* @get_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
store i64 %6, i64* %3
%7 = load i8*, i8** %2
%8 = call i32 @strcpy(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 0), i8* %7)
%9 = load i64, i64* %3
%10 = sub i64 %9, 1
store i64 %10, i64* %4
br label %11
11: ; preds = %25, %1
%12 = load i64, i64* %4
%13 = icmp uge i64 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i64, i64* %4
%16 = getelementptr inbounds [4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i64, i64* %4
%22 = add i64 %21, 1
%23 = getelementptr inbounds [4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 %22
store i8 0, i8* %23
br label %28
24: ; preds = %14
br label %25
25: ; preds = %24
%26 = load i64, i64* %4
%27 = add i64 %26, -1
store i64 %27, i64* %4
br label %11
28: ; preds = %20, %11
ret i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 0)
}

LLVM IR (-O2):
@get_dir.dir = internal global [4097 x i8] zeroinitializer
define i8* @get_dir(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i32 @strcpy(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 0), i8* %0)
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %2, %1 ], [ %6, %4 ]
%6 = add i64 %5, -1
%7 = getelementptr inbounds [4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = getelementptr inbounds [4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 %5
store i8 0, i8* %11
ret i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @get_dir.dir, i64 0, i64 0)
}