#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 *, int);
char *strrchr(char const *, char);
int os_rGetSuffix(char const *path, char *buf, int size) {
  char *dp;
  char *sp;
  buf[0] = 0;
  if (!path)
    return 0;
  sp = strrchr(path, '/');
  dp = strrchr(path, '.');
  if (!dp)
    return 0;
  if (sp != NULL && sp + 1 >= dp)
    return 0;
  strncpy(buf, dp, size);
  buf[size - 1] = 0;
  return strlen(buf);
}


x86 assembly (clang, -O0):
<os_rGetSuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1161 <os_rGetSuffix+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <os_rGetSuffix+0xc2>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119c <os_rGetSuffix+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <os_rGetSuffix+0xc2>
cmpq   $0x0,-0x30(%rbp)
je     11c5 <os_rGetSuffix+0x95>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
cmp    -0x28(%rbp),%rax
jb     11c5 <os_rGetSuffix+0x95>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <os_rGetSuffix+0xc2>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_rGetSuffix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movb   $0x0,(%rsi)
test   %rdi,%rdi
je     1175 <os_rGetSuffix+0x45>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1175 <os_rGetSuffix+0x45>
test   %rbp,%rbp
je     1182 <os_rGetSuffix+0x52>
add    $0x1,%rbp
cmp    %rax,%rbp
jb     1182 <os_rGetSuffix+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movslq %r14d,%rax
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strlen@plt>

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

LLVM IR (-O2):
define i32 @os_rGetSuffix(i8* %0, i8* %1, i32 %2) {
store i8 0, i8* %1
%4 = icmp eq i8* %0, null
br i1 %4, label %20, label %5
5: ; preds = %3
%6 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%7 = tail call i8* @strrchr(i8* %0, i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %20, label %9
9: ; preds = %5
%10 = icmp eq i8* %6, null
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = icmp ult i8* %11, %7
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = tail call i32 @strncpy(i8* %1, i8* %7, i32 %2)
%16 = add nsw i32 %2, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 0, i8* %18
%19 = tail call i32 @strlen(i8* %1)
br label %20
20: ; preds = %9, %5, %3, %14
%21 = phi i32 [ %19, %14 ], [ 0, %3 ], [ 0, %5 ], [ 0, %9 ]
ret i32 %21
}