#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(char);
int strlen(char *);
char *MemStr_Stripwhite(char *string) {
  char *s, *t;
  for (s = string; isspace(*s); s++)
    ;
  if (*s == 0)
    return s;
  t = s + strlen(s) - 1;
  while (t > s && isspace(*t))
    t--;
  *++t = '\0';
  return s;
}


x86 assembly (clang, -O0):
<MemStr_Stripwhite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1160 <MemStr_Stripwhite+0x40>
jmp    114f <MemStr_Stripwhite+0x2f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <MemStr_Stripwhite+0x14>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117d <MemStr_Stripwhite+0x5d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1207 <MemStr_Stripwhite+0xe7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x29(%rbp)
jbe    11cb <MemStr_Stripwhite+0xab>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11db <MemStr_Stripwhite+0xbb>
jmp    11ec <MemStr_Stripwhite+0xcc>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11a2 <MemStr_Stripwhite+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MemStr_Stripwhite>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nop
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1130 <MemStr_Stripwhite+0x10>
cmpb   $0x0,(%rbx)
je     1185 <MemStr_Stripwhite+0x65>
lea    -0x1(%rbx),%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%r15
lea    (%r12,%r14,1),%rax
cmp    %rbx,%rax
jbe    117f <MemStr_Stripwhite+0x5f>
movsbl (%r15,%r14,1),%edi
call   1040 <isspace@plt>
lea    -0x1(%r15),%r12
test   %rax,%rax
jne    1160 <MemStr_Stripwhite+0x40>
movb   $0x0,0x1(%r15,%r14,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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