#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*/ invalid_space();
scalar_t__ isspace(char);
size_t leading_whitespace(char *s) {
  size_t result = 0;
  while (isspace(*s)) {
    if (*s++ == ' ')
      result += 1;
    else
      invalid_space();
  }
  return result;
}


x86 assembly (clang, -O0):
<leading_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1182 <leading_whitespace+0x62>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1176 <leading_whitespace+0x56>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    117d <leading_whitespace+0x5d>
mov    $0x0,%al
call   1030 <invalid_space@plt>
jmp    1134 <leading_whitespace+0x14>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leading_whitespace>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1164 <leading_whitespace+0x44>
add    $0x1,%rbx
xor    %r14d,%r14d
jmp    1158 <leading_whitespace+0x38>
nopl   (%rax)
xor    %eax,%eax
call   1030 <invalid_space@plt>
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1167 <leading_whitespace+0x47>
cmpb   $0x20,-0x1(%rbx)
jne    1140 <leading_whitespace+0x20>
add    $0x1,%r14
jmp    1147 <leading_whitespace+0x27>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @leading_whitespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
br label %4
4: ; preds = %20, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = call i64 @isspace(i8 signext %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 32
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i64, i64* %3
%17 = add i64 %16, 1
store i64 %17, i64* %3
br label %20
18: ; preds = %9
%19 = call i32 (...) @invalid_space()
br label %20
20: ; preds = %18, %15
br label %4
21: ; preds = %4
%22 = load i64, i64* %3
ret i64 %22
}

LLVM IR (-O2):
define i64 @leading_whitespace(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @isspace(i8 signext %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %1, %15
%6 = phi i64 [ %16, %15 ], [ 0, %1 ]
%7 = phi i8* [ %8, %15 ], [ %0, %1 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %7
%10 = icmp eq i8 %9, 32
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = add i64 %6, 1
br label %15
13: ; preds = %5
%14 = tail call i32 (...) @invalid_space()
br label %15
15: ; preds = %13, %11
%16 = phi i64 [ %12, %11 ], [ %6, %13 ]
%17 = load i8, i8* %8
%18 = tail call i64 @isspace(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %15, %1
%21 = phi i64 [ 0, %1 ], [ %16, %15 ]
ret i64 %21
}