#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);
char *strdup(char *);
int /*<<< orphan*/ tolower(int);
char *homogenize(char *str) {
  char *ans;
  char *fr;
  char *to;
  int ch;
  to = fr = ans = strdup(str);
  while ((ch = *fr++) != '\0') {
    if (isalnum(ch)) {
      *to++ = tolower(ch);
    }
  }
  *to = '\0';
  return ans;
}


x86 assembly (clang, -O0):
<homogenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11a1 <homogenize+0x71>
mov    -0x24(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     119c <homogenize+0x6c>
mov    -0x24(%rbp),%edi
call   1040 <tolower@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1151 <homogenize+0x21>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<homogenize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1050 <strdup@plt>
mov    %rax,%r14
mov    (%rax),%al
mov    %r14,%r15
test   %al,%al
je     118a <homogenize+0x5a>
mov    %r14,%rbx
add    $0x1,%rbx
mov    %r14,%r15
jmp    116b <homogenize+0x3b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     118a <homogenize+0x5a>
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     1160 <homogenize+0x30>
mov    %ebp,%edi
call   1040 <tolower@plt>
mov    %al,(%r15)
add    $0x1,%r15
jmp    1160 <homogenize+0x30>
movb   $0x0,(%r15)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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