#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__ isalpha(char);
char toupper(char);
int CleanSequenceLine(char *str) {
  char *s, *d;
  s = d = str;
  while ((*d = toupper(*s))) {
    if (isalpha(*d))
      d++;
    s++;
  }
  return d - str;
}


x86 assembly (clang, -O0):
<CleanSequenceLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    -0x18(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     1185 <CleanSequenceLine+0x65>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%rax
je     1174 <CleanSequenceLine+0x54>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1138 <CleanSequenceLine+0x18>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CleanSequenceLine>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %al,(%r14)
mov    %r14,%r15
test   %al,%al
je     1173 <CleanSequenceLine+0x53>
lea    0x1(%r14),%rbx
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <isalpha@plt>
cmp    $0x1,%rax
sbb    $0xffffffffffffffff,%r15
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %al,(%r15)
add    $0x1,%rbx
test   %al,%al
jne    1150 <CleanSequenceLine+0x30>
sub    %r14d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @CleanSequenceLine(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %4
store i8* %5, i8** %3
br label %6
6: ; preds = %20, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call signext i8 @toupper(i8 signext %8)
%10 = load i8*, i8** %4
store i8 %9, i8* %10
%11 = icmp ne i8 %9, 0
br i1 %11, label %12, label %23
12: ; preds = %6
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = call i64 @isalpha(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
br label %20
20: ; preds = %17, %12
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
br label %6
23: ; preds = %6
%24 = load i8*, i8** %4
%25 = load i8*, i8** %2
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
ret i32 %29
}

LLVM IR (-O2):
define i32 @CleanSequenceLine(i8* %0) {
%2 = load i8, i8* %0
%3 = tail call signext i8 @toupper(i8 signext %2)
store i8 %3, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %17, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %15, %5 ], [ %3, %1 ]
%7 = phi i8* [ %12, %5 ], [ %0, %1 ]
%8 = phi i8* [ %13, %5 ], [ %0, %1 ]
%9 = tail call i64 @isalpha(i8 signext %6)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i64
%12 = getelementptr i8, i8* %7, i64 %11
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = load i8, i8* %13
%15 = tail call signext i8 @toupper(i8 signext %14)
store i8 %15, i8* %12
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %5
17: ; preds = %5, %1
%18 = phi i8* [ %0, %1 ], [ %12, %5 ]
%19 = ptrtoint i8* %18 to i64
%20 = ptrtoint i8* %0 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
ret i32 %22
}