#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 *providers_trim_spaces(char *text) {
  char *tmp = text;
  while (tmp[0] == ' ')
    tmp++;
  while (strlen(tmp) > 1)
    if (tmp[strlen(tmp) - 1] == ' ')
      tmp[strlen(tmp) - 1] = '\0';
    else
      break;
  if (tmp[0] == ' ')
    tmp[0] = '\0';
  return tmp;
}


x86 assembly (clang, -O0):
<providers_trim_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1145 <providers_trim_spaces+0x35>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <providers_trim_spaces+0x14>
jmp    114a <providers_trim_spaces+0x3a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    11b6 <providers_trim_spaces+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11ac <providers_trim_spaces+0x9c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11b1 <providers_trim_spaces+0xa1>
jmp    11b6 <providers_trim_spaces+0xa6>
jmp    114a <providers_trim_spaces+0x3a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11cd <providers_trim_spaces+0xbd>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<providers_trim_spaces>:
push   %rbx
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1120 <providers_trim_spaces+0x10>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     116d <providers_trim_spaces+0x5d>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x20,-0x1(%rax,%rbx,1)
jne    116d <providers_trim_spaces+0x5d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jg     1140 <providers_trim_spaces+0x30>
cmpb   $0x20,(%rbx)
jne    1175 <providers_trim_spaces+0x65>
movb   $0x0,(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @providers_trim_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %11, %1
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 32
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
br label %5
14: ; preds = %5
br label %15
15: ; preds = %37, %14
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i8*, i8** %3
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 32
br i1 %28, label %29, label %36
29: ; preds = %19
%30 = load i8*, i8** %3
%31 = load i8*, i8** %3
%32 = call i32 @strlen(i8* %31)
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %30, i64 %34
store i8 0, i8* %35
br label %37
36: ; preds = %19
br label %38
37: ; preds = %29
br label %15
38: ; preds = %36, %15
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 32
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 0
store i8 0, i8* %46
br label %47
47: ; preds = %44, %38
%48 = load i8*, i8** %3
ret i8* %48
}

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