#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 */
unsigned int strlen(char *);
int count_args(char *string) {
  unsigned int i;
  int argc = 0;
  for (i = 0; i < strlen(string); i++) {
    if (string[i] == ' ')
      argc++;
    if (string[i + 1] == ':' && string[i] == ' ')
      break;
  }
  return argc;
}


x86 assembly (clang, -O0):
<count_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jae    11a8 <count_args+0x98>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1163 <count_args+0x53>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1195 <count_args+0x85>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1195 <count_args+0x85>
jmp    11a8 <count_args+0x98>
jmp    119a <count_args+0x8a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <count_args+0x1a>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_args>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
nopl   (%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jae    1158 <count_args+0x48>
lea    0x1(%r15),%eax
movzbl (%r14,%rbx,1),%ecx
cmp    $0x20,%cl
cmove  %eax,%r15d
lea    0x1(%rbx),%rdx
cmpb   $0x3a,0x1(%r14,%rbx,1)
mov    %rdx,%rbx
jne    1120 <count_args+0x10>
mov    %rdx,%rbx
cmp    $0x20,%cl
jne    1120 <count_args+0x10>
jmp    115b <count_args+0x4b>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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