#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*/ __is_delimiter(char const);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void extract_directory(const char *path, char *dir) {
  int r = strlen(path) - 1;
  while (r > 0 && !__is_delimiter(path[r]))
    --r;
  strncpy(dir, path, r);
  dir[r] = 0;
}


x86 assembly (clang, -O0):
<extract_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jle    117a <extract_directory+0x4a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <__is_delimiter@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    118a <extract_directory+0x5a>
jmp    1198 <extract_directory+0x68>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <extract_directory+0x1f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_directory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%r12d
add    $0xffffffff,%r12d
lea    (%r12,%r15,1),%rbp
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%ebx
mov    %rdx,%r13
cmp    $0x2,%eax
jl     1182 <extract_directory+0x52>
movsbl 0x0(%rbp,%r13,1),%edi
call   1040 <__is_delimiter@plt>
mov    %eax,%ecx
lea    -0x1(%rbx),%eax
lea    -0x1(%r13),%rdx
test   %ecx,%ecx
je     1160 <extract_directory+0x30>
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %r12d,%rax
add    %r14,%rax
movb   $0x0,0x0(%r13,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @extract_directory(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %5
br label %9
9: ; preds = %23, %2
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @__is_delimiter(i8 signext %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br label %21
21: ; preds = %12, %9
%22 = phi i1 [ false, %9 ], [ %20, %12 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* %5
%25 = add nsw i32 %24, -1
store i32 %25, i32* %5
br label %9
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = call i32 @strncpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
ret void
}

LLVM IR (-O2):
define void @extract_directory(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = zext i32 %3 to i64
br label %5
5: ; preds = %10, %2
%6 = phi i64 [ %7, %10 ], [ %4, %2 ]
%7 = add nsw i64 %6, -1
%8 = trunc i64 %6 to i32
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = and i64 %7, 4294967295
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @__is_delimiter(i8 signext %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %5, label %16
16: ; preds = %5, %10
%17 = trunc i64 %7 to i32
%18 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %17)
%19 = shl i64 %7, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
ret void
}