#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*/ exit(int);
int strlen(char *);
void clean_name(char *path) {
  int len = strlen(path);
  int ext_len = strlen(".masm");
  if (len <= ext_len)
    exit(1);
  int i;
  for (i = 0; i < ext_len; i++) {
    if (".masm"[ext_len - i] != path[len - i])
      exit(1);
  }
  if (ext_len != i)
    exit(1);
  path[len - i] = '\0';
}


x86 assembly (clang, -O0):
<clean_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
lea    0xec1(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     115d <clean_name+0x3d>
mov    $0x1,%edi
call   1040 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ba <clean_name+0x9a>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
movslq %eax,%rcx
lea    0xe80(%rip),%rax
movsbl (%rax,%rcx,1),%eax
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%edx
sub    -0x14(%rbp),%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11a7 <clean_name+0x87>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11ac <clean_name+0x8c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <clean_name+0x44>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11d0 <clean_name+0xb0>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    0xec7(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15d,%ebp
sub    %eax,%ebp
jle    1190 <clean_name+0x70>
test   %eax,%eax
jle    117b <clean_name+0x5b>
mov    %eax,%eax
movslq %r15d,%rdx
add    %r14,%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
lea    (%rax,%rsi,1),%rdi
movzbl (%rbx,%rdi,1),%ecx
cmp    (%rdx,%rsi,1),%cl
jne    1190 <clean_name+0x70>
add    $0xffffffffffffffff,%rsi
mov    %rax,%rcx
add    %rsi,%rcx
jne    1160 <clean_name+0x40>
jmp    117d <clean_name+0x5d>
jne    1190 <clean_name+0x70>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c".masm\00"
define void @clean_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %4
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
store i32 0, i32* %5
br label %15
15: ; preds = %39, %14
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %42
19: ; preds = %15
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = sub nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [6 x i8], [6 x i8]* @.str, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8*, i8** %2
%28 = load i32, i32* %3
%29 = load i32, i32* %5
%30 = sub nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %26, %34
br i1 %35, label %36, label %38
36: ; preds = %19
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %19
br label %39
39: ; preds = %38
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %15
42: ; preds = %15
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
%49 = load i8*, i8** %2
%50 = load i32, i32* %3
%51 = load i32, i32* %5
%52 = sub nsw i32 %50, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %49, i64 %53
store i8 0, i8* %54
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c".masm\00"
define void @clean_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %2, %3
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %27
7: ; preds = %5
%8 = zext i32 %3 to i64
%9 = sext i32 %2 to i64
%10 = zext i32 %3 to i64
br label %13
11: ; preds = %1
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %24
%14 = phi i64 [ 0, %7 ], [ %25, %24 ]
%15 = sub nsw i64 %8, %14
%16 = getelementptr inbounds [6 x i8], [6 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sub nsw i64 %9, %14
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %17, %20
br i1 %21, label %24, label %22
22: ; preds = %13
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %13
%25 = add nuw nsw i64 %14, 1
%26 = icmp eq i64 %25, %10
br i1 %26, label %31, label %13
27: ; preds = %5
%28 = icmp eq i32 %3, 0
br i1 %28, label %31, label %29
29: ; preds = %27
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %24, %27
%32 = sub nsw i32 %2, %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
store i8 0, i8* %34
ret void
}