#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*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
int get_argc(char *command) {
  int argc = -1;
  char command_dup[1024];
  strncpy(command_dup, command, 1023);
  char *pch;
  pch = strtok(command_dup, " \n\t");
  while (pch != NULL) {
    pch = strtok(NULL, " \n\t");
    argc++;
  }
  return argc;
}


x86 assembly (clang, -O0):
<get_argc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
lea    -0x410(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     1198 <get_argc+0x78>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe82(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x418(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <get_argc+0x45>
mov    -0xc(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_argc>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     1172 <get_argc+0x52>
lea    0xea3(%rip),%r14
nopl   (%rax)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1160 <get_argc+0x40>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \0A\09\00"
define i32 @get_argc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
store i32 -1, i32* %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @strncpy(i8* %6, i8* %7, i32 1023)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %5
br label %11
11: ; preds = %14, %1
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %5
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %11
18: ; preds = %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [4 x i8] c" \0A\09\00"
define i32 @get_argc(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 1023)
%5 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %1, %7
%8 = phi i32 [ %10, %7 ], [ -1, %1 ]
%9 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = add nsw i32 %8, 1
%11 = icmp eq i8* %9, null
br i1 %11, label %12, label %7
12: ; preds = %7, %1
%13 = phi i32 [ -1, %1 ], [ %10, %7 ]
ret i32 %13
}