#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 *rm_beginning_ws(char *str) {
  char *s = str + strlen(str) - 1;
  while (*s == '\t' || *s == ' ') {
    *s = '\0';
    s--;
  }
  s = str;
  while (*s == '\t' || *s == ' ') {
    s++;
  }
  return s;
}


x86 assembly (clang, -O0):
<rm_beginning_ws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x19(%rbp)
je     1166 <rm_beginning_ws+0x56>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1176 <rm_beginning_ws+0x66>
jmp    118e <rm_beginning_ws+0x7e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1141 <rm_beginning_ws+0x31>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x1a(%rbp)
je     11bb <rm_beginning_ws+0xab>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11cb <rm_beginning_ws+0xbb>
jmp    11dc <rm_beginning_ws+0xcc>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1196 <rm_beginning_ws+0x86>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_beginning_ws>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
jmp    1137 <rm_beginning_ws+0x27>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
movzbl (%rax),%ecx
cmp    $0x9,%cl
je     1130 <rm_beginning_ws+0x20>
cmp    $0x20,%cl
je     1130 <rm_beginning_ws+0x20>
jmp    1154 <rm_beginning_ws+0x44>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x20,%al
je     1150 <rm_beginning_ws+0x40>
cmp    $0x9,%al
je     1150 <rm_beginning_ws+0x40>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @rm_beginning_ws(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
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %3
br label %10
10: ; preds = %22, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 9
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br label %20
20: ; preds = %15, %10
%21 = phi i1 [ true, %10 ], [ %19, %15 ]
br i1 %21, label %22, label %26
22: ; preds = %20
%23 = load i8*, i8** %3
store i8 0, i8* %23
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %3
br label %10
26: ; preds = %20
%27 = load i8*, i8** %2
store i8* %27, i8** %3
br label %28
28: ; preds = %40, %26
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 9
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i8*, i8** %3
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 32
br label %38
38: ; preds = %33, %28
%39 = phi i1 [ true, %28 ], [ %37, %33 ]
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %3
br label %28
43: ; preds = %38
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
define i8* @rm_beginning_ws(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 = %9, %1
%6 = phi i8* [ %4, %1 ], [ %7, %9 ]
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = load i8, i8* %7
switch i8 %8, label %10 [
i8 9, label %9
i8 32, label %9
]
9: ; preds = %5, %5
store i8 0, i8* %7
br label %5
10: ; preds = %5, %13
%11 = phi i8* [ %14, %13 ], [ %0, %5 ]
%12 = load i8, i8* %11
switch i8 %12, label %15 [
i8 9, label %13
i8 32, label %13
]
13: ; preds = %10, %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
br label %10
15: ; preds = %10
ret i8* %11
}