#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*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
int hasdirectory(char *source, char *result) {
  char *tp2;
  if ((tp2 = strrchr(source, '/')) == NULL)
    return (0);
  strncpy(result, source, tp2 - source + 1);
  result[tp2 - source + 1] = '\0';
  return (1);
}


x86 assembly (clang, -O0):
<hasdirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1158 <hasdirectory+0x38>
movl   $0x0,-0x4(%rbp)
jmp    1191 <hasdirectory+0x71>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hasdirectory>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     115c <hasdirectory+0x3c>
mov    %rax,%rbx
sub    %r15,%rbx
lea    0x1(%rbx),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
movb   $0x0,0x1(%r14,%rbx,1)
mov    $0x1,%eax
jmp    115e <hasdirectory+0x3e>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @hasdirectory(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %30
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = add nsw i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i32 @strncpy(i8* %12, i8* %13, i32 %20)
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = load i8*, i8** %4
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = add nsw i64 %27, 1
%29 = getelementptr inbounds i8, i8* %22, i64 %28
store i8 0, i8* %29
store i32 1, i32* %3
br label %30
30: ; preds = %11, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @hasdirectory(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = add nsw i64 %8, 1
%10 = trunc i64 %9 to i32
%11 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %10)
%12 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %12
br label %13
13: ; preds = %2, %5
%14 = phi i32 [ 1, %5 ], [ 0, %2 ]
ret i32 %14
}