#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 */
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int split(char const *, int /*<<< orphan*/ *, int *, int /*<<< orphan*/ *);
char *dirname_a(const char *path) {
  int dlen;
  int rc;
  char *d;
  rc = split(path, NULL, &dlen, NULL);
  if (rc < 0)
    return NULL;
  d = malloc(dlen + 1);
  if (d == NULL)
    return NULL;
  memcpy(d, path, dlen);
  d[dlen] = '\0';
  return d;
}


x86 assembly (clang, -O0):
<dirname_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x14(%rbp),%rdx
mov    %rcx,%rsi
call   1030 <split@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    116a <dirname_a+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <dirname_a+0x85>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <dirname_a+0x61>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <dirname_a+0x85>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirname_a>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xc(%rsp),%rdx
xor    %esi,%esi
xor    %ecx,%ecx
call   1030 <split@plt>
test   %eax,%eax
js     1181 <dirname_a+0x51>
mov    0xc(%rsp),%r15d
lea    0x1(%r15),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117f <dirname_a+0x4f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
movslq 0xc(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1181 <dirname_a+0x51>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @dirname_a(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @split(i8* %0, i32* null, i32* %2, i32* null)
%5 = icmp slt i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%9 = call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %6
%12 = call i32 @memcpy(i8* %9, i8* %0, i32 %7)
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %9, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %6, %1, %11
%17 = phi i8* [ %9, %11 ], [ null, %1 ], [ null, %6 ]
ret i8* %17
}