#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*/ addendpath(char *);
int /*<<< orphan*/ delendpath(char *);
char *getfilename(char *);
int /*<<< orphan*/ strcpy(char *, char *);
void truncfilepath(char *path, int delend) {
  char *i = getfilename(path);
  if (i)
    *i = 0;
  if (delend) {
    delendpath(path);
    if (!path[0])
      strcpy(path, ".");
  } else
    addendpath(path);
}


x86 assembly (clang, -O0):
<truncfilepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getfilename@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116e <truncfilepath+0x2e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
je     11a3 <truncfilepath+0x63>
mov    -0x8(%rbp),%rdi
call   1050 <delendpath@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119e <truncfilepath+0x5e>
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11ac <truncfilepath+0x6c>
mov    -0x8(%rbp),%rdi
call   1060 <addendpath@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncfilepath>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <getfilename@plt>
test   %rax,%rax
je     1155 <truncfilepath+0x15>
movb   $0x0,(%rax)
test   %ebp,%ebp
je     116d <truncfilepath+0x2d>
mov    %rbx,%rdi
call   1050 <delendpath@plt>
cmpb   $0x0,(%rbx)
je     117b <truncfilepath+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <addendpath@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @truncfilepath(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i8* @getfilename(i8* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i8*, i8** %5
store i8 0, i8* %11
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call i32 @delendpath(i8* %16)
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %15
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %22, %15
br label %29
26: ; preds = %12
%27 = load i8*, i8** %3
%28 = call i32 @addendpath(i8* %27)
br label %29
29: ; preds = %26, %25
ret void
}

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