#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 const);
scalar_t__ strlen(char const *);
int muggle_str_lstrip_idx(const char *str) {
  if (str == NULL) {
    return -1;
  }
  int str_len = (int)strlen(str);
  int idx = 0;
  while (isspace(str[idx])) {
    if (++idx >= str_len) {
      return -1;
    }
  }
  return idx;
}


x86 assembly (clang, -O0):
<muggle_str_lstrip_idx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <muggle_str_lstrip_idx+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <muggle_str_lstrip_idx+0x7a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1194 <muggle_str_lstrip_idx+0x74>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
jl     118f <muggle_str_lstrip_idx+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <muggle_str_lstrip_idx+0x7a>
jmp    1156 <muggle_str_lstrip_idx+0x36>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muggle_str_lstrip_idx>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     116d <muggle_str_lstrip_idx+0x4d>
mov    %rdi,%r15
call   1030 <strlen@plt>
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     116a <muggle_str_lstrip_idx+0x4a>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <muggle_str_lstrip_idx+0x30>
jmp    116d <muggle_str_lstrip_idx+0x4d>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @muggle_str_lstrip_idx(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = trunc i64 %4 to i32
%6 = call i32 @llvm.smax.i32(i32 %5, i32 1)
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %14, %3
%9 = phi i64 [ %15, %14 ], [ 0, %3 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%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 = %8
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %19, label %8
17: ; preds = %8
%18 = trunc i64 %9 to i32
br label %19
19: ; preds = %14, %17, %1
%20 = phi i32 [ -1, %1 ], [ %18, %17 ], [ -1, %14 ]
ret i32 %20
}