#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ isspace(char);
int /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
char *str_lstrip(char *str) {
  assert(str != NULL);
  char *ptr = str;
  char *end = str + strlen(str);
  for (; ptr != end && isspace(*ptr); ptr++)
    ;
  memmove(str, ptr, strlen(ptr) + 1);
  return str;
}


x86 assembly (clang, -O0):
<str_lstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     11b0 <str_lstrip+0x70>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11c0 <str_lstrip+0x80>
jmp    11d6 <str_lstrip+0x96>
jmp    11c5 <str_lstrip+0x85>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1187 <str_lstrip+0x47>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <memmove@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_lstrip>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r14,%r12
test   %eax,%eax
je     119c <str_lstrip+0x5c>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%r15
mov    %r14,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r12),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     119c <str_lstrip+0x5c>
add    $0x1,%r12
add    $0xffffffffffffffff,%rbx
jne    1180 <str_lstrip+0x40>
mov    %r15,%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <memmove@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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