#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 */
unsigned char strlen(char *);
char *str(char *p) {
  unsigned char i;
  while (*p++ == 0x20)
    ;
  p--;
  while (*p++ == 0x09)
    ;
  p--;
  i = strlen(p);
  while (p[--i] == 0x0a)
    ;
  p[++i] = '\0';
  return p;
}


x86 assembly (clang, -O0):
<str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    113c <str+0x2c>
jmp    111c <str+0xc>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
cmp    $0x9,%eax
jne    1168 <str+0x58>
jmp    1148 <str+0x38>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x9(%rbp),%cl
add    $0xff,%cl
mov    %cl,-0x9(%rbp)
movzbl %cl,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11a2 <str+0x92>
jmp    1180 <str+0x70>
mov    -0x8(%rbp),%rax
mov    -0x9(%rbp),%cl
add    $0x1,%cl
mov    %cl,-0x9(%rbp)
movzbl %cl,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str>:
push   %rbx
add    $0xffffffffffffffff,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%rdi),%eax
add    $0x1,%rdi
cmp    $0x20,%al
je     1120 <str+0x10>
cmp    $0x9,%al
jne    113f <str+0x2f>
lea    0x1(%rdi),%rbx
cmpb   $0x9,0x1(%rdi)
mov    %rbx,%rdi
je     1130 <str+0x20>
jmp    1142 <str+0x32>
mov    %rdi,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%al
nopl   0x0(%rax)
lea    -0x2(%rax),%ecx
movzbl %cl,%ecx
add    $0xff,%al
cmpb   $0xa,(%rbx,%rcx,1)
je     1150 <str+0x40>
movzbl %al,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @str(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %4, %2 ]
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = load i8, i8* %3
switch i8 %5, label %11 [
i8 32, label %2
i8 9, label %6
]
6: ; preds = %2, %6
%7 = phi i8* [ %8, %6 ], [ %3, %2 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 9
br i1 %10, label %6, label %11
11: ; preds = %2, %6
%12 = phi i8* [ %8, %6 ], [ %3, %2 ]
%13 = tail call zeroext i8 @strlen(i8* %12)
br label %14
14: ; preds = %14, %11
%15 = phi i8 [ %13, %11 ], [ %16, %14 ]
%16 = add i8 %15, -1
%17 = zext i8 %16 to i64
%18 = getelementptr inbounds i8, i8* %12, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %14, label %21
21: ; preds = %14
%22 = zext i8 %15 to i64
%23 = getelementptr inbounds i8, i8* %12, i64 %22
store i8 0, i8* %23
ret i8* %12
}