#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 */
size_t strlen(char *);
void strip_trailing_period_and_whitespace(char *buff) {
  size_t i = strlen(buff);
  while (i && (buff[i - 1] == '.' || buff[i - 1] <= ' '))
    i--;
  buff[i] = '\0';
}


x86 assembly (clang, -O0):
<strip_trailing_period_and_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     1176 <strip_trailing_period_and_whitespace+0x66>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x2e,%ecx
mov    %al,-0x12(%rbp)
je     1170 <strip_trailing_period_and_whitespace+0x60>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
setle  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1186 <strip_trailing_period_and_whitespace+0x76>
jmp    1197 <strip_trailing_period_and_whitespace+0x87>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1129 <strip_trailing_period_and_whitespace+0x19>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_trailing_period_and_whitespace>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
nopl   0x0(%rax)
mov    %rax,%rcx
sub    $0x1,%rax
jb     1138 <strip_trailing_period_and_whitespace+0x28>
movzbl -0x1(%rbx,%rcx,1),%edx
cmp    $0x2e,%dl
je     1120 <strip_trailing_period_and_whitespace+0x10>
cmp    $0x21,%dl
jl     1120 <strip_trailing_period_and_whitespace+0x10>
movb   $0x0,(%rbx,%rcx,1)
pop    %rbx
ret

LLVM IR (-O0):
define void @strip_trailing_period_and_whitespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
store i64 %5, i64* %3
br label %6
6: ; preds = %29, %1
%7 = load i64, i64* %3
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i64, i64* %3
%12 = sub i64 %11, 1
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 46
br i1 %16, label %25, label %17
17: ; preds = %9
%18 = load i8*, i8** %2
%19 = load i64, i64* %3
%20 = sub i64 %19, 1
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sle i32 %23, 32
br label %25
25: ; preds = %17, %9
%26 = phi i1 [ true, %9 ], [ %24, %17 ]
br label %27
27: ; preds = %25, %6
%28 = phi i1 [ false, %6 ], [ %26, %25 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i64, i64* %3
%31 = add i64 %30, -1
store i64 %31, i64* %3
br label %6
32: ; preds = %27
%33 = load i8*, i8** %2
%34 = load i64, i64* %3
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 0, i8* %35
ret void
}

LLVM IR (-O2):
define void @strip_trailing_period_and_whitespace(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %3
3: ; preds = %6, %1
%4 = phi i64 [ %2, %1 ], [ %7, %6 ]
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = add i64 %4, -1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 46
%11 = icmp slt i8 %9, 33
%12 = or i1 %10, %11
br i1 %12, label %3, label %13
13: ; preds = %6, %3
%14 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 0, i8* %14
ret void
}