#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;
  if (string == NULL)
    return -1;
  pstr = strrchr(string, '.');
  if (pstr == NULL) {
    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)
cmpq   $0x0,-0x18(%rbp)
jne    114f <get_extension+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <get_extension+0x80>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1188 <get_extension+0x68>
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <get_extension+0x80>
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    $0xffffffff,%ebx
test   %rsi,%rsi
je     1165 <get_extension+0x45>
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1156 <get_extension+0x36>
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %ebx,%ebx
jmp    1165 <get_extension+0x45>
lea    0xea3(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %ebx,%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 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %23
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i8* @strrchr(i8* %11, i8 signext 46)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%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 = %10
%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, %9
%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 = icmp eq i8* %1, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call i8* @strrchr(i8* %1, i8 signext 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%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 = %4
%10 = getelementptr inbounds i8, i8* %5, i64 1
%11 = tail call i32 @strcpy(i8* %0, i8* %10)
br label %12
12: ; preds = %2, %9, %7
%13 = phi i32 [ -1, %7 ], [ 0, %9 ], [ -1, %2 ]
ret i32 %13
}