#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 /*<<< orphan*/ isspace(unsigned char);
int strlen(char *);
void cleanup(char *line) {
  int len = strlen(line);
  if (len > 1 && line[len - 1] == '\n') {
    do {
      unsigned char c = line[len - 2];
      if (!isspace(c))
        break;
      line[len - 2] = '\n';
      len--;
      line[len] = 0;
    } while (len > 1);
  }
}


x86 assembly (clang, -O0):
<cleanup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    11c0 <cleanup+0xa0>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11c0 <cleanup+0xa0>
jmp    1161 <cleanup+0x41>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    118b <cleanup+0x6b>
jmp    11bb <cleanup+0x9b>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x1,-0xc(%rbp)
jg     1161 <cleanup+0x41>
jmp    11c0 <cleanup+0xa0>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanup>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1167 <cleanup+0x47>
lea    -0x1(%rax),%ecx
cmpb   $0xa,(%r14,%rcx,1)
jne    1167 <cleanup+0x47>
mov    %eax,%ebx
xchg   %ax,%ax
lea    -0x2(%rbx),%r15d
movzbl (%r14,%r15,1),%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     1167 <cleanup+0x47>
movb   $0xa,(%r14,%r15,1)
movb   $0x0,-0x1(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1140 <cleanup+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @cleanup(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %24
4: ; preds = %1
%5 = add nsw i32 %2, -1
%6 = zext 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 %24
10: ; preds = %4
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %10, %20
%13 = phi i64 [ %11, %10 ], [ %21, %20 ]
%14 = add i64 %13, 4294967294
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @isspace(i8 zeroext %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %12
store i8 10, i8* %16
%21 = add nsw i64 %13, -1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 0, i8* %22
%23 = icmp ugt i64 %21, 1
br i1 %23, label %12, label %24
24: ; preds = %12, %20, %4, %1
ret void
}