#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 *);
int strlen(char *);
char *get_dir_name_from_path(char *in) {
  static char ret[1000];
  strcpy(ret, in);
  int i = 0;
  for (i = strlen(in); i > 0; i--) {
    if (in[i] == '/') {
      ret[i] = 0;
      return ret;
    }
  }
  strcpy(ret, "");
  return ret;
}


x86 assembly (clang, -O0):
<get_dir_name_from_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2f09(%rip),%rdi
call   1030 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11a0 <get_dir_name_from_path+0x80>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    118d <get_dir_name_from_path+0x6d>
movslq -0x14(%rbp),%rcx
lea    0x2ec7(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ebc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11be <get_dir_name_from_path+0x9e>
jmp    1192 <get_dir_name_from_path+0x72>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <get_dir_name_from_path+0x2f>
lea    0x2e99(%rip),%rdi
lea    0xe52(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x2e86(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dir_name_from_path>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x2f12(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1167 <get_dir_name_from_path+0x47>
mov    %eax,%ecx
add    %rcx,%rbx
nopw   0x0(%rax,%rax,1)
mov    %eax,%ecx
cmpb   $0x2f,(%r14,%rcx,1)
je     117c <get_dir_name_from_path+0x5c>
lea    -0x1(%rax),%ecx
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%eax
mov    %ecx,%eax
jg     1150 <get_dir_name_from_path+0x30>
lea    0x2ed2(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    117f <get_dir_name_from_path+0x5f>
movb   $0x0,(%rbx)
lea    0x2eba(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@get_dir_name_from_path.ret = internal global [1000 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @get_dir_name_from_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strcpy(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 0), i8* %5)
store i32 0, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
br label %9
9: ; preds = %25, %1
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, 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 = %12
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 %22
store i8 0, i8* %23
store i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 0), i8** %2
br label %30
24: ; preds = %12
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
br label %9
28: ; preds = %9
%29 = call i32 @strcpy(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 0), i8** %2
br label %30
30: ; preds = %28, %20
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@get_dir_name_from_path.ret = internal global [1000 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @get_dir_name_from_path(i8* %0) {
%2 = tail call i32 @strcpy(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 0), i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %1, %14
%6 = phi i32 [ %15, %14 ], [ %3, %1 ]
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = zext i32 %6 to i64
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 %12
store i8 0, i8* %13
br label %19
14: ; preds = %5
%15 = add nsw i32 %6, -1
%16 = icmp sgt i32 %6, 1
br i1 %16, label %5, label %17
17: ; preds = %14, %1
%18 = tail call i32 @strcpy(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
ret i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_dir_name_from_path.ret, i64 0, i64 0)
}