#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 *strip_trailing_whitespace(char *p_str) {
  int len;
  char *p_tmp;
  len = strlen(p_str);
  if (len == 0)
    return p_str;
  p_tmp = p_str + len - 1;
  while (*p_tmp == ' ' || *p_tmp == '\n')
    p_tmp--;
  p_tmp++;
  *p_tmp = '\0';
  return p_str;
}


x86 assembly (clang, -O0):
<strip_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    113f <strip_trailing_whitespace+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <strip_trailing_whitespace+0xa3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x21(%rbp)
je     1177 <strip_trailing_whitespace+0x67>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1187 <strip_trailing_whitespace+0x77>
jmp    1198 <strip_trailing_whitespace+0x88>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1152 <strip_trailing_whitespace+0x42>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_trailing_whitespace>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     1148 <strip_trailing_whitespace+0x38>
cltq
add    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rcx
add    $0xffffffffffffffff,%rax
movzbl -0x1(%rcx),%edx
cmp    $0xa,%dl
je     1130 <strip_trailing_whitespace+0x20>
cmp    $0x20,%dl
je     1130 <strip_trailing_whitespace+0x20>
movb   $0x0,(%rcx)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @strip_trailing_whitespace(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %11, %4
%8 = phi i8* [ %6, %4 ], [ %9, %11 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
switch i8 %10, label %12 [
i8 32, label %11
i8 10, label %11
]
11: ; preds = %7, %7
br label %7
12: ; preds = %7
store i8 0, i8* %8
br label %13
13: ; preds = %1, %12
ret i8* %0
}