#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);
int count_argc(const char *str) {
  int count = 0;
  char was_space;
  for (was_space = 1; *str; str++) {
    if (isspace(*str)) {
      was_space = 1;
    } else if (was_space) {
      was_space = 0;
      count++;
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<count_argc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x1,-0xd(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1185 <count_argc+0x75>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1153 <count_argc+0x43>
movb   $0x1,-0xd(%rbp)
jmp    116f <count_argc+0x5f>
cmpb   $0x0,-0xd(%rbp)
je     116a <count_argc+0x5a>
movb   $0x0,-0xd(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <count_argc+0x5f>
jmp    1174 <count_argc+0x64>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <count_argc+0x17>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_argc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1156 <count_argc+0x46>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %r14d,%r14d
mov    $0x1,%ebp
xor    %r15d,%r15d
nop
movsbl %al,%edi
call   1030 <isspace@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
cmovne %r14d,%ebp
add    %ebp,%r15d
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %ecx,%ebp
test   %al,%al
jne    1130 <count_argc+0x20>
jmp    1159 <count_argc+0x49>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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