#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 *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
int stripext(char *fname, char *result) {
  char *chp;
  int LenExt;
  chp = strrchr(fname, '.');
  if (chp != NULL && chp != fname) {
    LenExt = strlen(fname) - strlen(chp);
    strncpy(result, fname, LenExt);
    return (LenExt);
  } else {
    strcpy(result, fname);
    return 0;
  }
}


x86 assembly (clang, -O0):
<stripext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b5 <stripext+0x75>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11b5 <stripext+0x75>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <stripext+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripext>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1187 <stripext+0x47>
mov    %rax,%rbx
cmp    %r15,%rax
je     1187 <stripext+0x47>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
sub    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
jmp    1194 <stripext+0x54>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @stripext(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
%8 = load i8*, i8** %4
%9 = call i8* @strrchr(i8* %8, i8 signext 46)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %27
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i8*, i8** %4
%15 = icmp ne i8* %13, %14
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %6
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %18, %20
store i32 %21, i32* %7
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = call i32 @strncpy(i8* %22, i8* %23, i32 %24)
%26 = load i32, i32* %7
store i32 %26, i32* %3
br label %31
27: ; preds = %12, %2
%28 = load i8*, i8** %5
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %28, i8* %29)
store i32 0, i32* %3
br label %31
31: ; preds = %27, %16
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @stripext(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
%5 = icmp eq i8* %3, %0
%6 = or i1 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i32 @strlen(i8* %3)
%10 = sub nsw i32 %8, %9
%11 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %10)
br label %14
12: ; preds = %2
%13 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %14
14: ; preds = %12, %7
%15 = phi i32 [ %10, %7 ], [ 0, %12 ]
ret i32 %15
}