#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 remove_extension(char *ext_filename, char *filename) {
  char *pstr = NULL;
  int ext_pos = 0;
  if (ext_filename == NULL || filename == NULL)
    return -1;
  pstr = strrchr(ext_filename, '.');
  if (pstr == NULL || pstr == ext_filename) {
    strcpy(filename, "");
    return -1;
  }
  ext_pos = pstr - ext_filename;
  if (ext_pos <= 0) {
    strcpy(filename, "");
    return -1;
  }
  strcpy(filename, ext_filename);
  filename[ext_pos] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<remove_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1155 <remove_extension+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    1161 <remove_extension+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <remove_extension+0xdc>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118c <remove_extension+0x6c>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11a8 <remove_extension+0x88>
mov    -0x18(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <remove_extension+0xdc>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     11dc <remove_extension+0xbc>
mov    -0x18(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <remove_extension+0xdc>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_extension>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     117f <remove_extension+0x5f>
mov    %rsi,%r15
test   %rsi,%rsi
je     117f <remove_extension+0x5f>
mov    %rdi,%rbp
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1170 <remove_extension+0x50>
mov    %rax,%rbx
sub    %rbp,%rbx
je     1170 <remove_extension+0x50>
test   %ebx,%ebx
jle    1170 <remove_extension+0x50>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
xor    %r14d,%r14d
jmp    117f <remove_extension+0x5f>
lea    0xe89(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @remove_extension(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%8 = icmp eq i8* %7, null
%9 = icmp eq i8* %7, %0
%10 = or i1 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %26
13: ; preds = %6
%14 = ptrtoint i8* %7 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %26
21: ; preds = %13
%22 = tail call i32 @strcpy(i8* %1, i8* %0)
%23 = shl i64 %16, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %2, %21, %19, %11
%27 = phi i32 [ -1, %11 ], [ -1, %19 ], [ 0, %21 ], [ -1, %2 ]
ret i32 %27
}