#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*/ strncpy(char *, char *, size_t);
char *strrchr(char const *, char);
int dcs_fileext(const char *filename, char *extbuf, size_t extbuflen) {
  if (filename == NULL || extbuf == NULL || extbuflen == 0)
    return -1;
  char *lastdot = strrchr(filename, '.');
  if (lastdot == NULL) {
    strncpy(extbuf, "", extbuflen);
  } else {
    strncpy(extbuf, lastdot, extbuflen);
  }
  return 0;
}


x86 assembly (clang, -O0):
<dcs_fileext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1155 <dcs_fileext+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1155 <dcs_fileext+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    1161 <dcs_fileext+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <dcs_fileext+0x8f>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <dcs_fileext+0x77>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1030 <strncpy@plt>
jmp    11a8 <dcs_fileext+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dcs_fileext>:
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1169 <dcs_fileext+0x49>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1169 <dcs_fileext+0x49>
mov    %rdx,%r14
test   %rdx,%rdx
je     1169 <dcs_fileext+0x49>
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1155 <dcs_fileext+0x35>
mov    %rbx,%rdi
mov    %rax,%rsi
jmp    115f <dcs_fileext+0x3f>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @dcs_fileext(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i64, i64* %7
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %3
store i32 -1, i32* %4
br label %33
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i8* @strrchr(i8* %19, i8 signext 46)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i64, i64* %7
%26 = call i32 @strncpy(i8* %24, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64 %25)
br label %32
27: ; preds = %18
%28 = load i8*, i8** %6
%29 = load i8*, i8** %8
%30 = load i64, i64* %7
%31 = call i32 @strncpy(i8* %28, i8* %29, i64 %30)
br label %32
32: ; preds = %27, %23
store i32 0, i32* %4
br label %33
33: ; preds = %32, %17
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @dcs_fileext(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i64 %2, 0
%8 = or i1 %6, %7
br i1 %8, label %16, label %9
9: ; preds = %3
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64 %2)
br label %16
14: ; preds = %9
%15 = tail call i32 @strncpy(i8* %1, i8* %10, i64 %2)
br label %16
16: ; preds = %12, %14, %3
%17 = phi i32 [ -1, %3 ], [ 0, %14 ], [ 0, %12 ]
ret i32 %17
}