int count_spaces(current, buffer)
int current;
char *buffer;
{
  register char *buf;
  register int cur;
  cur = current;
  for (buf = buffer; *buf != '\0'; ++buf) {
    switch (*buf) {
    case '\n':
    case 014:
      cur = 1;
      break;
    case '\t':
      cur = ((cur - 1) & 0177770) + 8 + 1;
      break;
    case '':
      --cur;
      break;
    default:
      ++cur;
      break;
    }
  }
  return (cur);
}


x86 assembly (clang, -O0):
<count_spaces>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a8 <count_spaces+0xa8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffff8,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     1189 <count_spaces+0x89>
mov    -0x28(%rbp),%rax
lea    0xeb3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x1c(%rbp)
jmp    1192 <count_spaces+0x92>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
and    $0xfff8,%eax
add    $0x8,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <count_spaces+0x92>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <count_spaces+0x92>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1197 <count_spaces+0x97>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1119 <count_spaces+0x19>
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_spaces>:
mov    (%rsi),%dl
test   %dl,%dl
je     115f <count_spaces+0x5f>
add    $0x1,%rsi
lea    0xeef(%rip),%rcx
jmp    1132 <count_spaces+0x32>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%edi
mov    %edi,%eax
movzbl (%rsi),%edx
add    $0x1,%rsi
mov    %eax,%edi
test   %dl,%dl
je     115e <count_spaces+0x5e>
movsbl %dl,%edx
add    $0xfffffff8,%edx
cmp    $0x4,%edx
ja     1120 <count_spaces+0x20>
mov    $0x1,%eax
movslq (%rcx,%rdx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
add    $0xffffffff,%edi
jmp    1123 <count_spaces+0x23>
add    $0xffffffff,%edi
and    $0xfff8,%edi
add    $0x9,%edi
jmp    1123 <count_spaces+0x23>
ret
mov    %edi,%eax
ret

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

LLVM IR (-O2):
define i32 @count_spaces(i32 %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %18
%6 = phi i8 [ %21, %18 ], [ %3, %2 ]
%7 = phi i32 [ %19, %18 ], [ %0, %2 ]
%8 = phi i8* [ %20, %18 ], [ %1, %2 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %16 [
i32 10, label %18
i32 12, label %18
i32 9, label %10
i32 8, label %14
]
10: ; preds = %5
%11 = add i32 %7, 65535
%12 = and i32 %11, 65528
%13 = add nuw nsw i32 %12, 9
br label %18
14: ; preds = %5
%15 = add nsw i32 %7, -1
br label %18
16: ; preds = %5
%17 = add nsw i32 %7, 1
br label %18
18: ; preds = %5, %5, %10, %14, %16
%19 = phi i32 [ %17, %16 ], [ %15, %14 ], [ %13, %10 ], [ 1, %5 ], [ 1, %5 ]
%20 = getelementptr inbounds i8, i8* %8, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %18, %2
%24 = phi i32 [ %0, %2 ], [ %19, %18 ]
ret i32 %24
}