#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*/ error(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
void getDirName(char *path, char *pfx) {
  char *p;
  if (strlen(path) > 256) {
    error("load: path too long", -1);
    return;
  }
  strcpy(pfx, path);
  p = strrchr(pfx, '/');
  if (p == NULL)
    strcpy(pfx, ".");
  else
    *p = 0;
}


x86 assembly (clang, -O0):
<getDirName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x100,%eax
jle    117a <getDirName+0x3a>
lea    0xe95(%rip),%rdi
mov    $0xffffffff,%esi
call   1060 <error@plt>
jmp    11c0 <getDirName+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b9 <getDirName+0x79>
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c0 <getDirName+0x80>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDirName>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x101,%eax
jl     116e <getDirName+0x2e>
lea    0xea3(%rip),%rdi
mov    $0xffffffff,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <error@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1196 <getDirName+0x56>
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe77(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"load: path too long\00"
@.str.1 = [2 x i8] c".\00"
define void @getDirName(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = icmp sgt i32 %7, 256
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %24
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %4
%16 = call i8* @strrchr(i8* %15, i8 signext 47)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %24
22: ; preds = %11
%23 = load i8*, i8** %5
store i8 0, i8* %23
br label %24
24: ; preds = %9, %22, %19
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"load: path too long\00"
@.str.1 = [2 x i8] c".\00"
define void @getDirName(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 256
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %14
7: ; preds = %2
%8 = tail call i32 @strcpy(i8* %1, i8* %0)
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %14
13: ; preds = %7
store i8 0, i8* %9
br label %14
14: ; preds = %11, %13, %5
ret void
}