#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 const *);
const char *check_trailing_barchar(const char *str) {
  register const char *p = str + strlen(str);
  while (*--p == ' ' && p > str)
    ;
  return *p == '|' ? p : (char *)0;
}


x86 assembly (clang, -O0):
<check_trailing_barchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
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
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
jne    116c <check_trailing_barchar+0x5c>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117c <check_trailing_barchar+0x6c>
jmp    1181 <check_trailing_barchar+0x71>
jmp    113d <check_trailing_barchar+0x2d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7c,%eax
jne    119e <check_trailing_barchar+0x8e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11a9 <check_trailing_barchar+0x99>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11a9 <check_trailing_barchar+0x99>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_trailing_barchar>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rax),%edx
lea    -0x1(%rax),%rcx
cmp    $0x20,%dl
jne    1144 <check_trailing_barchar+0x34>
cmp    %rbx,%rax
mov    %rcx,%rax
ja     1130 <check_trailing_barchar+0x20>
add    $0x1,%rcx
xor    %eax,%eax
cmp    $0x7c,%dl
cmove  %rcx,%rax
pop    %rbx
ret

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

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