#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*/ has_more_non_whitespace_chars(char *, int);
void remove_trailing_whitespace(char line[]) {
  for (int i = 0; line[i] != '\0'; ++i) {
    if (!has_more_non_whitespace_chars(line, i)) {
      line[i] = '\0';
      return;
    }
  }
}


x86 assembly (clang, -O0):
<remove_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1171 <remove_trailing_whitespace+0x61>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <has_more_non_whitespace_chars@plt>
cmp    $0x0,%eax
jne    115e <remove_trailing_whitespace+0x4e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1171 <remove_trailing_whitespace+0x61>
jmp    1163 <remove_trailing_whitespace+0x53>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <remove_trailing_whitespace+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_trailing_whitespace>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1143 <remove_trailing_whitespace+0x33>
mov    %rdi,%r14
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <has_more_non_whitespace_chars@plt>
test   %eax,%eax
je     113c <remove_trailing_whitespace+0x2c>
cmpb   $0x0,0x1(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1120 <remove_trailing_whitespace+0x10>
jmp    1143 <remove_trailing_whitespace+0x33>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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