#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(char);
int strlen(char *);
char tolower(char);
char *clean(char *str) {
  int curr = 0;
  for (int i = 0; i < strlen(str); ++i) {
    if (isalnum(str[i])) {
      str[curr] = tolower(str[i]);
      curr++;
    }
  }
  str[curr] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<clean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11bb <clean+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
je     11a8 <clean+0x78>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ad <clean+0x7d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114a <clean+0x1a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1189 <clean+0x59>
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    1163 <clean+0x33>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    118c <clean+0x5c>
movsbl (%r14,%rbx,1),%edi
call   1040 <isalnum@plt>
test   %rax,%rax
je     1150 <clean+0x20>
movsbl (%r14,%rbx,1),%edi
call   1050 <tolower@plt>
movslq %r15d,%r15
mov    %al,(%r14,%r15,1)
add    $0x1,%r15d
jmp    1150 <clean+0x20>
xor    %r15d,%r15d
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @clean(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %32, %1
%6 = load i32, i32* %4
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %35
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = call i64 @isalnum(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %10
%19 = load i8*, i8** %2
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call signext i8 @tolower(i8 signext %23)
%25 = load i8*, i8** %2
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %31
31: ; preds = %18, %10
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %5
35: ; preds = %5
%36 = load i8*, i8** %2
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
define i8* @clean(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %21, %1
%5 = phi i32 [ 0, %1 ], [ %22, %21 ]
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 0, i8* %7
ret i8* %0
8: ; preds = %1, %21
%9 = phi i64 [ %23, %21 ], [ 0, %1 ]
%10 = phi i32 [ %22, %21 ], [ 0, %1 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
%13 = tail call i64 @isalnum(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %8
%16 = load i8, i8* %11
%17 = tail call signext i8 @tolower(i8 signext %16)
%18 = sext i32 %10 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %17, i8* %19
%20 = add nsw i32 %10, 1
br label %21
21: ; preds = %8, %15
%22 = phi i32 [ %20, %15 ], [ %10, %8 ]
%23 = add nuw nsw i64 %9, 1
%24 = tail call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %8, label %4
}