#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 */
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *strrchr(char const *, char);
int find_png_filename(const char *filename, char *o_f) {
  const char *nstart = filename;
  char *x = strrchr(filename, '/');
  if (x)
    nstart = x + 1;
  else {
    x = strrchr(filename, '\\');
    if (x)
      nstart = x + 1;
  }
  size_t strl = strlen(nstart);
  char *d = strrchr(filename, '.');
  if (d)
    strl = (d - nstart);
  strncpy(o_f, nstart, (strl < 8) ? strl : 8);
  return strl;
}


x86 assembly (clang, -O0):
<find_png_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1176 <find_png_filename+0x46>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a4 <find_png_filename+0x74>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119f <find_png_filename+0x6f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a4 <find_png_filename+0x74>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11dd <find_png_filename+0xad>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x8,-0x28(%rbp)
jae    1205 <find_png_filename+0xd5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1213 <find_png_filename+0xe3>
mov    $0x8,%eax
mov    %rax,-0x48(%rbp)
jmp    1213 <find_png_filename+0xe3>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_png_filename>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1157 <find_png_filename+0x27>
mov    %rax,%r13
add    $0x1,%r13
jmp    116f <find_png_filename+0x3f>
mov    %r15,%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%r13
test   %rax,%rax
cmove  %r15,%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
sub    %r13,%rbx
test   %rax,%rax
cmove  %r12,%rbx
cmp    $0x8,%rbx
mov    $0x8,%edx
cmovb  %rbx,%rdx
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <strncpy@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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