#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 /*<<< orphan*/ isalnum(char);
int strlen(char *);
void strip(char *str) {
  int sz = strlen(str) - 1;
  while (!isalnum(str[sz]) && sz >= 0) {
    str[sz--] = '\0';
  }
}


x86 assembly (clang, -O0):
<strip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
jne    1166 <strip+0x46>
cmpl   $0x0,-0xc(%rbp)
setge  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1176 <strip+0x56>
jmp    1191 <strip+0x71>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    113b <strip+0x1b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
movslq %eax,%r14
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <isalnum@plt>
test   %eax,%eax
jne    1181 <strip+0x61>
test   %ebp,%ebp
jle    1181 <strip+0x61>
lea    (%r14,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
mov    %ebp,%ebp
add    $0xfffffffffffffffe,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rax)
movsbl (%rbx,%rbp,1),%edi
call   1040 <isalnum@plt>
test   %eax,%eax
jne    1181 <strip+0x61>
lea    (%rbx,%rbp,1),%rax
lea    -0x1(%rbp),%rcx
cmp    $0x1,%rbp
mov    %rcx,%rbp
jne    1160 <strip+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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