#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 *);
int clean_line(char *line) {
  int len = strlen(line);
  if (!len)
    return 0;
  if (line[len - 1] == '\n')
    line[--len] = '\0';
  if (line[len - 1] == '\r')
    line[--len] = '\0';
  for (; *line; line++)
    if (*line == '\t')
      *line = ' ';
  return len;
}


x86 assembly (clang, -O0):
<clean_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    113e <clean_line+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11df <clean_line+0xcf>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    116c <clean_line+0x5c>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    119a <clean_line+0x8a>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    119f <clean_line+0x8f>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d9 <clean_line+0xc9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
jne    11c3 <clean_line+0xb3>
mov    -0x10(%rbp),%rax
movb   $0x20,(%rax)
jmp    11c8 <clean_line+0xb8>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    119f <clean_line+0x8f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_line>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     1141 <clean_line+0x31>
mov    %eax,%ecx
movslq %eax,%rdx
lea    -0x1(%rdx),%rax
cmpb   $0xa,-0x1(%rbx,%rdx,1)
jne    1145 <clean_line+0x35>
movb   $0x0,(%rbx,%rax,1)
add    $0xfffffffe,%ecx
movslq %ecx,%rdx
mov    %ecx,%esi
cmpb   $0xd,(%rbx,%rdx,1)
jne    1167 <clean_line+0x57>
jmp    1152 <clean_line+0x42>
xor    %eax,%eax
jmp    1173 <clean_line+0x63>
mov    %rax,%rdx
mov    %eax,%esi
mov    %ecx,%eax
cmpb   $0xd,(%rbx,%rdx,1)
jne    1167 <clean_line+0x57>
movb   $0x0,(%rbx,%rdx,1)
mov    %esi,%eax
jmp    1167 <clean_line+0x57>
nopw   0x0(%rax,%rax,1)
movb   $0x20,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x9,%cl
je     1160 <clean_line+0x50>
test   %cl,%cl
jne    1163 <clean_line+0x53>
pop    %rbx
ret

LLVM IR (-O0):
define i32 @clean_line(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 0, i32* %2
br label %58
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %25
19: ; preds = %10
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = add nsw i32 %21, -1
store i32 %22, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %19, %10
%26 = load i8*, i8** %3
%27 = load i32, i32* %4
%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 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 13
br i1 %33, label %34, label %40
34: ; preds = %25
%35 = load i8*, i8** %3
%36 = load i32, i32* %4
%37 = add nsw i32 %36, -1
store i32 %37, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %34, %25
br label %41
41: ; preds = %53, %40
%42 = load i8*, i8** %3
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 9
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = load i8*, i8** %3
store i8 32, i8* %51
br label %52
52: ; preds = %50, %45
br label %53
53: ; preds = %52
%54 = load i8*, i8** %3
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %3
br label %41
56: ; preds = %41
%57 = load i32, i32* %4
store i32 %57, i32* %2
br label %58
58: ; preds = %56, %9
%59 = load i32, i32* %2
ret i32 %59
}

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