#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(int);
char *strchr(char *, char);
int strlen(char *);
void strtrail(char *wrk) {
  char *p;
  if (wrk == NULL)
    return;
  if ((p = strchr(wrk, '\n')) != NULL)
    *p = 0;
  if ((p = strchr(wrk, '\r')) != NULL)
    *p = 0;
  while (isspace((int)*(wrk + strlen(wrk) - 1)))
    *(wrk + strlen(wrk) - 1) = 0;
}


x86 assembly (clang, -O0):
<strtrail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114c <strtrail+0x1c>
jmp    11e9 <strtrail+0xb9>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     116f <strtrail+0x3f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1192 <strtrail+0x62>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1197 <strtrail+0x67>
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
movsbl -0x1(%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11e9 <strtrail+0xb9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    1197 <strtrail+0x67>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtrail>:
push   %rbx
test   %rdi,%rdi
je     1198 <strtrail+0x68>
mov    %rdi,%rbx
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     114b <strtrail+0x1b>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     117f <strtrail+0x4f>
movb   $0x0,(%rax)
jmp    117f <strtrail+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rbx,%rax,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1170 <strtrail+0x40>
pop    %rbx
ret

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

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