#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 tail(char *buf) {
  int l;
  int i;
  if (buf == NULL)
    return;
  l = strlen(buf) - 1;
  for (i = l; i >= 0; i--) {
    if (buf[i] <= 0x20)
      buf[i] = '\0';
    else
      break;
  }
}


x86 assembly (clang, -O0):
<tail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <tail+0x1c>
jmp    1189 <tail+0x79>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1189 <tail+0x79>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jg     1171 <tail+0x61>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1176 <tail+0x66>
jmp    1189 <tail+0x79>
jmp    117b <tail+0x6b>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <tail+0x31>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tail>:
push   %rbx
test   %rdi,%rdi
je     1147 <tail+0x37>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1147 <tail+0x37>
mov    %eax,%eax
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rax),%ecx
cmpb   $0x20,(%rbx,%rcx,1)
jg     1147 <tail+0x37>
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1130 <tail+0x20>
pop    %rbx
ret

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

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