#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__ is_space(char);
int strlen(char *);
char *chop(char *line) {
  if (line) {
    char *p1 = line + strlen(line);
    if (!*p1)
      p1--;
    while ((p1 > line) && is_space(*p1))
      p1--;
    *(++p1) = 0;
  }
  return line;
}


x86 assembly (clang, -O0):
<chop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d3 <chop+0xb3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1171 <chop+0x51>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1176 <chop+0x56>
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jbe    119f <chop+0x7f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <is_space@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11af <chop+0x8f>
jmp    11c0 <chop+0xa0>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1176 <chop+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chop>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     116d <chop+0x4d>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x1,(%r14,%rax,1)
lea    (%r14,%rax,1),%rbx
sbb    $0x0,%rbx
cmp    %r14,%rbx
jbe    1169 <chop+0x49>
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <is_space@plt>
test   %rax,%rax
je     1169 <chop+0x49>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
ja     1150 <chop+0x30>
mov    %r14,%rbx
movb   $0x0,0x1(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @chop(i8* returned %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = sext i1 %8 to i64
%10 = getelementptr i8, i8* %6, i64 %9
%11 = icmp ugt i8* %10, %0
br i1 %11, label %12, label %20
12: ; preds = %3, %17
%13 = phi i8* [ %18, %17 ], [ %10, %3 ]
%14 = load i8, i8* %13
%15 = tail call i64 @is_space(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %13, i64 -1
%19 = icmp ugt i8* %18, %0
br i1 %19, label %12, label %20
20: ; preds = %12, %17, %3
%21 = phi i8* [ %10, %3 ], [ %0, %17 ], [ %13, %12 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 0, i8* %22
br label %23
23: ; preds = %20, %1
ret i8* %0
}