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


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,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x10(%rbp),%rdi
sub    $0x1,%eax
cltq
add    %rax,%rdi
lea    0xea0(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1195 <rm_end_space+0x65>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    119a <rm_end_space+0x6a>
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
je     11f0 <rm_end_space+0xc0>
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    11f5 <rm_end_space+0xc5>
jmp    11fa <rm_end_space+0xca>
jmp    119a <rm_end_space+0x6a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_end_space>:
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xeb6(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1168 <rm_end_space+0x38>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%edi
call   1050 <isblank@plt>
test   %rax,%rax
jne    1159 <rm_end_space+0x29>
pop    %rbx
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
%3 = load i8*, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sub nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %3, i64 %7
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %11, %1
br label %19
19: ; preds = %38, %18
%20 = load i8*, i8** %2
%21 = load i8*, i8** %2
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i64 @isblank(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %19
%31 = load i8*, i8** %2
%32 = load i8*, i8** %2
%33 = call i32 @strlen(i8* %32)
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %31, i64 %35
store i8 0, i8* %36
br label %38
37: ; preds = %19
br label %39
38: ; preds = %30
br label %19
39: ; preds = %37
ret void
}

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