#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*/ assert(int /*<<< orphan*/);
int strlen(char *);
void remove_trailing_whitespaces(char *str) {
  int i, size;
  assert(str != NULL);
  if (str == NULL)
    return;
  size = strlen(str);
  for (i = size - 1; i >= 0; i--) {
    if (str[i] == ' ') {
      str[i] = '\0';
    } else
      break;
  }
}


x86 assembly (clang, -O0):
<remove_trailing_whitespaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
jne    114e <remove_trailing_whitespaces+0x2e>
jmp    11ab <remove_trailing_whitespaces+0x8b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11ab <remove_trailing_whitespaces+0x8b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1193 <remove_trailing_whitespaces+0x73>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1198 <remove_trailing_whitespaces+0x78>
jmp    11ab <remove_trailing_whitespaces+0x8b>
jmp    119d <remove_trailing_whitespaces+0x7d>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <remove_trailing_whitespaces+0x43>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_trailing_whitespaces>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
test   %rbx,%rbx
je     1167 <remove_trailing_whitespaces+0x47>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1167 <remove_trailing_whitespaces+0x47>
mov    %eax,%eax
add    $0x1,%rax
nopl   0x0(%rax)
lea    -0x2(%rax),%ecx
cmpb   $0x20,(%rbx,%rcx,1)
jne    1167 <remove_trailing_whitespaces+0x47>
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1150 <remove_trailing_whitespaces+0x30>
pop    %rbx
ret

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

LLVM IR (-O2):
define void @remove_trailing_whitespaces(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = icmp eq i8* %0, null
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %18
%12 = phi i64 [ %10, %9 ], [ %13, %18 ]
%13 = add nsw i64 %12, -1
%14 = and i64 %13, 4294967295
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 32
br i1 %17, label %18, label %20
18: ; preds = %11
store i8 0, i8* %15
%19 = icmp ugt i64 %12, 1
br i1 %19, label %11, label %20
20: ; preds = %11, %18, %6, %1
ret void
}