#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*/ strcat(char *, char *);
int strlen(char *);
void _path_tail(char *buf, char *name) {
  int flag = 1;
  int i = 0;
  if ((strlen(buf) + strlen(name)) >= 4096) {
    flag = 0;
  }
  for (i = strlen(buf); i >= 0; i--) {
    if (buf[i] == '/') {
      buf[i] = '\0';
      break;
    }
  }
  if (flag) {
    strcat(buf, name);
  }
}


x86 assembly (clang, -O0):
<_path_tail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cmp    $0x1000,%eax
jl     116c <_path_tail+0x4c>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11bb <_path_tail+0x9b>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11a8 <_path_tail+0x88>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11bb <_path_tail+0x9b>
jmp    11ad <_path_tail+0x8d>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1178 <_path_tail+0x58>
cmpl   $0x0,-0x14(%rbp)
je     11d2 <_path_tail+0xb2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_path_tail>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
add    %ebp,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     1175 <_path_tail+0x55>
mov    %eax,%ecx
add    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edx
cmpb   $0x2f,(%rbx,%rdx,1)
je     1189 <_path_tail+0x69>
lea    -0x1(%rax),%edx
add    $0xffffffffffffffff,%rcx
test   %eax,%eax
mov    %edx,%eax
jg     1160 <_path_tail+0x40>
cmp    $0xfff,%r15d
jle    1195 <_path_tail+0x75>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,(%rcx)
cmp    $0xfff,%r15d
jg     117e <_path_tail+0x5e>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strcat@plt>

LLVM IR (-O0):
define void @_path_tail(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 1, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = icmp sge i32 %11, 4096
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %5
br label %14
14: ; preds = %13, %2
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %34, %14
%18 = load i32, i32* %6
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
br label %37
33: ; preds = %20
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, -1
store i32 %36, i32* %6
br label %17
37: ; preds = %28, %17
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i8*, i8** %3
%42 = load i8*, i8** %4
%43 = call i32 @strcat(i8* %41, i8* %42)
br label %44
44: ; preds = %40, %37
ret void
}

LLVM IR (-O2):
define void @_path_tail(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = icmp sgt i32 %5, 4095
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %21
9: ; preds = %2, %18
%10 = phi i32 [ %19, %18 ], [ %7, %2 ]
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = zext i32 %10 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
br label %21
18: ; preds = %9
%19 = add nsw i32 %10, -1
%20 = icmp sgt i32 %10, 0
br i1 %20, label %9, label %21
21: ; preds = %18, %2, %15
br i1 %6, label %24, label %22
22: ; preds = %21
%23 = tail call i32 @strcat(i8* %0, i8* %1)
br label %24
24: ; preds = %22, %21
ret void
}