#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 */
size_t strlen(char const *);
size_t count_white_spaces(const char *buf) {
  size_t pos = 0;
  const size_t len = strlen(buf);
  while (((buf[pos] == ' ') || (buf[pos] == '\t')) && (pos < len)) {
    pos++;
  }
  return pos;
}


x86 assembly (clang, -O0):
<count_white_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1160 <count_white_spaces+0x50>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x9,%ecx
mov    %al,-0x19(%rbp)
jne    116e <count_white_spaces+0x5e>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117e <count_white_spaces+0x6e>
jmp    118f <count_white_spaces+0x7f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1131 <count_white_spaces+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_white_spaces>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
xchg   %ax,%ax
movzbl (%rbx,%rax,1),%edx
cmp    $0x20,%dl
je     112e <count_white_spaces+0x1e>
cmp    $0x9,%dl
jne    113c <count_white_spaces+0x2c>
cmp    %rax,%rcx
je     1139 <count_white_spaces+0x29>
add    $0x1,%rax
jmp    1120 <count_white_spaces+0x10>
mov    %rcx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i64 @count_white_spaces(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %3
3: ; preds = %9, %1
%4 = phi i64 [ 0, %1 ], [ %10, %9 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
switch i8 %6, label %11 [
i8 32, label %7
i8 9, label %7
]
7: ; preds = %3, %3
%8 = icmp eq i64 %4, %2
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = add i64 %4, 1
br label %3
11: ; preds = %3, %7
%12 = phi i64 [ %4, %3 ], [ %2, %7 ]
ret i64 %12
}