#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*/ strcpy(char *, char *);
char *strrchr(char *, char);
void file_dirname(char *dest, char *src) {
  char *p;
  strcpy(dest, ".");
  if (src && *src) {
    strcpy(dest, src);
    p = strrchr(dest, '/');
    if (p) {
      *p = 0;
    }
  }
}


x86 assembly (clang, -O0):
<file_dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x10(%rbp)
je     1191 <file_dirname+0x71>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1191 <file_dirname+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118c <file_dirname+0x6c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1191 <file_dirname+0x71>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_dirname>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xecf(%rip),%rsi
call   1030 <strcpy@plt>
test   %rbx,%rbx
je     1160 <file_dirname+0x40>
cmpb   $0x0,(%rbx)
je     1160 <file_dirname+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1160 <file_dirname+0x40>
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @file_dirname(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 @strcpy(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %3
%20 = call i8* @strrchr(i8* %19, i8 signext 47)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = load i8*, i8** %5
store i8 0, i8* %24
br label %25
25: ; preds = %23, %15
br label %26
26: ; preds = %25, %10, %2
ret void
}

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