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


x86 assembly (clang, -O0):
<cli_text_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1138 <cli_text_trim+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f5 <cli_text_trim+0xe5>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     1174 <cli_text_trim+0x64>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1184 <cli_text_trim+0x74>
jmp    1195 <cli_text_trim+0x85>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1148 <cli_text_trim+0x38>
jmp    119a <cli_text_trim+0x8a>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x22(%rbp)
je     11c6 <cli_text_trim+0xb6>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
seta   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11d6 <cli_text_trim+0xc6>
jmp    11ed <cli_text_trim+0xdd>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
jmp    119a <cli_text_trim+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_text_trim>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
test   %rsi,%rsi
je     118d <cli_text_trim+0x7d>
mov    %rsi,%r14
lea    (%r15,%rsi,1),%r12
add    $0xffffffffffffffff,%r12
mov    %r15,%r13
nop
mov    %r13,%rbx
movzbl 0x0(%r13),%edi
call   1030 <isspace@plt>
add    $0x1,%r13
test   %rax,%rax
je     114b <cli_text_trim+0x3b>
cmp    %r12,%rbx
jb     1130 <cli_text_trim+0x20>
movzbl (%r12),%edi
call   1030 <isspace@plt>
add    $0xffffffffffffffff,%r13
cmp    %r12,%rbx
jae    118a <cli_text_trim+0x7a>
test   %rax,%rax
je     118a <cli_text_trim+0x7a>
lea    (%r14,%r15,1),%rbx
add    $0xfffffffffffffffe,%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x1(%rbx)
movzbl (%rbx),%edi
call   1030 <isspace@plt>
cmp    %r13,%rbx
jbe    118a <cli_text_trim+0x7a>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1170 <cli_text_trim+0x60>
mov    %r13,%r15
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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