#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 /*<<< orphan*/ __strCopySub(char **, char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
char *strCreate();
size_t strFindFirstNotOf(char *, char *);
size_t strFindLastNotOf(char *, char *);
int /*<<< orphan*/ strFree(char *);
void __strTrim(char **stringPtr) {
  char *ns;
  size_t pos1;
  size_t pos2;
  assert(stringPtr != NULL);
  assert(*stringPtr != NULL);
  ns = strCreate();
  pos1 = strFindFirstNotOf(*stringPtr, " \t\r\n");
  if (pos1 >= 0) {
    pos2 = strFindLastNotOf(&(*stringPtr)[pos1], " \t\r\n");
    if (pos2 >= 0)
      __strCopySub(&ns, &(*stringPtr)[pos1], 0, pos2 + 1);
  }
  strFree(*stringPtr);
  *stringPtr = ns;
}


x86 assembly (clang, -O0):
<__strTrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1040 <strCreate@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe54(%rip),%rsi
call   1070 <strFindFirstNotOf@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jb     1209 <__strTrim+0xa9>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    -0x18(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1030 <strFindLastNotOf@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jb     1204 <__strTrim+0xa4>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
add    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
lea    -0x10(%rbp),%rdi
xor    %edx,%edx
call   1060 <__strCopySub@plt>
jmp    1209 <__strTrim+0xa9>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1080 <strFree@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__strTrim>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%r15)
setne  %dil
call   1050 <assert@plt>
xor    %eax,%eax
call   1040 <strCreate@plt>
mov    %rax,0x8(%rsp)
mov    (%r15),%rdi
lea    0xe61(%rip),%r14
mov    %r14,%rsi
call   1070 <strFindFirstNotOf@plt>
mov    %rax,%rbx
mov    (%r15),%rdi
add    %rax,%rdi
mov    %r14,%rsi
call   1030 <strFindLastNotOf@plt>
add    (%r15),%rbx
lea    0x1(%rax),%rcx
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <__strCopySub@plt>
mov    (%r15),%rdi
call   1080 <strFree@plt>
mov    0x8(%rsp),%rax
mov    %rax,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c" \09\0D\0A\00"
define void @__strTrim(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8** %0, i8*** %2
%6 = load i8**, i8*** %2
%7 = icmp ne i8** %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8**, i8*** %2
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i8* (...) @strCreate()
store i8* %15, i8** %3
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = call i64 @strFindFirstNotOf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 %18, i64* %4
%19 = load i64, i64* %4
%20 = icmp uge i64 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %1
%22 = load i8**, i8*** %2
%23 = load i8*, i8** %22
%24 = load i64, i64* %4
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = call i64 @strFindLastNotOf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 %26, i64* %5
%27 = load i64, i64* %5
%28 = icmp uge i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %21
%30 = load i8**, i8*** %2
%31 = load i8*, i8** %30
%32 = load i64, i64* %4
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = load i64, i64* %5
%35 = add i64 %34, 1
%36 = call i32 @__strCopySub(i8** %3, i8* %33, i32 0, i64 %35)
br label %37
37: ; preds = %29, %21
br label %38
38: ; preds = %37, %1
%39 = load i8**, i8*** %2
%40 = load i8*, i8** %39
%41 = call i32 @strFree(i8* %40)
%42 = load i8*, i8** %3
%43 = load i8**, i8*** %2
store i8* %42, i8** %43
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0D\0A\00"
define void @__strTrim(i8** %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp ne i8** %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i8*, i8** %0
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i8* (...) @strCreate()
store i8* %11, i8** %2
%12 = load i8*, i8** %0
%13 = tail call i64 @strFindFirstNotOf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %0
%15 = getelementptr inbounds i8, i8* %14, i64 %13
%16 = tail call i64 @strFindLastNotOf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %0
%18 = getelementptr inbounds i8, i8* %17, i64 %13
%19 = add i64 %16, 1
%20 = call i32 @__strCopySub(i8** %2, i8* %18, i32 0, i64 %19)
%21 = load i8*, i8** %0
%22 = call i32 @strFree(i8* %21)
%23 = load i8*, i8** %2
store i8* %23, i8** %0
ret void
}