#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 */
scalar_t__ csc_isdelim(char *, char);
int /*<<< orphan*/ csc_strlcpy(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *csc_path_path(char *path, char *buffer, int blen) {
  int i;
  for (i = strlen(path) - 1; i >= 0; i--) {
    if (csc_isdelim("/", path[i])) {
      break;
    }
  }
  if (i >= 0) {
    i += 2;
    if (buffer) {
      csc_strlcpy(buffer, path, i > blen ? blen : i);
    }
    return path + i - 1;
  }
  if (buffer && (blen > 3)) {
    strcpy(buffer, ".");
    strcat(buffer, "/");
  }
  return path;
}


x86 assembly (clang, -O0):
<csc_path_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11b6 <csc_path_path+0x66>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xe75(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1060 <csc_isdelim@plt>
cmp    $0x0,%rax
je     11a3 <csc_path_path+0x53>
jmp    11b6 <csc_path_path+0x66>
jmp    11a8 <csc_path_path+0x58>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1172 <csc_path_path+0x22>
cmpl   $0x0,-0x20(%rbp)
jl     1229 <csc_path_path+0xd9>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1211 <csc_path_path+0xc1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11fb <csc_path_path+0xab>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1201 <csc_path_path+0xb1>
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
call   1050 <csc_strlcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1266 <csc_path_path+0x116>
cmpq   $0x0,-0x18(%rbp)
je     125e <csc_path_path+0x10e>
cmpl   $0x3,-0x1c(%rbp)
jle    125e <csc_path_path+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xda7(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csc_path_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe91(%rip),%r12
nop
test   %ebp,%ebp
jle    11b3 <csc_path_path+0x63>
movsbl -0x1(%rbx,%rbp,1),%esi
mov    %r12,%rdi
call   1060 <csc_isdelim@plt>
add    $0xffffffffffffffff,%rbp
test   %rax,%rax
je     1170 <csc_path_path+0x20>
add    $0x2,%rbp
test   %r14,%r14
je     11a8 <csc_path_path+0x58>
cmp    %r15d,%ebp
cmovle %ebp,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <csc_strlcpy@plt>
mov    %ebp,%eax
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
jmp    11dc <csc_path_path+0x8c>
test   %r14,%r14
je     11dc <csc_path_path+0x8c>
cmp    $0x4,%r15d
jl     11dc <csc_path_path+0x8c>
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe2c(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define i8* @csc_path_path(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %8
br label %12
12: ; preds = %25, %3
%13 = load i32, i32* %8
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i64 @csc_isdelim(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
br label %28
24: ; preds = %15
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, -1
store i32 %27, i32* %8
br label %12
28: ; preds = %23, %12
%29 = load i32, i32* %8
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %55
31: ; preds = %28
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 2
store i32 %33, i32* %8
%34 = load i8*, i8** %6
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %49
36: ; preds = %31
%37 = load i8*, i8** %6
%38 = load i8*, i8** %5
%39 = load i32, i32* %8
%40 = load i32, i32* %7
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = load i32, i32* %7
br label %46
44: ; preds = %36
%45 = load i32, i32* %8
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ %43, %42 ], [ %45, %44 ]
%48 = call i32 @csc_strlcpy(i8* %37, i8* %38, i32 %47)
br label %49
49: ; preds = %46, %31
%50 = load i8*, i8** %5
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = getelementptr inbounds i8, i8* %53, i64 -1
store i8* %54, i8** %4
br label %68
55: ; preds = %28
%56 = load i8*, i8** %6
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %66
58: ; preds = %55
%59 = load i32, i32* %7
%60 = icmp sgt i32 %59, 3
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load i8*, i8** %6
%63 = call i32 @strcpy(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%64 = load i8*, i8** %6
%65 = call i32 @strcat(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %66
66: ; preds = %61, %58, %55
%67 = load i8*, i8** %5
store i8* %67, i8** %4
br label %68
68: ; preds = %66, %49
%69 = load i8*, i8** %4
ret i8* %69
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define i8* @csc_path_path(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = zext i32 %4 to i64
br label %6
6: ; preds = %11, %3
%7 = phi i64 [ %8, %11 ], [ %5, %3 ]
%8 = add nsw i64 %7, -1
%9 = trunc i64 %7 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %0, i64 %8
%13 = load i8, i8* %12
%14 = tail call i64 @csc_isdelim(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %6, label %16
16: ; preds = %11
%17 = trunc i64 %7 to i32
%18 = add nuw nsw i32 %17, 1
%19 = icmp eq i8* %1, null
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = icmp sgt i32 %18, %2
%22 = select i1 %21, i32 %2, i32 %18
%23 = tail call i32 @csc_strlcpy(i8* %1, i8* %0, i32 %22)
br label %24
24: ; preds = %20, %16
%25 = zext i32 %18 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -1
br label %35
28: ; preds = %6
%29 = icmp ne i8* %1, null
%30 = icmp sgt i32 %2, 3
%31 = and i1 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %28, %32, %24
%36 = phi i8* [ %27, %24 ], [ %0, %32 ], [ %0, %28 ]
ret i8* %36
}