#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 trim(char *s) {
  int len = strlen(s) - 1;
  while (s[len] == '\n' || s[len] == '\r' || s[len] == ' ')
    len--;
  s[len + 1] = 0;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0xd(%rbp)
je     1174 <trim+0x64>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0xd(%rbp)
je     1174 <trim+0x64>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1184 <trim+0x74>
jmp    1192 <trim+0x82>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    112b <trim+0x1b>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
shl    $0x20,%rax
movabs $0x100002400,%rdx
movabs $0xffffffff00000000,%rsi
ff ff ff
nopl   0x0(%rax,%rax,1)
movzbl (%rcx),%edi
cmp    $0x20,%rdi
ja     1158 <trim+0x48>
bt     %rdi,%rdx
jae    1158 <trim+0x48>
add    %rsi,%rax
add    $0xffffffffffffffff,%rcx
jmp    1140 <trim+0x30>
sar    $0x20,%rax
movb   $0x0,(%rbx,%rax,1)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @trim(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %9, %1
%5 = phi i64 [ %3, %1 ], [ %6, %9 ]
%6 = add i64 %5, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %10 [
i8 10, label %9
i8 13, label %9
i8 32, label %9
]
9: ; preds = %4, %4, %4
br label %4
10: ; preds = %4
%11 = shl i64 %5, 32
%12 = ashr exact i64 %11, 32
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 0, i8* %13
ret void
}