#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);
int strlen(char *);
char *ui_cmd_remove_trailing_ws(char *input) {
  if (!input)
    return NULL;
  char *input_end = input + strlen(input) - 1;
  while (input_end && isspace(*input_end)) {
    *input_end = '\0';
    input_end--;
  }
  return input;
}


x86 assembly (clang, -O0):
<ui_cmd_remove_trailing_ws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <ui_cmd_remove_trailing_ws+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11bf <ui_cmd_remove_trailing_ws+0x9f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x21(%rbp)
je     118f <ui_cmd_remove_trailing_ws+0x6f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    119f <ui_cmd_remove_trailing_ws+0x7f>
jmp    11b7 <ui_cmd_remove_trailing_ws+0x97>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1169 <ui_cmd_remove_trailing_ws+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ui_cmd_remove_trailing_ws>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     1165 <ui_cmd_remove_trailing_ws+0x45>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1165 <ui_cmd_remove_trailing_ws+0x45>
add    %r14,%rbx
add    $0xffffffffffffffff,%rbx
xchg   %ax,%ax
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1150 <ui_cmd_remove_trailing_ws+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @ui_cmd_remove_trailing_ws(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, 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 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = load i8, i8* %7
%9 = tail call i64 @isspace(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %3, %11
%12 = phi i8* [ %13, %11 ], [ %7, %3 ]
store i8 0, i8* %12
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = load i8, i8* %13
%15 = tail call i64 @isspace(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %11
17: ; preds = %11, %3, %1
ret i8* %0
}