#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*/ strlen(char *);
char *strrchr(char *, char);
char *substr(char *, int, int /*<<< orphan*/);
char *GetSuffix(char *fileName) {
  char *ptr, c = '.';
  int pos;
  char *temps = "F:\\workspace\\zhoulu.wmv.ppt";
  if (!fileName)
    fileName = temps;
  ptr = strrchr(fileName, c);
  if (ptr == 0)
    return NULL;
  pos = ptr - fileName;
  return substr(fileName, pos + 1, strlen(fileName));
}


x86 assembly (clang, -O0):
<GetSuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x2e,-0x19(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115e <GetSuffix+0x2e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <GetSuffix+0x57>
movq   $0x0,-0x8(%rbp)
jmp    11c1 <GetSuffix+0x91>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
call   1040 <substr@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetSuffix>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
lea    0xec2(%rip),%r14
cmovne %rdi,%r14
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1178 <GetSuffix+0x48>
mov    %rax,%rbx
sub    %r14d,%ebx
add    $0x1,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <substr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"F:\\workspace\\zhoulu.wmv.ppt\00"
define i8* @GetSuffix(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8 46, i8* %5
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = load i8*, i8** %7
store i8* %11, i8** %3
br label %12
12: ; preds = %10, %1
%13 = load i8*, i8** %3
%14 = load i8, i8* %5
%15 = call i8* @strrchr(i8* %13, i8 signext %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
store i8* null, i8** %2
br label %32
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %6
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = call i8* @substr(i8* %26, i32 %28, i32 %30)
store i8* %31, i8** %2
br label %32
32: ; preds = %19, %18
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
@.str = [28 x i8] c"F:\\workspace\\zhoulu.wmv.ppt\00"
define i8* @GetSuffix(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %3 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = add nsw i32 %10, 1
%12 = tail call i32 @strlen(i8* %3)
%13 = tail call i8* @substr(i8* %3, i32 %11, i32 %12)
br label %14
14: ; preds = %1, %6
%15 = phi i8* [ %13, %6 ], [ null, %1 ]
ret i8* %15
}