#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 /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
char *ltrim(char *str) {
  int i = 0;
  int len = strlen(str);
  while (isspace(str[i]))
    i++;
  memmove(str, &str[i], len - i);
  str[len - i] = 0;
  return str;
}


x86 assembly (clang, -O0):
<ltrim>:
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
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1178 <ltrim+0x48>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <ltrim+0x1f>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%edx
sub    -0xc(%rbp),%edx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltrim>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
movsbl 0x1(%rbx,%rbp,1),%edi
call   1040 <isspace@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1150 <ltrim+0x20>
mov    %ebp,%esi
add    %rbx,%rsi
mov    %r14d,%r14d
sub    %rbp,%r14
mov    %rbx,%rdi
mov    %r14d,%edx
call   1050 <memmove@plt>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ltrim(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 = %15, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = call i64 @isspace(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
%19 = load i8*, i8** %2
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = sub nsw i32 %24, %25
%27 = call i32 @memmove(i8* %19, i8* %23, i32 %26)
%28 = load i8*, i8** %2
%29 = load i32, i32* %4
%30 = load i32, i32* %3
%31 = sub nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
define i8* @ltrim(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ %9, %3 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = tail call i64 @isspace(i8 signext %6)
%8 = icmp eq i64 %7, 0
%9 = add nuw i64 %4, 1
br i1 %8, label %10, label %3
10: ; preds = %3
%11 = trunc i64 %4 to i32
%12 = and i64 %4, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = sub nsw i32 %2, %11
%15 = tail call i32 @memmove(i8* %0, i8* %13, i32 %14)
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
ret i8* %0
}