#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_arguments(const char *cmdline) {
  int i = 0;
  int arguments = 0;
  for (; i < strlen(cmdline); i++) {
    if (cmdline[i] == ' ') {
      arguments++;
      while (cmdline[i + 1] == ' ') {
        i++;
      }
    }
  }
  return arguments + 1;
}


x86 assembly (clang, -O0):
<count_arguments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%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
jge    11a4 <count_arguments+0x94>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1191 <count_arguments+0x81>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    118c <count_arguments+0x7c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1164 <count_arguments+0x54>
jmp    1191 <count_arguments+0x81>
jmp    1196 <count_arguments+0x86>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <count_arguments+0x1a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_arguments>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1162 <count_arguments+0x52>
lea    0x1(%rbx),%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    113f <count_arguments+0x2f>
xchg   %ax,%ax
add    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jge    1165 <count_arguments+0x55>
movslq %ebp,%rax
cmpb   $0x20,(%rbx,%rax,1)
jne    1130 <count_arguments+0x20>
lea    -0x1(%rax),%ebp
add    %r14,%rax
xchg   %ax,%ax
add    $0x1,%ebp
cmpb   $0x20,(%rax)
lea    0x1(%rax),%rax
je     1150 <count_arguments+0x40>
add    $0x1,%r15d
jmp    1130 <count_arguments+0x20>
xor    %r15d,%r15d
add    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_arguments(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %35, %1
%6 = load i32, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %38
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sext 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 %34
18: ; preds = %10
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %30, %18
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
%25 = sext 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, 32
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %21
33: ; preds = %21
br label %34
34: ; preds = %33, %10
br label %35
35: ; preds = %34
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %5
38: ; preds = %5
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
ret i32 %40
}

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