#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*/ PATH_MAX;
scalar_t__ calloc(int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
char *pyi_dirname(const char *fullpath) {
  char *match = strrchr(fullpath, '/');
  char *pathname = (char *)calloc(PATH_MAX, sizeof(char));
  ;
  if (match != NULL)
    strncpy(pathname, fullpath, match - fullpath + 1);
  else
    strcpy(pathname, fullpath);
  ;
  return pathname;
}


x86 assembly (clang, -O0):
<pyi_dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a3 <pyi_dirname+0x63>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    11b0 <pyi_dirname+0x70>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pyi_dirname>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1185 <pyi_dirname+0x45>
sub    %r15d,%ebx
add    $0x1,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
jmp    1190 <pyi_dirname+0x50>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@PATH_MAX = global i32 0
define i8* @pyi_dirname(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = load i32, i32* @PATH_MAX
%4 = tail call i64 @calloc(i32 %3, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i8* %2, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = ptrtoint i8* %2 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 1
%13 = tail call i32 @strncpy(i8* %5, i8* %0, i32 %12)
br label %16
14: ; preds = %1
%15 = tail call i32 @strcpy(i8* %5, i8* %0)
br label %16
16: ; preds = %14, %7
ret i8* %5
}