#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*/ deleteCharacter(char *, int);
scalar_t__ isspace(char);
int strlen(char *);
void trimSpaces(char *string) {
  while (strlen(string) >= 1 && isspace(string[0])) {
    deleteCharacter(string, 0);
  }
  while (strlen(string) >= 1 && isspace(string[strlen(string) - 1])) {
    deleteCharacter(string, strlen(string) - 1);
  }
}


x86 assembly (clang, -O0):
<trimSpaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x9(%rbp)
jl     116b <trimSpaces+0x3b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    117b <trimSpaces+0x4b>
jmp    118b <trimSpaces+0x5b>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <deleteCharacter@plt>
jmp    113c <trimSpaces+0xc>
jmp    1190 <trimSpaces+0x60>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0xa(%rbp)
jl     11d9 <trimSpaces+0xa9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
test   $0x1,%al
jne    11e9 <trimSpaces+0xb9>
jmp    120d <trimSpaces+0xdd>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
sub    $0x1,%esi
call   1050 <deleteCharacter@plt>
jmp    1190 <trimSpaces+0x60>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimSpaces>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1030 <strlen@plt>
test   %eax,%eax
jle    119c <trimSpaces+0x6c>
movsbl (%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     119c <trimSpaces+0x6c>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <deleteCharacter@plt>
mov    %rbx,%rdi
jmp    1140 <trimSpaces+0x10>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11a8 <trimSpaces+0x78>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    -0x1(%rax),%esi
mov    %rbx,%rdi
call   1050 <deleteCharacter@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jg     1170 <trimSpaces+0x40>
pop    %rbx
ret

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

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