#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 *);
void str_trim(char **string) {
  while (isspace(**string)) {
    (*string)++;
  }
  if (**string == 0) {
    return;
  }
  char *end = *string + strlen(*string) - 1;
  while (end > *string && isspace(*end)) {
    end--;
  }
  *(end + 1) = 0;
}


x86 assembly (clang, -O0):
<str_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1158 <str_trim+0x38>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    112c <str_trim+0xc>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1170 <str_trim+0x50>
jmp    11f0 <str_trim+0xd0>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
mov    %al,-0x19(%rbp)
jbe    11c7 <str_trim+0xa7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11d7 <str_trim+0xb7>
jmp    11e8 <str_trim+0xc8>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    119b <str_trim+0x7b>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_trim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rdi),%rax
movsbl (%rax),%edi
xchg   %ax,%ax
call   1040 <isspace@plt>
test   %rax,%rax
je     114a <str_trim+0x2a>
mov    (%r15),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%r15)
movsbl 0x1(%rax),%edi
jmp    1130 <str_trim+0x10>
mov    (%r15),%r14
cmpb   $0x0,(%r14)
je     118d <str_trim+0x6d>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rcx
add    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rcx,%rbx
cmp    (%r15),%rcx
jbe    1189 <str_trim+0x69>
movsbl (%rbx),%edi
call   1040 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
jne    1170 <str_trim+0x50>
movb   $0x0,0x1(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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