#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 */
char *Strdup(char *, char *);
char *rindex(char *, char);
scalar_t__ strcasecmp(char *, char *);
char *strchr(char *, char);
int strlen(char *);
char *Root(char *name, char *suffix) {
  char *path, *find, *dot;
  int epos;
  if (name == NULL)
    return (NULL);
  find = rindex(name, '/');
  if (find == NULL)
    find = name;
  else
    find += 1;
  if (suffix == NULL) {
    dot = strchr(find, '.');
    if (dot != NULL)
      *dot = '\0';
    path = Strdup(find, "Extracting root from");
    if (dot != NULL)
      *dot = '.';
  } else {
    epos = strlen(find);
    epos -= strlen(suffix);
    if (epos > 0 && strcasecmp(find + epos, suffix) == 0) {
      find[epos] = '\0';
      path = Strdup(find, "Extracting root from");
      find[epos] = suffix[0];
    } else
      path = Strdup(find, "Allocating root");
  }
  return (path);
}


x86 assembly (clang, -O0):
<Root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1178 <Root+0x28>
movq   $0x0,-0x8(%rbp)
jmp    12a6 <Root+0x156>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <rindex@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a2 <Root+0x52>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11ae <Root+0x5e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1208 <Root+0xb8>
mov    -0x28(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11dd <Root+0x8d>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1060 <Strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1203 <Root+0xb3>
mov    -0x30(%rbp),%rax
movb   $0x2e,(%rax)
jmp    129e <Root+0x14e>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    1285 <Root+0x135>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1285 <Root+0x135>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   1060 <Strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1299 <Root+0x149>
mov    -0x28(%rbp),%rdi
lea    0xd85(%rip),%rsi
call   1060 <Strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    129e <Root+0x14e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Root>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b2 <Root+0x62>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1070 <rindex@plt>
lea    0x1(%rax),%r12
test   %rax,%rax
cmove  %rbx,%r12
mov    %r12,%rdi
test   %r14,%r14
je     11b6 <Root+0x66>
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
jle    11a9 <Root+0x59>
mov    %ebx,%r15d
add    %r12,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11df <Root+0x8f>
lea    0xe65(%rip),%rsi
jmp    120b <Root+0xbb>
xor    %eax,%eax
jmp    11f8 <Root+0xa8>
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1204 <Root+0xb4>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xe2e(%rip),%rsi
mov    %r12,%rdi
call   1060 <Strdup@plt>
movb   $0x2e,(%rbx)
jmp    11f8 <Root+0xa8>
movb   $0x0,(%r15)
lea    0xe16(%rip),%rsi
mov    %r12,%rdi
call   1060 <Strdup@plt>
mov    (%r14),%cl
mov    %cl,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdf5(%rip),%rsi
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <Strdup@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Extracting root from\00"
@.str.1 = [16 x i8] c"Allocating root\00"
define i8* @Root(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* null, i8** %3
br label %78
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @rindex(i8* %14, i8 signext 47)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i8*, i8** %4
store i8* %19, i8** %7
br label %23
20: ; preds = %13
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %7
br label %23
23: ; preds = %20, %18
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %41
26: ; preds = %23
%27 = load i8*, i8** %7
%28 = call i8* @strchr(i8* %27, i8 signext 46)
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i8*, i8** %8
store i8 0, i8* %32
br label %33
33: ; preds = %31, %26
%34 = load i8*, i8** %7
%35 = call i8* @Strdup(i8* %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* %35, i8** %6
%36 = load i8*, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i8*, i8** %8
store i8 46, i8* %39
br label %40
40: ; preds = %38, %33
br label %76
41: ; preds = %23
%42 = load i8*, i8** %7
%43 = call i32 @strlen(i8* %42)
store i32 %43, i32* %9
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
%46 = load i32, i32* %9
%47 = sub nsw i32 %46, %45
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %72
50: ; preds = %41
%51 = load i8*, i8** %7
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8*, i8** %5
%56 = call i64 @strcasecmp(i8* %54, i8* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %72
58: ; preds = %50
%59 = load i8*, i8** %7
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %7
%64 = call i8* @Strdup(i8* %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* %64, i8** %6
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i64 0
%67 = load i8, i8* %66
%68 = load i8*, i8** %7
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
store i8 %67, i8* %71
br label %75
72: ; preds = %50, %41
%73 = load i8*, i8** %7
%74 = call i8* @Strdup(i8* %73, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* %74, i8** %6
br label %75
75: ; preds = %72, %58
br label %76
76: ; preds = %75, %40
%77 = load i8*, i8** %6
store i8* %77, i8** %3
br label %78
78: ; preds = %76, %12
%79 = load i8*, i8** %3
ret i8* %79
}

LLVM IR (-O2):
@.str = [21 x i8] c"Extracting root from\00"
@.str.1 = [16 x i8] c"Allocating root\00"
define i8* @Root(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %32, label %4
4: ; preds = %2
%5 = tail call i8* @rindex(i8* %0, i8 signext 47)
%6 = icmp eq i8* %5, null
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = select i1 %6, i8* %0, i8* %7
%9 = icmp eq i8* %1, null
br i1 %9, label %10, label %17
10: ; preds = %4
%11 = tail call i8* @strchr(i8* %8, i8 signext 46)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i8* @Strdup(i8* %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %32
15: ; preds = %10
store i8 0, i8* %11
%16 = tail call i8* @Strdup(i8* %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8 46, i8* %11
br label %32
17: ; preds = %4
%18 = tail call i32 @strlen(i8* %8)
%19 = tail call i32 @strlen(i8* %1)
%20 = sub nsw i32 %18, %19
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = zext i32 %20 to i64
%24 = getelementptr inbounds i8, i8* %8, i64 %23
%25 = tail call i64 @strcasecmp(i8* %24, i8* %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
store i8 0, i8* %24
%28 = tail call i8* @Strdup(i8* %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%29 = load i8, i8* %1
store i8 %29, i8* %24
br label %32
30: ; preds = %22, %17
%31 = tail call i8* @Strdup(i8* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %13, %15, %30, %27, %2
%33 = phi i8* [ null, %2 ], [ %16, %15 ], [ %28, %27 ], [ %31, %30 ], [ %14, %13 ]
ret i8* %33
}