#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*/ strcpy(char *, char *);
char *strrchr(char *, char);
int get_extension(char *extension, char *string) {
  char *pstr = NULL;
  pstr = strrchr(string, '.');
  if (pstr == NULL || pstr == string) {
    strcpy(extension, "");
    return -1;
  }
  strcpy(extension, pstr + 1);
  return 0;
}


x86 assembly (clang, -O0):
<get_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1163 <get_extension+0x43>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    117f <get_extension+0x5f>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <get_extension+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_extension>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1154 <get_extension+0x34>
cmp    %rbx,%rax
je     1154 <get_extension+0x34>
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    1168 <get_extension+0x48>
lea    0xea5(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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