#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 */
scalar_t__ isspace(char);
int strlen(char *);
void remove_trailing_whitespace(char *line) {
  char *end = line + strlen(line) - 1;
  while (isspace(*end)) {
    *end = '\0';
    --end;
  }
  *(end + 1) = '\n';
  *(end + 2) = '\0';
}


x86 assembly (clang, -O0):
<remove_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     117f <remove_trailing_whitespace+0x5f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1151 <remove_trailing_whitespace+0x31>
mov    -0x10(%rbp),%rax
movb   $0xa,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_trailing_whitespace>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
lea    (%r14,%rax,1),%rbx
movsbl -0x1(%r14,%rax,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     116b <remove_trailing_whitespace+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x1(%rbx),%r14
movb   $0x0,-0x1(%rbx)
movsbl -0x2(%rbx),%edi
call   1040 <isspace@plt>
mov    %r14,%rbx
test   %rax,%rax
jne    1150 <remove_trailing_whitespace+0x30>
jmp    116e <remove_trailing_whitespace+0x4e>
mov    %rbx,%r14
movw   $0xa,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @remove_trailing_whitespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %3
br label %10
10: ; preds = %15, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = call i64 @isspace(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %3
store i8 0, i8* %16
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 -1
store i8* %18, i8** %3
br label %10
19: ; preds = %10
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8 10, i8* %21
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 2
store i8 0, i8* %23
ret void
}

LLVM IR (-O2):
define void @remove_trailing_whitespace(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = load i8, i8* %5
%7 = tail call i64 @isspace(i8 signext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %1, %9
%10 = phi i8* [ %11, %9 ], [ %5, %1 ]
store i8 0, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = load i8, i8* %11
%13 = tail call i64 @isspace(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %9
15: ; preds = %9, %1
%16 = phi i8* [ %4, %1 ], [ %10, %9 ]
store i8 10, i8* %16
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 0, i8* %17
ret void
}