#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 *find_last_slash(char *);
char *path_default_slash();
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
void path_basedir(char *path) {
  if (strlen(path) < 2)
    return;
  char *last = find_last_slash(path);
  if (last)
    last[1] = '\0';
  else
    snprintf(path, 3, ".%s", path_default_slash());
}


x86 assembly (clang, -O0):
<path_basedir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jge    1163 <path_basedir+0x23>
jmp    11af <path_basedir+0x6f>
mov    -0x8(%rbp),%rdi
call   1030 <find_last_slash@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1188 <path_basedir+0x48>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11af <path_basedir+0x6f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <path_default_slash@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rcx
mov    $0x3,%esi
lea    0xe56(%rip),%rdx
call   1050 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_basedir>:
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     115f <path_basedir+0x1f>
mov    %rbx,%rdi
call   1030 <find_last_slash@plt>
test   %rax,%rax
je     1161 <path_basedir+0x21>
movb   $0x0,0x1(%rax)
pop    %rbx
ret
xor    %eax,%eax
call   1060 <path_default_slash@plt>
lea    0xe91(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %rax,%rcx
pop    %rbx
jmp    1050 <snprintf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c".%s\00"
define void @path_basedir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %8
7: ; preds = %1
br label %20
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i8* @find_last_slash(i8* %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8 0, i8* %15
br label %20
16: ; preds = %8
%17 = load i8*, i8** %2
%18 = call i8* (...) @path_default_slash()
%19 = call i32 @snprintf(i8* %17, i32 3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %7, %16, %13
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c".%s\00"
define void @path_basedir(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 2
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i8* @find_last_slash(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %8
br label %12
9: ; preds = %4
%10 = tail call i8* (...) @path_default_slash()
%11 = tail call i32 @snprintf(i8* %0, i32 3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %7, %9, %1
ret void
}