#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__ isblank(char);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void rm_end_space(char *l) {
  while (strncmp(&l[strlen(l) - 1], "\n", 1) == 0 ||
         isblank(l[strlen(l) - 1])) {
    l[strlen(l) - 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<rm_end_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
sub    $0x1,%eax
cltq
add    %rax,%rdi
lea    0xea0(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
je     11ac <rm_end_space+0x7c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isblank@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    11bc <rm_end_space+0x8c>
jmp    11e2 <rm_end_space+0xb2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    113c <rm_end_space+0xc>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_end_space>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec2(%rip),%r14
jmp    114f <rm_end_space+0x1f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1140 <rm_end_space+0x10>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%edi
call   1050 <isblank@plt>
test   %rax,%rax
jne    1140 <rm_end_space+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @rm_end_space(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %24, %1
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %4, i64 %8
%10 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %3
%13 = load i8*, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @isblank(i8 signext %19)
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %12, %3
%23 = phi i1 [ true, %3 ], [ %21, %12 ]
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = load i8*, i8** %2
%26 = load i8*, i8** %2
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
store i8 0, i8* %30
br label %3
31: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @rm_end_space(i8* %0) {
br label %2
2: ; preds = %17, %1
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %2
%10 = tail call i32 @strlen(i8* %0)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = tail call i64 @isblank(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %2, %9
%18 = tail call i32 @strlen(i8* %0)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 0, i8* %21
br label %2
22: ; preds = %9
ret void
}