#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*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
void getroot(char *filespc, char *filroot) {
  char *str;
  strcpy(filroot, filespc);
  while (str = strrchr(filroot, '.')) {
    if (!strcmp(str, ".rec"))
      *str = '\0';
    else if (!strcmp(str, ".dat"))
      *str = '\0';
    else if (!strcmp(str, ".txt"))
      *str = '\0';
    else if (!strcmp(str, ".lst"))
      *str = '\0';
    else
      break;
  }
}


x86 assembly (clang, -O0):
<getroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1216 <getroot+0xe6>
mov    -0x18(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    118e <getroot+0x5e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1211 <getroot+0xe1>
mov    -0x18(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b3 <getroot+0x83>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    120c <getroot+0xdc>
mov    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11d8 <getroot+0xa8>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1207 <getroot+0xd7>
mov    -0x18(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11fd <getroot+0xcd>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1202 <getroot+0xd2>
jmp    1216 <getroot+0xe6>
jmp    1207 <getroot+0xd7>
jmp    120c <getroot+0xdc>
jmp    1211 <getroot+0xe1>
jmp    114d <getroot+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getroot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11d4 <getroot+0xa4>
mov    %rax,%rbx
lea    0xe9b(%rip),%r14
lea    0xe99(%rip),%r12
lea    0xe97(%rip),%r13
lea    0xe95(%rip),%rbp
jmp    1198 <getroot+0x68>
nopl   0x0(%rax)
movb   $0x0,(%rbx)
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d4 <getroot+0xa4>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <getroot+0x50>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <getroot+0x50>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <getroot+0x50>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <getroot+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".rec\00"
@.str.1 = [5 x i8] c".dat\00"
@.str.2 = [5 x i8] c".txt\00"
@.str.3 = [5 x i8] c".lst\00"
define void @getroot(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 = load i8*, i8** %3
%8 = call i32 @strcpy(i8* %6, i8* %7)
br label %9
9: ; preds = %41, %2
%10 = load i8*, i8** %4
%11 = call i8* @strrchr(i8* %10, i8 signext 46)
store i8* %11, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %42
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = load i8*, i8** %5
store i8 0, i8* %18
br label %41
19: ; preds = %13
%20 = load i8*, i8** %5
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = load i8*, i8** %5
store i8 0, i8* %24
br label %40
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = load i8*, i8** %5
store i8 0, i8* %30
br label %39
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = load i8*, i8** %5
store i8 0, i8* %36
br label %38
37: ; preds = %31
br label %42
38: ; preds = %35
br label %39
39: ; preds = %38, %29
br label %40
40: ; preds = %39, %23
br label %41
41: ; preds = %40, %17
br label %9
42: ; preds = %37, %9
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".rec\00"
@.str.1 = [5 x i8] c".dat\00"
@.str.2 = [5 x i8] c".txt\00"
@.str.3 = [5 x i8] c".lst\00"
define void @getroot(i8* %0, i8* %1) {
%3 = tail call i32 @strcpy(i8* %1, i8* %0)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %2, %19
%7 = phi i8* [ %20, %19 ], [ %4, %2 ]
%8 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16, %13, %10, %6
store i8 0, i8* %7
%20 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %6
22: ; preds = %19, %16, %2
ret void
}