#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 strlen(char *);
void elim_trailing_ws(char *string) {
  int i, l = strlen(string);
  for (i = l - 1; i >= 0; i--) {
    if (string[i] == ' ')
      continue;
    else if (string[i] == '\t')
      continue;
    else
      break;
  }
  string[(i >= 0) ? (i + 1) : 0] = '\0';
}


x86 assembly (clang, -O0):
<elim_trailing_ws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
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     1182 <elim_trailing_ws+0x72>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1155 <elim_trailing_ws+0x45>
jmp    1174 <elim_trailing_ws+0x64>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
jne    116f <elim_trailing_ws+0x5f>
jmp    1174 <elim_trailing_ws+0x64>
jmp    1182 <elim_trailing_ws+0x72>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <elim_trailing_ws+0x21>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11a2 <elim_trailing_ws+0x92>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ac <elim_trailing_ws+0x9c>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ac <elim_trailing_ws+0x9c>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elim_trailing_ws>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1153 <elim_trailing_ws+0x43>
mov    %eax,%eax
jmp    113d <elim_trailing_ws+0x2d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
jbe    1153 <elim_trailing_ws+0x43>
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
movzbl (%rbx,%rdx,1),%edx
cmp    $0x20,%dl
je     1130 <elim_trailing_ws+0x20>
cmp    $0x9,%dl
je     1130 <elim_trailing_ws+0x20>
jmp    1155 <elim_trailing_ws+0x45>
xor    %eax,%eax
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
pop    %rbx
ret

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

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