#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 */
char *astrcpy(char *);
char *astrmid(char const *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ isspace(char const);
size_t strlen(char const *);
char *astrltrim(const char *s) {
  char *result = NULL;
  size_t ii;
  for (ii = 0; ii < strlen(s); ++ii) {
    if (!isspace(s[ii])) {
      result = astrmid(s, ii, 0);
      break;
    }
  }
  if (result == NULL)
    result = astrcpy("");
  return result;
}


x86 assembly (clang, -O0):
<astrltrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    11c5 <astrltrim+0x85>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11af <astrltrim+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1060 <astrmid@plt>
mov    %rax,-0x10(%rbp)
jmp    11c5 <astrltrim+0x85>
jmp    11b4 <astrltrim+0x74>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <astrltrim+0x1c>
cmpq   $0x0,-0x10(%rbp)
jne    11e0 <astrltrim+0xa0>
lea    0xe29(%rip),%rdi
call   1050 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrltrim>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     11a1 <astrltrim+0x61>
mov    %rdi,%r14
movsbl %al,%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     1185 <astrltrim+0x45>
mov    $0x1,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbx
jae    11a1 <astrltrim+0x61>
movsbl (%r14,%rbx,1),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    1160 <astrltrim+0x20>
add    $0xffffffffffffffff,%rbx
jmp    1187 <astrltrim+0x47>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <astrmid@plt>
test   %rax,%rax
je     11a1 <astrltrim+0x61>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe58(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <astrcpy@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @astrltrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
store i64 0, i64* %4
br label %5
5: ; preds = %22, %1
%6 = load i64, i64* %4
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = icmp ult i64 %6, %8
br i1 %9, label %10, label %25
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i64, i64* %4
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = load i8, i8* %13
%15 = call i32 @isspace(i8 signext %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = load i64, i64* %4
%20 = call i8* @astrmid(i8* %18, i64 %19, i32 0)
store i8* %20, i8** %3
br label %25
21: ; preds = %10
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = add i64 %23, 1
store i64 %24, i64* %4
br label %5
25: ; preds = %17, %5
%26 = load i8*, i8** %3
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i8* @astrcpy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %29, i8** %3
br label %30
30: ; preds = %28, %25
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @astrltrim(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = tail call i32 @isspace(i8 signext %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4, %12
%8 = phi i64 [ %9, %12 ], [ 0, %4 ]
%9 = add nuw i64 %8, 1
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 %9
%14 = load i8, i8* %13
%15 = tail call i32 @isspace(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %12, %4
%18 = phi i64 [ 0, %4 ], [ %9, %12 ]
%19 = tail call i8* @astrmid(i8* %0, i64 %18, i32 0)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %7, %1, %17
%22 = tail call i8* @astrcpy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = phi i8* [ %22, %21 ], [ %19, %17 ]
ret i8* %24
}