#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*/ exit(int);
char *strtok(char *, char *);
int /*<<< orphan*/ usage(char *);
int countHosts(char *buf) {
  char *p;
  char *u;
  int n = 0;
  if (buf == NULL) {
    usage("brun");
    exit(-1);
  }
  p = buf;
  u = strtok(p, " \n\t");
  ++n;
  while ((u = strtok(NULL, " \n\t")))
    ++n;
  return (n);
}


x86 assembly (clang, -O0):
<countHosts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1164 <countHosts+0x34>
lea    0xeab(%rip),%rdi
call   1030 <usage@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe71(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b5 <countHosts+0x85>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <countHosts+0x59>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countHosts>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116c <countHosts+0x3c>
lea    0xec5(%rip),%r14
mov    %r14,%rsi
call   1040 <strtok@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1150 <countHosts+0x20>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe8d(%rip),%rdi
call   1030 <usage@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

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

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