#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 */
scalar_t__ isspace(unsigned char);
int /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
void http_utils_trim_whitespace(char **str) {
  char *end, *start;
  if (str == NULL) {
    return;
  }
  start = *str;
  if (start == NULL) {
    return;
  }
  while (isspace((unsigned char)*start))
    start++;
  if (*start == 0) {
    **str = 0;
    return;
  }
  end = (char *)(start + strlen(start) - 1);
  while (end > start && isspace((unsigned char)*end)) {
    end--;
  }
  *(end + 1) = 0;
  memmove(*str, start, strlen(start) + 1);
}


x86 assembly (clang, -O0):
<http_utils_trim_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114c <http_utils_trim_whitespace+0x1c>
jmp    1257 <http_utils_trim_whitespace+0x127>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <http_utils_trim_whitespace+0x37>
jmp    1257 <http_utils_trim_whitespace+0x127>
jmp    116c <http_utils_trim_whitespace+0x3c>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1193 <http_utils_trim_whitespace+0x63>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116c <http_utils_trim_whitespace+0x3c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b2 <http_utils_trim_whitespace+0x82>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
jmp    1257 <http_utils_trim_whitespace+0x127>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x21(%rbp)
jbe    1200 <http_utils_trim_whitespace+0xd0>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1210 <http_utils_trim_whitespace+0xe0>
jmp    1221 <http_utils_trim_whitespace+0xf1>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11d7 <http_utils_trim_whitespace+0xa7>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <memmove@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_utils_trim_whitespace>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     11de <http_utils_trim_whitespace+0xae>
mov    %rdi,%r14
mov    (%rdi),%rbx
test   %rbx,%rbx
je     11de <http_utils_trim_whitespace+0xae>
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1160 <http_utils_trim_whitespace+0x30>
cmpb   $0x0,(%rbx)
je     11d8 <http_utils_trim_whitespace+0xa8>
lea    -0x1(%rbx),%r13
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%r12
lea    (%r15,%r13,1),%rax
cmp    %rbx,%rax
jbe    11b0 <http_utils_trim_whitespace+0x80>
movzbl (%r12,%r15,1),%edi
call   1040 <isspace@plt>
lea    -0x1(%r12),%r13
test   %rax,%rax
jne    1190 <http_utils_trim_whitespace+0x60>
movb   $0x0,0x1(%r12,%r15,1)
mov    (%r14),%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <memmove@plt>
mov    (%r14),%rax
movb   $0x0,(%rax)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @http_utils_trim_whitespace(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
store i8** %0, i8*** %2
%5 = load i8**, i8*** %2
%6 = icmp eq i8** %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
br label %62
8: ; preds = %1
%9 = load i8**, i8*** %2
%10 = load i8*, i8** %9
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %8
br label %62
14: ; preds = %8
br label %15
15: ; preds = %20, %14
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = call i64 @isspace(i8 zeroext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
br label %15
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i8**, i8*** %2
%30 = load i8*, i8** %29
store i8 0, i8* %30
br label %62
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = getelementptr inbounds i8, i8* %36, i64 -1
store i8* %37, i8** %3
br label %38
38: ; preds = %49, %31
%39 = load i8*, i8** %3
%40 = load i8*, i8** %4
%41 = icmp ugt i8* %39, %40
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i8*, i8** %3
%44 = load i8, i8* %43
%45 = call i64 @isspace(i8 zeroext %44)
%46 = icmp ne i64 %45, 0
br label %47
47: ; preds = %42, %38
%48 = phi i1 [ false, %38 ], [ %46, %42 ]
br i1 %48, label %49, label %52
49: ; preds = %47
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i32 -1
store i8* %51, i8** %3
br label %38
52: ; preds = %47
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i64 1
store i8 0, i8* %54
%55 = load i8**, i8*** %2
%56 = load i8*, i8** %55
%57 = load i8*, i8** %4
%58 = load i8*, i8** %4
%59 = call i32 @strlen(i8* %58)
%60 = add nsw i32 %59, 1
%61 = call i32 @memmove(i8* %56, i8* %57, i32 %60)
br label %62
62: ; preds = %52, %28, %13, %7
ret void
}

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