#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 /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char tolower(char);
void strcpy_strip_ext(char *d, char *s) {
  char *tmp = strrchr(s, '.');
  if (!tmp) {
    strcpy(d, s);
    return;
  } else {
    strncpy(d, s, tmp - s);
    d[tmp - s] = 0;
  }
  while (*d) {
    *d = tolower(*d);
    d++;
  }
}


x86 assembly (clang, -O0):
<strcpy_strip_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <strcpy_strip_ext+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11e3 <strcpy_strip_ext+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11b1 <strcpy_strip_ext+0x71>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e3 <strcpy_strip_ext+0xa3>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <tolower@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <strcpy_strip_ext+0x71>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcpy_strip_ext>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     119c <strcpy_strip_ext+0x5c>
mov    %rax,%r15
sub    %r14,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r15,1)
mov    (%rbx),%al
test   %al,%al
je     1196 <strcpy_strip_ext+0x56>
add    $0x1,%rbx
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <strcpy_strip_ext+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

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

LLVM IR (-O2):
define void @strcpy_strip_ext(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %23
7: ; preds = %2
%8 = ptrtoint i8* %3 to i64
%9 = ptrtoint i8* %1 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %11)
%13 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %13
%14 = load i8, i8* %0
%15 = icmp eq i8 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %7, %16
%17 = phi i8 [ %21, %16 ], [ %14, %7 ]
%18 = phi i8* [ %20, %16 ], [ %0, %7 ]
%19 = tail call signext i8 @tolower(i8 signext %17)
store i8 %19, i8* %18
%20 = getelementptr inbounds i8, i8* %18, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %16
23: ; preds = %16, %7, %5
ret void
}