#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(int);
int strlen(char *);
void trim_whitespace(char *string) {
  char *read = string, *write = string;
  char c;
  read = string + strlen(string) - 1;
  while (isspace((int)*read))
    read--;
  write = read + 1;
  *write = '\0';
  for (read = string; isspace((int)*read); read++)
    continue;
  write = string;
  while (*read != '\0') {
    c = *read;
    read++;
    *write = c;
    write++;
  }
  *write = '\0';
}


x86 assembly (clang, -O0):
<trim_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1188 <trim_whitespace+0x68>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1161 <trim_whitespace+0x41>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11cf <trim_whitespace+0xaf>
jmp    11be <trim_whitespace+0x9e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a3 <trim_whitespace+0x83>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1216 <trim_whitespace+0xf6>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11d7 <trim_whitespace+0xb7>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_whitespace>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl -0x2(%rbx),%edi
call   1040 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1140 <trim_whitespace+0x20>
movb   $0x0,(%rbx)
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <trim_whitespace+0x40>
mov    -0x1(%rbx),%al
test   %al,%al
je     1193 <trim_whitespace+0x73>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
mov    %al,(%r14,%rcx,1)
movzbl (%rbx,%rcx,1),%eax
add    $0x1,%rcx
test   %al,%al
jne    1180 <trim_whitespace+0x60>
add    %rcx,%r14
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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