#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__ isEndOfLine(char);
scalar_t__ isSpace(char);
int strlen(char *);
void removeEndGaps(char *line) {
  int i, len = strlen(line);
  for (i = len - 1; i > -1; i--) {
    if (isSpace(line[i]) || isEndOfLine(line[i]))
      line[i] = '\0';
    else
      break;
  }
}


x86 assembly (clang, -O0):
<removeEndGaps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jle    11ba <removeEndGaps+0x8a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isSpace@plt>
cmp    $0x0,%rax
jne    1191 <removeEndGaps+0x61>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isEndOfLine@plt>
cmp    $0x0,%rax
je     11a2 <removeEndGaps+0x72>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a7 <removeEndGaps+0x77>
jmp    11ba <removeEndGaps+0x8a>
jmp    11ac <removeEndGaps+0x7c>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1151 <removeEndGaps+0x21>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeEndGaps>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1181 <removeEndGaps+0x51>
mov    %eax,%ebx
add    $0x1,%rbx
jmp    115f <removeEndGaps+0x2f>
nopl   0x0(%rax)
movb   $0x0,(%r14,%r15,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    1181 <removeEndGaps+0x51>
lea    -0x2(%rbx),%r15d
movsbl (%r14,%r15,1),%edi
call   1050 <isSpace@plt>
test   %rax,%rax
jne    1150 <removeEndGaps+0x20>
movsbl (%r14,%r15,1),%edi
call   1040 <isEndOfLine@plt>
test   %rax,%rax
jne    1150 <removeEndGaps+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @removeEndGaps(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %18
%7 = phi i64 [ %5, %4 ], [ %8, %18 ]
%8 = add nsw i64 %7, -1
%9 = and i64 %8, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isSpace(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %6
%15 = load i8, i8* %10
%16 = tail call i64 @isEndOfLine(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14, %6
store i8 0, i8* %10
%19 = icmp ugt i64 %7, 1
br i1 %19, label %6, label %20
20: ; preds = %18, %14, %1
ret void
}