#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(unsigned char *);
int strip(unsigned char *s) {
  int len = strlen(s);
  if (s[len - 1] == '\n')
    s[len-- - 1] = '\0';
  while (len > 0 && s[len - 1] == '\t')
    s[len-- - 1] = '\0';
  return len;
}


x86 assembly (clang, -O0):
<strip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    115b <strip+0x4b>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1160 <strip+0x50>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jle    1189 <strip+0x79>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1199 <strip+0x89>
jmp    11b7 <strip+0xa7>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1160 <strip+0x50>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
cmpb   $0xa,-0x1(%rbx,%rcx,1)
jne    112d <strip+0x1d>
add    $0xffffffffffffffff,%rcx
movb   $0x0,(%rbx,%rcx,1)
mov    %ecx,%eax
test   %eax,%eax
jle    115f <strip+0x4f>
mov    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
cmpb   $0x9,(%rbx,%rdx,1)
jne    115f <strip+0x4f>
movb   $0x0,(%rbx,%rdx,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
ja     1140 <strip+0x30>
xor    %eax,%eax
pop    %rbx
ret

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

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