#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 */
char *strchr(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
void TrimBuffer(char *buffer) {
  char *begin = buffer, *end;
  if (!buffer || !(*buffer))
    return;
  end = strchr(buffer, NULL) - 1;
  while ((end != buffer) &&
         ((*end == ' ') || (*end == '\t') || (*end == '\r') || (*end == '\n')))
    end--;
  if (end == buffer)
    *buffer = '\0';
  else
    *(end + 1) = '\0';
  while ((*begin == ' ') || (*begin == '\t'))
    begin++;
  if (*begin == '#')
    buffer[0] = '\0';
  else
    strcpy(buffer, begin);
}


x86 assembly (clang, -O0):
<TrimBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114c <TrimBuffer+0x2c>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1151 <TrimBuffer+0x31>
jmp    1285 <TrimBuffer+0x165>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strchr@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
je     11ce <TrimBuffer+0xae>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x1a(%rbp)
je     11c8 <TrimBuffer+0xa8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x1a(%rbp)
je     11c8 <TrimBuffer+0xa8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x1a(%rbp)
je     11c8 <TrimBuffer+0xa8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11de <TrimBuffer+0xbe>
jmp    11ef <TrimBuffer+0xcf>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <TrimBuffer+0x46>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1209 <TrimBuffer+0xe9>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1211 <TrimBuffer+0xf1>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1216 <TrimBuffer+0xf6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x1b(%rbp)
je     123b <TrimBuffer+0x11b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
test   $0x1,%al
jne    124b <TrimBuffer+0x12b>
jmp    125c <TrimBuffer+0x13c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1216 <TrimBuffer+0xf6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1278 <TrimBuffer+0x158>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1285 <TrimBuffer+0x165>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TrimBuffer>:
push   %rbx
test   %rdi,%rdi
je     1196 <TrimBuffer+0x76>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1196 <TrimBuffer+0x76>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
add    $0xffffffffffffffff,%rax
mov    %rbx,%rcx
cmp    %rbx,%rax
je     1174 <TrimBuffer+0x54>
movabs $0x100002600,%rcx
xchg   %ax,%ax
movzbl (%rax),%edx
cmp    $0x20,%rdx
ja     116d <TrimBuffer+0x4d>
bt     %rdx,%rcx
jae    116d <TrimBuffer+0x4d>
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jne    1150 <TrimBuffer+0x30>
mov    %rbx,%rcx
jmp    1174 <TrimBuffer+0x54>
add    $0x1,%rax
mov    %rax,%rcx
movb   $0x0,(%rcx)
mov    %rbx,%rsi
jmp    1184 <TrimBuffer+0x64>
nopl   0x0(%rax)
add    $0x1,%rsi
movzbl (%rsi),%eax
cmp    $0x9,%al
je     1180 <TrimBuffer+0x60>
cmp    $0x20,%al
je     1180 <TrimBuffer+0x60>
cmp    $0x23,%al
jne    1198 <TrimBuffer+0x78>
movb   $0x0,(%rbx)
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define void @TrimBuffer(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8, %1
br label %85
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i8* @strchr(i8* %14, i32* null)
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8* %16, i8** %4
br label %17
17: ; preds = %45, %13
%18 = load i8*, i8** %4
%19 = load i8*, i8** %2
%20 = icmp ne i8* %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 32
br i1 %25, label %41, label %26
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 9
br i1 %30, label %41, label %31
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 13
br i1 %35, label %41, label %36
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 10
br label %41
41: ; preds = %36, %31, %26, %21
%42 = phi i1 [ true, %31 ], [ true, %26 ], [ true, %21 ], [ %40, %36 ]
br label %43
43: ; preds = %41, %17
%44 = phi i1 [ false, %17 ], [ %42, %41 ]
br i1 %44, label %45, label %48
45: ; preds = %43
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 -1
store i8* %47, i8** %4
br label %17
48: ; preds = %43
%49 = load i8*, i8** %4
%50 = load i8*, i8** %2
%51 = icmp eq i8* %49, %50
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = load i8*, i8** %2
store i8 0, i8* %53
br label %57
54: ; preds = %48
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 1
store i8 0, i8* %56
br label %57
57: ; preds = %54, %52
br label %58
58: ; preds = %70, %57
%59 = load i8*, i8** %3
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 32
br i1 %62, label %68, label %63
63: ; preds = %58
%64 = load i8*, i8** %3
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 9
br label %68
68: ; preds = %63, %58
%69 = phi i1 [ true, %58 ], [ %67, %63 ]
br i1 %69, label %70, label %73
70: ; preds = %68
%71 = load i8*, i8** %3
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %3
br label %58
73: ; preds = %68
%74 = load i8*, i8** %3
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 35
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = load i8*, i8** %2
%80 = getelementptr inbounds i8, i8* %79, i64 0
store i8 0, i8* %80
br label %85
81: ; preds = %73
%82 = load i8*, i8** %2
%83 = load i8*, i8** %3
%84 = call i32 @strcpy(i8* %82, i8* %83)
br label %85
85: ; preds = %12, %81, %78
ret void
}

LLVM IR (-O2):
define void @TrimBuffer(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %27, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %27, label %6
6: ; preds = %3
%7 = tail call i8* @strchr(i8* %0, i32* null)
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp eq i8* %8, %0
br i1 %9, label %17, label %10
10: ; preds = %6, %14
%11 = phi i8* [ %15, %14 ], [ %8, %6 ]
%12 = phi i8* [ %11, %14 ], [ %7, %6 ]
%13 = load i8, i8* %11
switch i8 %13, label %17 [
i8 32, label %14
i8 9, label %14
i8 13, label %14
i8 10, label %14
]
14: ; preds = %10, %10, %10, %10
%15 = getelementptr inbounds i8, i8* %11, i64 -1
%16 = icmp eq i8* %15, %0
br i1 %16, label %17, label %10
17: ; preds = %10, %14, %6
%18 = phi i8* [ %0, %6 ], [ %0, %14 ], [ %12, %10 ]
store i8 0, i8* %18
br label %19
19: ; preds = %22, %17
%20 = phi i8* [ %0, %17 ], [ %23, %22 ]
%21 = load i8, i8* %20
switch i8 %21, label %25 [
i8 32, label %22
i8 9, label %22
i8 35, label %24
]
22: ; preds = %19, %19
%23 = getelementptr inbounds i8, i8* %20, i64 1
br label %19
24: ; preds = %19
store i8 0, i8* %0
br label %27
25: ; preds = %19
%26 = tail call i32 @strcpy(i8* %0, i8* %20)
br label %27
27: ; preds = %24, %25, %1, %3
ret void
}