#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *strrchr(char const *, char);
int get_name_from_path(const char *path, char *name, size_t size) {
  char *p1, *p2, *p;
  p1 = strrchr(path, '/');
  p2 = strrchr(path, '\\');
  if (p1 == NULL && p2 == NULL) {
    strncpy(name, path, size);
    return strlen(name);
  }
  p = ((p1) > (p2) ? (p1) : (p2)) + 1;
  strncpy(name, p, size);
  return strlen(name);
}


x86 assembly (clang, -O0):
<get_name_from_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a0 <get_name_from_path+0x70>
cmpq   $0x0,-0x30(%rbp)
jne    11a0 <get_name_from_path+0x70>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11ec <get_name_from_path+0xbc>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    11bb <get_name_from_path+0x8b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11c3 <get_name_from_path+0x93>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_name_from_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rbx,%rcx
or     %rax,%rcx
jne    116b <get_name_from_path+0x3b>
mov    %r15,%rdi
mov    %r12,%rsi
jmp    117c <get_name_from_path+0x4c>
cmp    %rax,%rbx
cmova  %rbx,%rax
add    $0x1,%rax
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strlen@plt>

LLVM IR (-O0):
define i32 @get_name_from_path(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i8*, i8** %5
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %8
%13 = load i8*, i8** %5
%14 = call i8* @strrchr(i8* %13, i8 signext 92)
store i8* %14, i8** %9
%15 = load i8*, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %27
17: ; preds = %3
%18 = load i8*, i8** %9
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = load i64, i64* %7
%24 = call i32 @strncpy(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
store i32 %26, i32* %4
br label %44
27: ; preds = %17, %3
%28 = load i8*, i8** %8
%29 = load i8*, i8** %9
%30 = icmp ugt i8* %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i8*, i8** %8
br label %35
33: ; preds = %27
%34 = load i8*, i8** %9
br label %35
35: ; preds = %33, %31
%36 = phi i8* [ %32, %31 ], [ %34, %33 ]
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** %10
%38 = load i8*, i8** %6
%39 = load i8*, i8** %10
%40 = load i64, i64* %7
%41 = call i32 @strncpy(i8* %38, i8* %39, i64 %40)
%42 = load i8*, i8** %6
%43 = call i32 @strlen(i8* %42)
store i32 %43, i32* %4
br label %44
44: ; preds = %35, %20
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
define i32 @get_name_from_path(i8* %0, i8* %1, i64 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%6 = icmp eq i8* %4, null
%7 = icmp eq i8* %5, null
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @strncpy(i8* %1, i8* %0, i64 %2)
br label %16
11: ; preds = %3
%12 = icmp ugt i8* %4, %5
%13 = select i1 %12, i8* %4, i8* %5
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = tail call i32 @strncpy(i8* %1, i8* %14, i64 %2)
br label %16
16: ; preds = %11, %9
%17 = tail call i32 @strlen(i8* %1)
ret i32 %17
}