#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 strlen(char const *);
int count_indents(const char *str) {
  int i = 0;
  int len = strlen(str);
  int indents = 0;
  while (i < len) {
    if (str[i] == 0x09) {
      indents += 4;
    } else if (str[i] == 0x20) {
      indents++;
    } else {
      return indents;
    }
    i++;
  }
  return indents;
}


x86 assembly (clang, -O0):
<count_indents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a6 <count_indents+0x96>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
jne    1165 <count_indents+0x55>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    1198 <count_indents+0x88>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1188 <count_indents+0x78>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <count_indents+0x83>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <count_indents+0x9c>
jmp    1198 <count_indents+0x88>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <count_indents+0x26>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_indents>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1156 <count_indents+0x46>
mov    %eax,%ecx
xor    %edx,%edx
xor    %eax,%eax
jmp    113b <count_indents+0x2b>
nopl   0x0(%rax,%rax,1)
add    %esi,%eax
add    $0x1,%rdx
cmp    %rdx,%rcx
je     1158 <count_indents+0x48>
movzbl (%r14,%rdx,1),%ebx
mov    $0x4,%esi
cmp    $0x9,%bl
je     1130 <count_indents+0x20>
cmp    $0x20,%bl
jne    1158 <count_indents+0x48>
mov    $0x1,%esi
jmp    1130 <count_indents+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @count_indents(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %38, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %41
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, 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 %24
21: ; preds = %13
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 4
store i32 %23, i32* %6
br label %38
24: ; preds = %13
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 32
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %37
35: ; preds = %24
%36 = load i32, i32* %6
store i32 %36, i32* %2
br label %43
37: ; preds = %32
br label %38
38: ; preds = %37, %21
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %9
41: ; preds = %9
%42 = load i32, i32* %6
store i32 %42, i32* %2
br label %43
43: ; preds = %41, %35
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
define i32 @count_indents(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %12
%7 = phi i64 [ 0, %4 ], [ %15, %12 ]
%8 = phi i32 [ 0, %4 ], [ %14, %12 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
switch i8 %10, label %17 [
i8 9, label %12
i8 32, label %11
]
11: ; preds = %6
br label %12
12: ; preds = %6, %11
%13 = phi i32 [ 1, %11 ], [ 4, %6 ]
%14 = add nuw nsw i32 %8, %13
%15 = add nuw nsw i64 %7, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %17, label %6
17: ; preds = %6, %12, %1
%18 = phi i32 [ 0, %1 ], [ %14, %12 ], [ %8, %6 ]
ret i32 %18
}