#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 checkName(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
void toValidName(char *n) {
  int pos = checkName(n);
  while (pos < strlen(n)) {
    memmove(n + pos, n + pos + 1, strlen(n) - pos);
    pos = checkName(n);
  }
}


x86 assembly (clang, -O0):
<toValidName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <checkName@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    11b2 <toValidName+0x82>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
sub    -0xc(%rbp),%edx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rdi
call   1040 <checkName@plt>
mov    %eax,-0xc(%rbp)
jmp    1148 <toValidName+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toValidName>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
call   1040 <checkName@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jge    117e <toValidName+0x4e>
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%r15
lea    (%rbx,%rbp,1),%r14
add    $0x1,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %ebp,%eax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
mov    %rbx,%rdi
jmp    1140 <toValidName+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @toValidName(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @checkName(i8* %4)
store i32 %5, i32* %3
br label %6
6: ; preds = %11, %1
%7 = load i32, i32* %3
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %28
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8*, i8** %2
%22 = call i32 @strlen(i8* %21)
%23 = load i32, i32* %3
%24 = sub nsw i32 %22, %23
%25 = call i32 @memmove(i8* %15, i8* %20, i32 %24)
%26 = load i8*, i8** %2
%27 = call i32 @checkName(i8* %26)
store i32 %27, i32* %3
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @toValidName(i8* %0) {
%2 = tail call i32 @checkName(i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %2, %3
br i1 %4, label %5, label %16
5: ; preds = %1, %5
%6 = phi i32 [ %13, %5 ], [ %2, %1 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i32 @strlen(i8* %0)
%11 = sub nsw i32 %10, %6
%12 = tail call i32 @memmove(i8* %8, i8* %9, i32 %11)
%13 = tail call i32 @checkName(i8* %0)
%14 = tail call i32 @strlen(i8* %0)
%15 = icmp slt i32 %13, %14
br i1 %15, label %5, label %16
16: ; preds = %5, %1
ret void
}