#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 */
scalar_t__ strcmp(char *, char *);
int wordCounter(char **args, int spaces, int indexCommand) {
  int i = 0, counter = 0, wordCounter = 0, exit = 1;
  while (counter < indexCommand) {
    if (!strcmp(args[i], "|"))
      counter++;
    i++;
  }
  while (exit && i <= spaces) {
    if (strcmp(args[i], "|"))
      wordCounter++;
    else
      exit = 0;
    i++;
  }
  return wordCounter;
}


x86 assembly (clang, -O0):
<wordCounter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1183 <wordCounter+0x73>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1175 <wordCounter+0x65>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <wordCounter+0x2e>
jmp    1188 <wordCounter+0x78>
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     11a3 <wordCounter+0x93>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
setle  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b3 <wordCounter+0xa3>
jmp    11f8 <wordCounter+0xe8>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe3a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11e3 <wordCounter+0xd3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ea <wordCounter+0xda>
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <wordCounter+0x78>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wordCounter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
mov    %rdi,%r15
xor    %ebp,%ebp
mov    $0x0,%ebx
test   %edx,%edx
jle    115d <wordCounter+0x4d>
mov    %edx,%r13d
xor    %ebx,%ebx
lea    0xec7(%rip),%r12
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
cmp    $0x1,%rax
adc    $0x0,%r14d
add    $0x1,%rbx
cmp    %r13d,%r14d
jl     1140 <wordCounter+0x30>
mov    0x4(%rsp),%r13d
cmp    %r13d,%ebx
jg     11ae <wordCounter+0x9e>
mov    %ebx,%eax
lea    (%r15,%rax,8),%r12
xor    %ebp,%ebp
lea    0xe8a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%r14d
mov    (%r12),%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
add    %r14d,%ebp
test   %rax,%rax
je     11ae <wordCounter+0x9e>
lea    0x1(%rbx),%eax
add    $0x8,%r12
cmp    %r13d,%ebx
mov    %eax,%ebx
jl     1180 <wordCounter+0x70>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
define i32 @wordCounter(i8** %0, i32 %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 1, i32* %10
br label %11
11: ; preds = %26, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i8**, i8*** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %15
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %26
26: ; preds = %23, %15
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %11
29: ; preds = %11
br label %30
30: ; preds = %51, %29
%31 = load i32, i32* %10
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* %7
%35 = load i32, i32* %5
%36 = icmp sle i32 %34, %35
br label %37
37: ; preds = %33, %30
%38 = phi i1 [ false, %30 ], [ %36, %33 ]
br i1 %38, label %39, label %54
39: ; preds = %37
%40 = load i8**, i8*** %4
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %39
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %51
50: ; preds = %39
store i32 0, i32* %10
br label %51
51: ; preds = %50, %47
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %30
54: ; preds = %37
%55 = load i32, i32* %9
ret i32 %55
}

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
define i32 @wordCounter(i8** nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %12, label %7
5: ; preds = %12
%6 = trunc i64 %21 to i32
br label %7
7: ; preds = %5, %3
%8 = phi i32 [ 0, %3 ], [ %6, %5 ]
%9 = icmp sgt i32 %8, %1
br i1 %9, label %36, label %10
10: ; preds = %7
%11 = zext i32 %8 to i64
br label %23
12: ; preds = %3, %12
%13 = phi i64 [ %21, %12 ], [ 0, %3 ]
%14 = phi i32 [ %20, %12 ], [ 0, %3 ]
%15 = getelementptr inbounds i8*, i8** %0, i64 %13
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %14, %19
%21 = add nuw i64 %13, 1
%22 = icmp slt i32 %20, %2
br i1 %22, label %12, label %5
23: ; preds = %10, %23
%24 = phi i64 [ %11, %10 ], [ %32, %23 ]
%25 = phi i32 [ 0, %10 ], [ %31, %23 ]
%26 = getelementptr inbounds i8*, i8** %0, i64 %24
%27 = load i8*, i8** %26
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i32
%31 = add nuw nsw i32 %25, %30
%32 = add nuw nsw i64 %24, 1
%33 = trunc i64 %24 to i32
%34 = icmp slt i32 %33, %1
%35 = select i1 %29, i1 %34, i1 false
br i1 %35, label %23, label %36
36: ; preds = %23, %7
%37 = phi i32 [ 0, %7 ], [ %31, %23 ]
ret i32 %37
}