#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 */
int strlen(char *);
char *rstrip(char *s) {
  int len;
  if (s == NULL)
    return s;
  len = strlen(s);
  if (len < 1)
    return s;
  len--;
  while (s[len] == ' ') {
    s[len] = (char)0;
    len--;
    if (len < 0)
      break;
  }
  return s;
}


x86 assembly (clang, -O0):
<rstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <rstrip+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <rstrip+0x96>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1157 <rstrip+0x47>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <rstrip+0x96>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    119e <rstrip+0x8e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1199 <rstrip+0x89>
jmp    119e <rstrip+0x8e>
jmp    1160 <rstrip+0x50>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rstrip>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     114d <rstrip+0x3d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    114d <rstrip+0x3d>
mov    %eax,%eax
nopw   0x0(%rax,%rax,1)
cmpb   $0x20,-0x1(%rbx,%rax,1)
jne    114d <rstrip+0x3d>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
test   $0xfffffffe,%eax
mov    %rcx,%rax
jne    1130 <rstrip+0x20>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @rstrip(i8* returned %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 = icmp slt i32 %4, 1
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %14
%9 = phi i64 [ %7, %6 ], [ %10, %14 ]
%10 = add nsw i64 %9, -1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 32
br i1 %13, label %14, label %17
14: ; preds = %8
store i8 0, i8* %11
%15 = and i64 %9, 4294967294
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %8, %14, %3, %1
ret i8* %0
}