#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 *get_token_from_string(char *, char const *, char *);
scalar_t__ strlen(char *);
int count_tokens_in_string(char *line, const char *delim) {
  int count = 0;
  char token[2048], *next;
  next = get_token_from_string(line, delim, token);
  while (strlen(token)) {
    count++;
    next = get_token_from_string(next, delim, token);
  }
  return (count);
}


x86 assembly (clang, -O0):
<count_tokens_in_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x820(%rbp),%rdx
call   1040 <get_token_from_string@plt>
mov    %rax,-0x828(%rbp)
lea    -0x820(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1197 <count_tokens_in_string+0x77>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x828(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x820(%rbp),%rdx
call   1040 <get_token_from_string@plt>
mov    %rax,-0x828(%rbp)
jmp    1155 <count_tokens_in_string+0x35>
mov    -0x14(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_tokens_in_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%rbx
mov    %rsp,%rdx
call   1030 <get_token_from_string@plt>
cmpb   $0x0,(%rsp)
je     1159 <count_tokens_in_string+0x49>
xor    %ebp,%ebp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <get_token_from_string@plt>
cmpb   $0x0,(%rsp)
jne    1140 <count_tokens_in_string+0x30>
jmp    115b <count_tokens_in_string+0x4b>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_tokens_in_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [2048 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%11 = call i8* @get_token_from_string(i8* %8, i8* %9, i8* %10)
store i8* %11, i8** %7
br label %12
12: ; preds = %16, %2
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%14 = call i64 @strlen(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
%19 = load i8*, i8** %7
%20 = load i8*, i8** %4
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%22 = call i8* @get_token_from_string(i8* %19, i8* %20, i8* %21)
store i8* %22, i8** %7
br label %12
23: ; preds = %12
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
define i32 @count_tokens_in_string(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i8* @get_token_from_string(i8* %0, i8* %1, i8* %4)
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %2, %8
%9 = phi i8* [ %12, %8 ], [ %5, %2 ]
%10 = phi i32 [ %11, %8 ], [ 0, %2 ]
%11 = add nuw nsw i32 %10, 1
%12 = call i8* @get_token_from_string(i8* %9, i8* %1, i8* %4)
%13 = load i8, i8* %4
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8, %2
%16 = phi i32 [ 0, %2 ], [ %11, %8 ]
ret i32 %16
}