#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 *);
int /*<<< orphan*/ trim_leading(char *, size_t);
void trim(char *string, size_t buffsize) {
  char *ptr;
  trim_leading(string, buffsize);
  ptr = string + (strlen(string) - 1);
  while (ptr >= string && (*ptr == ' ' || *ptr == '\t'))
    ptr--;
  *(ptr + 1) = 0;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <trim_leading@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
jb     119f <trim+0x7f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x22(%rbp)
je     1199 <trim+0x79>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11af <trim+0x8f>
jmp    11c0 <trim+0xa0>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1161 <trim+0x41>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %rbx
mov    %rdi,%rbx
call   1030 <trim_leading@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    (%rcx,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
test   %ecx,%ecx
jg     1159 <trim+0x39>
jmp    1166 <trim+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jb     1166 <trim+0x46>
movzbl (%rax),%ecx
cmp    $0x20,%cl
je     1150 <trim+0x30>
cmp    $0x9,%cl
je     1150 <trim+0x30>
movb   $0x0,0x1(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @trim(i8* %0, i64 %1) {
%3 = tail call i32 @trim_leading(i8* %0, i64 %1)
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = icmp slt i32 %4, 1
br i1 %8, label %15, label %9
9: ; preds = %2, %12
%10 = phi i8* [ %13, %12 ], [ %7, %2 ]
%11 = load i8, i8* %10
switch i8 %11, label %15 [
i8 32, label %12
i8 9, label %12
]
12: ; preds = %9, %9
%13 = getelementptr inbounds i8, i8* %10, i64 -1
%14 = icmp ult i8* %13, %0
br i1 %14, label %15, label %9
15: ; preds = %12, %9, %2
%16 = phi i8* [ %7, %2 ], [ %10, %9 ], [ %13, %12 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 0, i8* %17
ret void
}