#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);
void trim_line_end(char *in_line) {
  char *line_end = in_line;
  while (*line_end)
    line_end++;
  while ((line_end - 1 > in_line) && isspace(*(line_end - 1)))
    line_end--;
  *line_end = 0;
}


x86 assembly (clang, -O0):
<trim_line_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1142 <trim_line_end+0x32>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <trim_line_end+0x14>
jmp    1147 <trim_line_end+0x37>
mov    -0x10(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jbe    1175 <trim_line_end+0x65>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1185 <trim_line_end+0x75>
jmp    1196 <trim_line_end+0x86>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <trim_line_end+0x37>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_line_end>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x2(%rdi),%rcx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x2(%rcx)
lea    0x1(%rcx),%rcx
jne    1120 <trim_line_end+0x10>
jmp    1141 <trim_line_end+0x31>
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
je     1149 <trim_line_end+0x39>
mov    %rcx,%rbx
cmp    %r14,%rcx
ja     1130 <trim_line_end+0x20>
movb   $0x0,0x1(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @trim_line_end(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %9, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %3
br label %5
12: ; preds = %5
br label %13
13: ; preds = %26, %12
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = load i8*, i8** %2
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = load i8, i8* %20
%22 = call i64 @isspace(i8 signext %21)
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %18, %13
%25 = phi i1 [ false, %13 ], [ %23, %18 ]
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %3
br label %13
29: ; preds = %24
%30 = load i8*, i8** %3
store i8 0, i8* %30
ret void
}

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