#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 */
typedef int /*<<< orphan*/ uint;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char const *);
char const *strncpy(char *, char const *, int /*<<< orphan*/);
int file_path_file(const char *src, char *dst, uint sz) {
  if (strlen(src) == 0)
    return 1;
  memset(dst, 0, sz);
  int len = strlen(strncpy(dst, src, sz));
  if (!strcmp(dst, "/"))
    return 0;
  for (; dst[len - 1] == '/' && len - 1 >= 0; len--)
    dst[len - 1] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<file_path_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    1171 <file_path_file+0x31>
movl   $0x1,-0x4(%rbp)
jmp    1228 <file_path_file+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11bf <file_path_file+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    1228 <file_path_file+0xe8>
jmp    11c4 <file_path_file+0x84>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x21(%rbp)
jne    11f2 <file_path_file+0xb2>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
setge  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1202 <file_path_file+0xc2>
jmp    1221 <file_path_file+0xe1>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11c4 <file_path_file+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_path_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <strlen@plt>
test   %eax,%eax
je     11cc <file_path_file+0x8c>
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11d2 <file_path_file+0x92>
movslq %ebp,%rax
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    11d2 <file_path_file+0x92>
test   %ebp,%ebp
jle    11d2 <file_path_file+0x92>
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
mov    %ebp,%eax
add    $0xfffffffffffffffe,%rbx
movb   $0x0,(%rcx)
cmpb   $0x2f,(%rbx,%rax,1)
jne    11d2 <file_path_file+0x92>
lea    (%rbx,%rax,1),%rcx
lea    -0x1(%rax),%rdx
cmp    $0x1,%rax
mov    %rdx,%rax
jne    11b0 <file_path_file+0x70>
jmp    11d2 <file_path_file+0x92>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @file_path_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%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 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 1, i32* %4
br label %52
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = load i32, i32* %7
%20 = call i8* @strncpy(i8* %17, i8* %18, i32 %19)
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %8
%22 = load i8*, i8** %6
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %13
store i32 0, i32* %4
br label %52
26: ; preds = %13
br label %27
27: ; preds = %48, %26
%28 = load i8*, i8** %6
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %40
36: ; preds = %27
%37 = load i32, i32* %8
%38 = sub nsw i32 %37, 1
%39 = icmp sge i32 %38, 0
br label %40
40: ; preds = %36, %27
%41 = phi i1 [ false, %27 ], [ %39, %36 ]
br i1 %41, label %42, label %51
42: ; preds = %40
%43 = load i8*, i8** %6
%44 = load i32, i32* %8
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 0, i8* %47
br label %48
48: ; preds = %42
%49 = load i32, i32* %8
%50 = add nsw i32 %49, -1
store i32 %50, i32* %8
br label %27
51: ; preds = %40
store i32 0, i32* %4
br label %52
52: ; preds = %51, %25, %12
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @file_path_file(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %32, label %6
6: ; preds = %3
%7 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
%8 = tail call i8* @strncpy(i8* %1, i8* %0, i32 %2)
%9 = tail call i32 @strlen(i8* %8)
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %6
%13 = add nsw i32 %9, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
%18 = icmp sgt i32 %9, 0
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %20, label %32
20: ; preds = %12
%21 = zext i32 %9 to i64
%22 = add nsw i64 %21, -1
br label %23
23: ; preds = %20, %23
%24 = phi i64 [ %22, %20 ], [ %26, %23 ]
%25 = phi i8* [ %15, %20 ], [ %27, %23 ]
store i8 0, i8* %25
%26 = add nsw i64 %24, -1
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 47
%30 = icmp ne i64 %24, 0
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %23, label %32
32: ; preds = %23, %12, %6, %3
%33 = phi i32 [ 1, %3 ], [ 0, %6 ], [ 0, %12 ], [ 0, %23 ]
ret i32 %33
}