#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__ strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ ytht_strsncpy(char *, char *, int);
char *ytht_strrtrim(char *s) {
  static char t[1024], *t2;
  if (s[0] == 0)
    return s;
  ytht_strsncpy(t, s, 1024);
  t2 = t + strlen(s) - 1;
  while (strchr(" \t\r\n", t2[0]) && t2 > t)
    t2--;
  t2[1] = 0;
  return t;
}


x86 assembly (clang, -O0):
<ytht_strrtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1159 <ytht_strrtrim+0x29>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <ytht_strrtrim+0xd8>
mov    -0x10(%rbp),%rsi
lea    0x2eec(%rip),%rdi
mov    $0x400,%edx
call   1050 <ytht_strsncpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
lea    0x2ecf(%rip),%rax
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x32c1(%rip)
mov    0x32ba(%rip),%rax
lea    0xe63(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     11cb <ytht_strrtrim+0x9b>
lea    0x2e92(%rip),%rax
cmp    %rax,0x328b(%rip)
seta   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11db <ytht_strrtrim+0xab>
jmp    11f2 <ytht_strrtrim+0xc2>
mov    0x326e(%rip),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x3263(%rip)
jmp    118f <ytht_strrtrim+0x5f>
mov    0x3257(%rip),%rax
movb   $0x0,0x1(%rax)
lea    0x2e4c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ytht_strrtrim>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     119e <ytht_strrtrim+0x6e>
lea    0x2f0d(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <ytht_strsncpy@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
add    %rbx,%rcx
lea    0xe98(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rcx),%rax
mov    %rax,0x32d5(%rip)
movsbl -0x1(%rcx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
mov    0x32c2(%rip),%rcx
test   %rax,%rax
je     1198 <ytht_strrtrim+0x68>
cmp    %rbx,%rcx
ja     1170 <ytht_strrtrim+0x40>
movb   $0x0,0x1(%rcx)
jmp    11a1 <ytht_strrtrim+0x71>
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ytht_strrtrim.t = internal global [1024 x i8] zeroinitializer
@ytht_strrtrim.t2 = internal global i8* null
@.str = [5 x i8] c" \09\0D\0A\00"
define i8* @ytht_strrtrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i8*, i8** %3
store i8* %10, i8** %2
br label %36
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @ytht_strsncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 0), i8* %12, i32 1024)
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 0), i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -1
store i8* %18, i8** @ytht_strrtrim.t2
br label %19
19: ; preds = %30, %11
%20 = load i8*, i8** @ytht_strrtrim.t2
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** @ytht_strrtrim.t2
%27 = icmp ugt i8* %26, getelementptr inbounds ([1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 0)
br label %28
28: ; preds = %25, %19
%29 = phi i1 [ false, %19 ], [ %27, %25 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** @ytht_strrtrim.t2
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** @ytht_strrtrim.t2
br label %19
33: ; preds = %28
%34 = load i8*, i8** @ytht_strrtrim.t2
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8 0, i8* %35
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 0), i8** %2
br label %36
36: ; preds = %33, %9
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@ytht_strrtrim.t = internal global [1024 x i8] zeroinitializer
@ytht_strrtrim.t2 = internal unnamed_addr global i8* null
@.str = [5 x i8] c" \09\0D\0A\00"
define i8* @ytht_strrtrim(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = tail call i32 @ytht_strsncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 0), i8* %0, i32 1024)
%6 = tail call i32 @strlen(i8* %0)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 %7
br label %9
9: ; preds = %9, %4
%10 = phi i8* [ %8, %4 ], [ %15, %9 ]
%11 = getelementptr inbounds i8, i8* %10, i64 -1
store i8* %11, i8** @ytht_strrtrim.t2
%12 = load i8, i8* %11
%13 = tail call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = icmp ne i64 %13, 0
%15 = load i8*, i8** @ytht_strrtrim.t2
%16 = icmp ugt i8* %15, getelementptr inbounds ([1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 0)
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %9, label %18
18: ; preds = %9
%19 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %19
br label %20
20: ; preds = %1, %18
%21 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @ytht_strrtrim.t, i64 0, i64 0), %18 ], [ %0, %1 ]
ret i8* %21
}