#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);
unsigned int strlen(char *);
char *trim(char *szString) {
  unsigned int i = 0, j = strlen(szString);
  while (isspace(szString[i++]))
    ;
  while (isspace(szString[--j]))
    ;
  szString[j + 1] = 0;
  return &szString[i - 1];
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1168 <trim+0x48>
jmp    113f <trim+0x1f>
jmp    116d <trim+0x4d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1194 <trim+0x74>
jmp    116d <trim+0x4d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
movsbl (%r14,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <trim+0x20>
add    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
lea    -0x2(%r15),%eax
movsbl (%r14,%rax,1),%edi
call   1040 <isspace@plt>
add    $0xffffffff,%r15d
test   %rax,%rax
jne    1160 <trim+0x40>
mov    %ebx,%eax
add    %r14,%rax
mov    %r15d,%ecx
movb   $0x0,(%r14,%rcx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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