#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 remove_tb(char *s) {
  int l;
  char *p;
  l = strlen(s);
  if (l <= 0)
    return;
  p = s + l - 1;
  while (p >= s) {
    if (*p == ' ')
      *p-- = 0;
    else
      break;
  }
  return;
}


x86 assembly (clang, -O0):
<remove_tb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1137 <remove_tb+0x27>
jmp    118e <remove_tb+0x7e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     1189 <remove_tb+0x79>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    117f <remove_tb+0x6f>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
jmp    1184 <remove_tb+0x74>
jmp    1189 <remove_tb+0x79>
jmp    114a <remove_tb+0x3a>
jmp    118e <remove_tb+0x7e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_tb>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1141 <remove_tb+0x31>
mov    %eax,%eax
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jb     1141 <remove_tb+0x31>
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%rax)
jne    1141 <remove_tb+0x31>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jae    1130 <remove_tb+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @remove_tb(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
br label %31
10: ; preds = %1
%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 = getelementptr inbounds i8, i8* %14, i64 -1
store i8* %15, i8** %4
br label %16
16: ; preds = %29, %10
%17 = load i8*, i8** %4
%18 = load i8*, i8** %2
%19 = icmp uge i8* %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 32
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %4
store i8 0, i8* %26
br label %29
28: ; preds = %20
br label %30
29: ; preds = %25
br label %16
30: ; preds = %28, %16
br label %31
31: ; preds = %30, %9
ret void
}

LLVM IR (-O2):
define void @remove_tb(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 1
%4 = zext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = icmp ult i8* %6, %0
%8 = select i1 %3, i1 true, i1 %7
br i1 %8, label %16, label %9
9: ; preds = %1, %13
%10 = phi i8* [ %14, %13 ], [ %6, %1 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 32
br i1 %12, label %13, label %16
13: ; preds = %9
store i8 0, i8* %10
%14 = getelementptr inbounds i8, i8* %10, i64 -1
%15 = icmp ult i8* %14, %0
br i1 %15, label %16, label %9
16: ; preds = %9, %13, %1
ret void
}