#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*/ free(char *);
int read_separator(char **);
char *read_word(char **);
int get_argc(char *message) {
  int result = 0;
  char *word = NULL;
  int null_arg = 0;
  if (read_separator(&message) == 0) {
    if (message[0] == '\0') {
      null_arg = 1;
    }
    word = read_word(&message);
    if (word != NULL) {
      free(word);
      result = 1;
      while (read_separator(&message) == 1) {
        word = read_word(&message);
        if (word != NULL) {
          free(word);
          result++;
        }
      }
    }
  }
  if (result == 1 && null_arg) {
    result = 0;
  }
  return result;
}


x86 assembly (clang, -O0):
<get_argc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <read_separator@plt>
cmp    $0x0,%eax
jne    11ee <get_argc+0xbe>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117b <get_argc+0x4b>
movl   $0x1,-0x1c(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <read_word@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e9 <get_argc+0xb9>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <read_separator@plt>
cmp    $0x1,%eax
jne    11e4 <get_argc+0xb4>
lea    -0x8(%rbp),%rdi
call   1050 <read_word@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11df <get_argc+0xaf>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a3 <get_argc+0x73>
jmp    11e9 <get_argc+0xb9>
jmp    11ee <get_argc+0xbe>
cmpl   $0x1,-0xc(%rbp)
jne    1209 <get_argc+0xd9>
cmpl   $0x0,-0x1c(%rbp)
je     1209 <get_argc+0xd9>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_argc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,(%rsp)
mov    %rsp,%rdi
call   1040 <read_separator@plt>
xor    %r15d,%r15d
mov    $0x0,%ebp
mov    $0x0,%r14d
test   %eax,%eax
je     1171 <get_argc+0x41>
test   %r14b,%r14b
cmove  %ebp,%r15d
cmp    $0x1,%ebp
cmovne %ebp,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
sete   %r14b
mov    %rsp,%rdi
call   1050 <read_word@plt>
test   %rax,%rax
je     11d7 <get_argc+0xa7>
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rsp,%rdi
call   1040 <read_separator@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
jne    1155 <get_argc+0x25>
mov    $0x1,%ebp
mov    %rsp,%rbx
jmp    11bd <get_argc+0x8d>
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <read_separator@plt>
cmp    $0x1,%eax
jne    1155 <get_argc+0x25>
mov    %rbx,%rdi
call   1050 <read_word@plt>
test   %rax,%rax
je     11b0 <get_argc+0x80>
mov    %rax,%rdi
call   1030 <free@plt>
add    $0x1,%ebp
jmp    11b0 <get_argc+0x80>
xor    %ebp,%ebp
jmp    1155 <get_argc+0x25>

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

LLVM IR (-O2):
define i32 @get_argc(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 @read_separator(i8** %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %26
5: ; preds = %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = call i8* @read_word(i8** %2)
%10 = icmp eq i8* %9, null
br i1 %10, label %26, label %11
11: ; preds = %5
%12 = call i32 @free(i8* %9)
%13 = call i32 @read_separator(i8** %2)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %26
15: ; preds = %11, %22
%16 = phi i32 [ %23, %22 ], [ 1, %11 ]
%17 = call i8* @read_word(i8** %2)
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = call i32 @free(i8* %17)
%21 = add nsw i32 %16, 1
br label %22
22: ; preds = %19, %15
%23 = phi i32 [ %21, %19 ], [ %16, %15 ]
%24 = call i32 @read_separator(i8** %2)
%25 = icmp eq i32 %24, 1
br i1 %25, label %15, label %26
26: ; preds = %22, %11, %5, %1
%27 = phi i32 [ 0, %5 ], [ 0, %1 ], [ 1, %11 ], [ %23, %22 ]
%28 = phi i1 [ %8, %5 ], [ false, %1 ], [ %8, %11 ], [ %8, %22 ]
%29 = icmp eq i32 %27, 1
%30 = and i1 %29, %28
%31 = select i1 %30, i32 0, i32 %27
ret i32 %31
}