#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 *, scalar_t__);
scalar_t__ strlen(char *);
char *ltrim(char *s) {
  if (s == NULL)
    return NULL;
  char *ptr = s;
  while (isspace(*ptr))
    ptr++;
  if (s != ptr)
    memmove(s, ptr, strlen(ptr) + 1);
  return s;
}


x86 assembly (clang, -O0):
<ltrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <ltrim+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <ltrim+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1183 <ltrim+0x53>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <ltrim+0x2c>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11be <ltrim+0x8e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltrim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rdi,%rdi
je     1178 <ltrim+0x48>
xor    %ebx,%ebx
nop
movsbl (%r15,%rbx,1),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <ltrim+0x10>
cmp    $0x1,%rbx
je     1178 <ltrim+0x48>
lea    (%r15,%rbx,1),%r14
add    $0xffffffffffffffff,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <memmove@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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