#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ str_rstrip(char *);
int strlen(char *);
void test_str_rstrip() {
  char buf1[] = "meep\n \n";
  str_rstrip(buf1);
  assert(strlen(buf1) == 4);
  char buf2[] = "mep\n";
  str_rstrip(buf2);
  assert(strlen(buf2) == 3);
  char buf3[] = "";
  str_rstrip(buf3);
  assert(strlen(buf3) == 0);
  char buf4[] = "\0\1";
  str_rstrip(buf4);
  assert(buf4[0] == '\0' && buf4[1] == '\1');
  char buf5[] = "  \n \t";
  str_rstrip(buf5);
  assert(strlen(buf5) == 0);
}


x86 assembly (clang, -O0):
<test_str_rstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <str_rstrip@plt>
lea    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0xe8d(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x9(%rbp)
lea    -0xd(%rbp),%rdi
call   1060 <str_rstrip@plt>
lea    -0xd(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <memset@plt>
lea    -0xe(%rbp),%rdi
call   1060 <str_rstrip@plt>
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0xe31(%rip),%ax
mov    %ax,-0x11(%rbp)
mov    0xe29(%rip),%al
mov    %al,-0xf(%rbp)
lea    -0x11(%rbp),%rdi
call   1060 <str_rstrip@plt>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x18(%rbp)
jne    1217 <test_str_rstrip+0xd7>
movsbl -0x10(%rbp),%eax
cmp    $0x1,%eax
sete   %al
mov    %al,-0x18(%rbp)
mov    -0x18(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0xde3(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xddd(%rip),%ax
mov    %ax,-0x13(%rbp)
lea    -0x17(%rbp),%rdi
call   1060 <str_rstrip@plt>
lea    -0x17(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_rstrip>:
push   %rbx
sub    $0x20,%rsp
movabs $0xa200a7065656d,%rax
mov    %rax,0x18(%rsp)
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <str_rstrip@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1040 <assert@plt>
movb   $0x0,0xc(%rsp)
movl   $0xa70656d,0x8(%rsp)
0a
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <str_rstrip@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1040 <assert@plt>
movb   $0x0,0x3(%rsp)
lea    0x3(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <str_rstrip@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
movb   $0x0,0x6(%rsp)
movw   $0x100,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1050 <str_rstrip@plt>
mov    0x5(%rsp),%al
xor    $0x1,%al
xor    %edi,%edi
or     0x4(%rsp),%al
sete   %dil
call   1040 <assert@plt>
movw   $0x9,0x14(%rsp)
movl   $0x200a2020,0x10(%rsp)
20
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <str_rstrip@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_str_rstrip.buf1 = [8 x i8] c"meep\0A \0A\00"
@__const.test_str_rstrip.buf2 = [5 x i8] c"mep\0A\00"
@__const.test_str_rstrip.buf4 = [3 x i8] c"\00\01\00"
@__const.test_str_rstrip.buf5 = [6 x i8] c" \0A \09\00"
define void @test_str_rstrip() {
%1 = alloca [8 x i8]
%2 = alloca [5 x i8]
%3 = alloca [1 x i8]
%4 = alloca [3 x i8]
%5 = alloca [6 x i8]
%6 = bitcast [8 x i8]* %1 to i8*
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%8 = call i32 @str_rstrip(i8* %7)
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = icmp eq i32 %10, 4
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = bitcast [5 x i8]* %2 to i8*
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%16 = call i32 @str_rstrip(i8* %15)
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = icmp eq i32 %18, 3
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = bitcast [1 x i8]* %3 to i8*
%23 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%24 = call i32 @str_rstrip(i8* %23)
%25 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = bitcast [3 x i8]* %4 to i8*
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%32 = call i32 @str_rstrip(i8* %31)
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %0
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 1
br label %42
42: ; preds = %37, %0
%43 = phi i1 [ false, %0 ], [ %41, %37 ]
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = bitcast [6 x i8]* %5 to i8*
%47 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%48 = call i32 @str_rstrip(i8* %47)
%49 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = icmp eq i32 %50, 0
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
ret void
}

LLVM IR (-O2):
@__const.test_str_rstrip.buf2 = [5 x i8] c"mep\0A\00"
@__const.test_str_rstrip.buf4 = [3 x i8] c"\00\01\00"
@__const.test_str_rstrip.buf5 = [6 x i8] c" \0A \09\00"
define void @test_str_rstrip() {
%1 = alloca i64
%2 = alloca [5 x i8]
%3 = alloca [1 x i8]
%4 = alloca [3 x i8]
%5 = alloca [6 x i8]
%6 = bitcast i64* %1 to i8*
store i64 2849978974561645, i64* %1
%7 = call i32 @str_rstrip(i8* %6)
%8 = call i32 @strlen(i8* %6)
%9 = icmp eq i32 %8, 4
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%13 = call i32 @str_rstrip(i8* %12)
%14 = call i32 @strlen(i8* %12)
%15 = icmp eq i32 %14, 3
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 0, i8* %18
%19 = call i32 @str_rstrip(i8* %18)
%20 = call i32 @strlen(i8* %18)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%25 = call i32 @str_rstrip(i8* %24)
%26 = load i8, i8* %24
%27 = icmp eq i8 %26, 0
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 1
%31 = select i1 %27, i1 %30, i1 false
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%35 = call i32 @str_rstrip(i8* %34)
%36 = call i32 @strlen(i8* %34)
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
ret void
}