#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 */
typedef char wchar_t;

/* Variables and functions */
int /*<<< orphan*/ *wcschr(char *, char);
int wcslen(char *);
void wcs_strip_trailing_whitespaces(wchar_t *s) {
  int len;
  for (len = wcslen(s) - 1; len >= 0; len--) {
    if (wcschr(L" \t\r\n", s[len]) == NULL)
      break;
    s[len] = '\0';
  }
}


x86 assembly (clang, -O0):
<wcs_strip_trailing_whitespaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <wcslen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1186 <wcs_strip_trailing_whitespaces+0x66>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xeac(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <wcschr@plt>
cmp    $0x0,%rax
jne    116c <wcs_strip_trailing_whitespaces+0x4c>
jmp    1186 <wcs_strip_trailing_whitespaces+0x66>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <wcs_strip_trailing_whitespaces+0x1b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcs_strip_trailing_whitespaces>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <wcslen@plt>
test   %eax,%eax
jle    1175 <wcs_strip_trailing_whitespaces+0x55>
mov    %eax,%ebx
add    $0x1,%rbx
lea    0xebf(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%r12d
movsbl (%r15,%r12,1),%esi
mov    %r14,%rdi
call   1040 <wcschr@plt>
test   %rax,%rax
je     1175 <wcs_strip_trailing_whitespaces+0x55>
movb   $0x0,(%r15,%r12,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1150 <wcs_strip_trailing_whitespaces+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i32] [i32 32, i32 9, i32 13, i32 10, i32 0]
define void @wcs_strip_trailing_whitespaces(i8* nocapture %0) {
%2 = tail call i32 @wcslen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %14
%7 = phi i64 [ %5, %4 ], [ %8, %14 ]
%8 = add nsw i64 %7, -1
%9 = and i64 %8, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32* @wcschr(i8* bitcast ([5 x i32]* @.str to i8*), i8 signext %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %6
store i8 0, i8* %10
%15 = icmp ugt i64 %7, 1
br i1 %15, label %6, label %16
16: ; preds = %14, %6, %1
ret void
}