#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*/ *strchr(char const *, char);
scalar_t__ strlen(char const *);
int cnt_cmd_args(const char **argv) {
  int i;
  for (i = 0; *argv; argv++) {
    i += strlen(*argv) + 1;
    if (strchr(*argv, ' ') != NULL)
      i += 2;
  }
  return i;
}


x86 assembly (clang, -O0):
<cnt_cmd_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1198 <cnt_cmd_args+0x78>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1182 <cnt_cmd_args+0x62>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <cnt_cmd_args+0x67>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    1133 <cnt_cmd_args+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cnt_cmd_args>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rbx
test   %rbx,%rbx
je     1176 <cnt_cmd_args+0x56>
mov    %rdi,%r14
add    $0x8,%r14
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
add    %r15d,%ebp
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    0x1(%rbp,%rcx,2),%r15d
mov    (%r14),%rbx
add    $0x8,%r14
test   %rbx,%rbx
jne    1140 <cnt_cmd_args+0x20>
jmp    1179 <cnt_cmd_args+0x59>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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