#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*/ strcpy(char *, char *);
char *strtok(char *, char *);
int num_of_exprs_in_str(char *clone_str) {
  int num = 0;
  char *tl;
  char str[2048] = "\0";
  strcpy(str, clone_str);
  for (tl = strtok(str, ",$"); tl != NULL; tl = strtok(NULL, ",$"))
    num++;
  return num;
}


x86 assembly (clang, -O0):
<num_of_exprs_in_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x820(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ad <num_of_exprs_in_str+0x7d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe61(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1180 <num_of_exprs_in_str+0x50>
mov    -0xc(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_of_exprs_in_str>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%r14
mov    %rsp,%r15
xor    %ebx,%ebx
mov    $0x800,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe9b(%rip),%rsi
mov    %r15,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     1192 <num_of_exprs_in_str+0x62>
xor    %ebx,%ebx
lea    0xe85(%rip),%r14
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <num_of_exprs_in_str+0x50>
mov    %ebx,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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