#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 strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char *, char);
void pyi_path_dirname(char *result, const char *path) {
  size_t len = 0;
  char *match = NULL;
  strncpy(result, path, strlen(path) + 1);
  len = strlen(result);
  if (result[len] == '/') {
    result[len] = '\0';
  }
  match = strrchr(result, '/');
  if (match != NULL) {
    *match = '\0';
  }
}


x86 assembly (clang, -O0):
<pyi_path_dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11ab <pyi_path_dirname+0x7b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cf <pyi_path_dirname+0x9f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pyi_path_dirname>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,(%rbx,%rax,1)
jne    1164 <pyi_path_dirname+0x34>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1179 <pyi_path_dirname+0x49>
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @pyi_path_dirname(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 1
%5 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %4)
%6 = tail call i32 @strlen(i8* %0)
%7 = sext 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 %12
11: ; preds = %2
store i8 0, i8* %8
br label %12
12: ; preds = %11, %2
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i8 0, i8* %13
br label %16
16: ; preds = %15, %12
ret void
}