#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 /*<<< orphan*/ printf(char *);
int strlen(char const *);
int count_params(const char *cmdline) {
  int params_count = 0;
  int length = strlen(cmdline);
  int inword = 0;
  int i;
  for (i = 0; i < length - 1; i++) {
    switch (cmdline[i]) {
    case ' ':
    case '\0':
    case '\r':
    case '\t':
      if (inword) {
        params_count++;
        inword = 0;
      }
      break;
    case '\n':
      printf("read new line");
      break;
    default:
      inword = 1;
      break;
    }
  }
  params_count++;
  return params_count;
}


x86 assembly (clang, -O0):
<count_params>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1208 <count_params+0xe8>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11be <count_params+0x9e>
jmp    117a <count_params+0x5a>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     11be <count_params+0x9e>
jmp    118b <count_params+0x6b>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     11dd <count_params+0xbd>
jmp    119c <count_params+0x7c>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     11be <count_params+0x9e>
jmp    11ad <count_params+0x8d>
mov    -0x1c(%rbp),%eax
sub    $0x20,%eax
jne    11ee <count_params+0xce>
jmp    11be <count_params+0x9e>
cmpl   $0x0,-0x14(%rbp)
je     11d8 <count_params+0xb8>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    11f5 <count_params+0xd5>
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
jmp    11f5 <count_params+0xd5>
movl   $0x1,-0x14(%rbp)
jmp    11fa <count_params+0xda>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114d <count_params+0x2d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_params>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x2,%eax
jl     119f <count_params+0x7f>
mov    %eax,%r12d
add    $0xffffffff,%r12d
xor    %ebx,%ebx
movabs $0x100002201,%r13
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1173 <count_params+0x53>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%r15d
sbb    $0xffffffff,%ebp
xor    %r15d,%r15d
add    $0x1,%rbx
cmp    %rbx,%r12
je     119f <count_params+0x7f>
movsbl (%r14,%rbx,1),%eax
cmp    $0x20,%eax
ja     1197 <count_params+0x77>
bt     %rax,%r13
jb     1160 <count_params+0x40>
cmp    $0xa,%rax
jne    1197 <count_params+0x77>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
jmp    116a <count_params+0x4a>
mov    $0x1,%r15d
jmp    116a <count_params+0x4a>
add    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"read new line\00"
define i32 @count_params(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %32, %1
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %35
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %30 [
i32 32, label %21
i32 0, label %21
i32 13, label %21
i32 9, label %21
i32 10, label %28
]
21: ; preds = %14, %14, %14, %14
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
store i32 0, i32* %5
br label %27
27: ; preds = %24, %21
br label %31
28: ; preds = %14
%29 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %31
30: ; preds = %14
store i32 1, i32* %5
br label %31
31: ; preds = %30, %28, %27
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %9
35: ; preds = %9
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"read new line\00"
define i32 @count_params(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %25
4: ; preds = %1
%5 = add nsw i32 %2, -1
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %4, %20
%8 = phi i64 [ 0, %4 ], [ %23, %20 ]
%9 = phi i32 [ 0, %4 ], [ %22, %20 ]
%10 = phi i32 [ 0, %4 ], [ %21, %20 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %8
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %20 [
i32 32, label %14
i32 0, label %14
i32 13, label %14
i32 9, label %14
i32 10, label %18
]
14: ; preds = %7, %7, %7, %7
%15 = icmp ne i32 %9, 0
%16 = zext i1 %15 to i32
%17 = add nsw i32 %10, %16
br label %20
18: ; preds = %7
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %14, %7, %18
%21 = phi i32 [ %10, %18 ], [ %17, %14 ], [ %10, %7 ]
%22 = phi i32 [ %9, %18 ], [ 0, %14 ], [ 1, %7 ]
%23 = add nuw nsw i64 %8, 1
%24 = icmp eq i64 %23, %6
br i1 %24, label %25, label %7
25: ; preds = %20, %1
%26 = phi i32 [ 0, %1 ], [ %21, %20 ]
%27 = add nsw i32 %26, 1
ret i32 %27
}