#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 */
scalar_t__ isalnum(int);
scalar_t__ isalpha(int);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
int SanitizeWaveName(char *waveName, int column) {
  int len, i, ch;
  int result = 0;
  len = (int)strlen(waveName);
  if (len == 0) {
    sprintf(waveName, "NoName%d", column);
    return 1;
  }
  ch = waveName[0];
  if (!(ch > 0 && isalpha(ch))) {
    memmove(waveName + 1, waveName, len + 1);
    waveName[0] = 'X';
    len += 1;
    result = 1;
  }
  if (len > 31) {
    waveName[31] = '\0';
    len = 31;
    result = 1;
  }
  for (i = 1; i < len; i++) {
    ch = waveName[i];
    if (!(ch > 0 && isalnum(ch))) {
      waveName[i] = '_';
      result = 1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<SanitizeWaveName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    119b <SanitizeWaveName+0x4b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe76(%rip),%rsi
call   1070 <sprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1279 <SanitizeWaveName+0x129>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11c1 <SanitizeWaveName+0x71>
mov    -0x20(%rbp),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
jne    11ef <SanitizeWaveName+0x9f>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1060 <memmove@plt>
mov    -0x10(%rbp),%rax
movb   $0x58,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1f,-0x18(%rbp)
jle    120f <SanitizeWaveName+0xbf>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1f(%rax)
movl   $0x1f,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1273 <SanitizeWaveName+0x123>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    124d <SanitizeWaveName+0xfd>
mov    -0x20(%rbp),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
jne    1260 <SanitizeWaveName+0x110>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
movl   $0x1,-0x24(%rbp)
jmp    1265 <SanitizeWaveName+0x115>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1216 <SanitizeWaveName+0xc6>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SanitizeWaveName>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%r14
test   %r14d,%r14d
je     119b <SanitizeWaveName+0x4b>
movzbl (%r12),%edi
test   %dil,%dil
jle    11b4 <SanitizeWaveName+0x64>
call   1050 <isalpha@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11b4 <SanitizeWaveName+0x64>
cmp    $0x20,%r14d
jl     11d9 <SanitizeWaveName+0x89>
movb   $0x0,0x1f(%r12)
mov    $0x1f,%r14d
mov    $0x1,%r15d
jmp    11df <SanitizeWaveName+0x8f>
lea    0xe5e(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
call   1070 <sprintf@plt>
mov    $0x1,%r15d
jmp    121a <SanitizeWaveName+0xca>
lea    0x1(%r12),%rdi
add    $0x1,%r14d
mov    %r12,%rsi
mov    %r14d,%edx
call   1060 <memmove@plt>
movb   $0x58,(%r12)
mov    $0x1,%r15d
cmp    $0x20,%r14d
jge    1187 <SanitizeWaveName+0x37>
cmp    $0x2,%r14d
jl     121a <SanitizeWaveName+0xca>
mov    %r14d,%ebp
mov    $0x1,%ebx
jmp    1204 <SanitizeWaveName+0xb4>
nopl   0x0(%rax)
movb   $0x5f,(%r12,%rbx,1)
mov    $0x1,%r15d
add    $0x1,%rbx
cmp    %rbx,%rbp
je     121a <SanitizeWaveName+0xca>
movzbl (%r12,%rbx,1),%edi
test   %dil,%dil
jle    11f0 <SanitizeWaveName+0xa0>
call   1040 <isalnum@plt>
test   %rax,%rax
jne    11fb <SanitizeWaveName+0xab>
jmp    11f0 <SanitizeWaveName+0xa0>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"NoName%d\00"
define i32 @SanitizeWaveName(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %46
8: ; preds = %2
%9 = load i8, i8* %0
%10 = icmp sgt i8 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = zext i8 %9 to i32
%13 = tail call i64 @isalpha(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11, %8
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = add nsw i32 %4, 1
%18 = tail call i32 @memmove(i8* %16, i8* %0, i32 %17)
store i8 88, i8* %0
br label %19
19: ; preds = %15, %11
%20 = phi i32 [ %4, %11 ], [ %17, %15 ]
%21 = phi i32 [ 0, %11 ], [ 1, %15 ]
%22 = icmp sgt i32 %20, 31
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %0, i64 31
store i8 0, i8* %24
br label %27
25: ; preds = %19
%26 = icmp sgt i32 %20, 1
br i1 %26, label %27, label %46
27: ; preds = %23, %25
%28 = phi i32 [ 1, %23 ], [ %21, %25 ]
%29 = phi i32 [ 31, %23 ], [ %20, %25 ]
%30 = zext i32 %29 to i64
br label %31
31: ; preds = %27, %42
%32 = phi i64 [ 1, %27 ], [ %44, %42 ]
%33 = phi i32 [ %28, %27 ], [ %43, %42 ]
%34 = getelementptr inbounds i8, i8* %0, i64 %32
%35 = load i8, i8* %34
%36 = icmp sgt i8 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = zext i8 %35 to i32
%39 = tail call i64 @isalnum(i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37, %31
store i8 95, i8* %34
br label %42
42: ; preds = %37, %41
%43 = phi i32 [ %33, %37 ], [ 1, %41 ]
%44 = add nuw nsw i64 %32, 1
%45 = icmp eq i64 %44, %30
br i1 %45, label %46, label %31
46: ; preds = %42, %25, %6
%47 = phi i32 [ 1, %6 ], [ %21, %25 ], [ %43, %42 ]
ret i32 %47
}