#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 *imgroot) {
  char *str;
  strcpy(imgroot, filespc);
  while ((str = strrchr(imgroot, '.'))) {
    if (!strcmp(str, ".rec"))
      *str = '\0';
    else if (!strcmp(str, ".img"))
      *str = '\0';
    else if (!strcmp(str, ".ifh"))
      *str = '\0';
    else if (!strcmp(str, ".4dfp"))
      *str = '\0';
    else if (!strcmp(str, ".hdr"))
      *str = '\0';
    else if (!strcmp(str, ".conc"))
      *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     126a <getroot+0x13a>
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    1265 <getroot+0x135>
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    1260 <getroot+0x130>
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    125b <getroot+0x12b>
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    1256 <getroot+0x126>
mov    -0x18(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1222 <getroot+0xf2>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1251 <getroot+0x121>
mov    -0x18(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1247 <getroot+0x117>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    124c <getroot+0x11c>
jmp    126a <getroot+0x13a>
jmp    1251 <getroot+0x121>
jmp    1256 <getroot+0x126>
jmp    125b <getroot+0x12b>
jmp    1260 <getroot+0x130>
jmp    1265 <getroot+0x135>
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     11fa <getroot+0xca>
mov    %rax,%rbx
lea    0xe97(%rip),%r14
lea    0xe95(%rip),%r12
lea    0xe93(%rip),%r13
lea    0xe91(%rip),%rbp
jmp    1198 <getroot+0x68>
movb   $0x0,(%rbx)
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11fa <getroot+0xca>
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>
mov    %rbx,%rdi
lea    0xe37(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <getroot+0x50>
mov    %rbx,%rdi
lea    0xe29(%rip),%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".img\00"
@.str.2 = [5 x i8] c".ifh\00"
@.str.3 = [6 x i8] c".4dfp\00"
@.str.4 = [5 x i8] c".hdr\00"
@.str.5 = [6 x i8] c".conc\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 = %55, %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 %56
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 %55
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 %54
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 %53
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 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 %52
37: ; preds = %31
%38 = load i8*, i8** %5
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = load i8*, i8** %5
store i8 0, i8* %42
br label %51
43: ; preds = %37
%44 = load i8*, i8** %5
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = load i8*, i8** %5
store i8 0, i8* %48
br label %50
49: ; preds = %43
br label %56
50: ; preds = %47
br label %51
51: ; preds = %50, %41
br label %52
52: ; preds = %51, %35
br label %53
53: ; preds = %52, %29
br label %54
54: ; preds = %53, %23
br label %55
55: ; preds = %54, %17
br label %9
56: ; preds = %49, %9
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".rec\00"
@.str.1 = [5 x i8] c".img\00"
@.str.2 = [5 x i8] c".ifh\00"
@.str.3 = [6 x i8] c".4dfp\00"
@.str.4 = [5 x i8] c".hdr\00"
@.str.5 = [6 x i8] c".conc\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 %28, label %6
6: ; preds = %2, %25
%7 = phi i8* [ %26, %25 ], [ %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 %25, 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 %25, 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 %25, label %16
16: ; preds = %13
%17 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22, %19, %16, %13, %10, %6
store i8 0, i8* %7
%26 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %6
28: ; preds = %25, %22, %2
ret void
}