#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);
char *kore_text_trim(char *string, size_t len) {
  char *end;
  if (len == 0)
    return (string);
  end = string + len;
  while (isspace(*string))
    string++;
  while (isspace(*end) && end > string)
    *(end)-- = '\0';
  return (string);
}


x86 assembly (clang, -O0):
<kore_text_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1138 <kore_text_trim+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cb <kore_text_trim+0xbb>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     116b <kore_text_trim+0x5b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <kore_text_trim+0x34>
jmp    1170 <kore_text_trim+0x60>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     119c <kore_text_trim+0x8c>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ac <kore_text_trim+0x9c>
jmp    11c3 <kore_text_trim+0xb3>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
jmp    1170 <kore_text_trim+0x60>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kore_text_trim>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
test   %rsi,%rsi
je     118d <kore_text_trim+0x7d>
mov    %rsi,%r14
lea    -0x1(%r15),%r12
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%r12),%edi
add    $0x1,%r12
call   1030 <isspace@plt>
test   %rax,%rax
jne    1130 <kore_text_trim+0x20>
lea    (%r15,%r14,1),%rbx
movsbl (%r15,%r14,1),%edi
call   1030 <isspace@plt>
cmp    %r12,%rbx
jbe    118a <kore_text_trim+0x7a>
test   %rax,%rax
je     118a <kore_text_trim+0x7a>
lea    (%r14,%r15,1),%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,0x1(%rbx)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
cmp    %r12,%rbx
jbe    118a <kore_text_trim+0x7a>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1170 <kore_text_trim+0x60>
mov    %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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