#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 */
char *extract_substring_after_str(char *, char *);
int /*<<< orphan*/ free(char *);
char *strtok(char *, char *);
int count_dependencies(char *line) {
  char *dependencies = extract_substring_after_str(line, ":");
  int num_dependencies = 0;
  char *pch = strtok(dependencies, " ");
  while (pch != NULL) {
    num_dependencies++;
    pch = strtok(NULL, " ");
  }
  free(dependencies);
  return num_dependencies;
}


x86 assembly (clang, -O0):
<count_dependencies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <extract_substring_after_str@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1198 <count_dependencies+0x68>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe78(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    116b <count_dependencies+0x3b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_dependencies>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rsi
call   1050 <extract_substring_after_str@plt>
mov    %rax,%r14
lea    0xeb7(%rip),%rsi
mov    %rax,%rdi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1182 <count_dependencies+0x52>
lea    0xea1(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1170 <count_dependencies+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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