#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*/ assert(int);
char *nvram_get(char const *);
int strlen(char *);
int ezplib_get_rule_num(const char *rule_set) {
  char *sep = "|";
  char *result = NULL;
  int i;
  int count;
  assert(strlen("|") == 1);
  result = nvram_get(rule_set);
  if (!result) {
    return -3;
  }
  if (!*result) {
    return 0;
  }
  for (i = 0, count = 0; result[i] != '\0'; i++) {
    if (result[i] == sep[0]) {
      count++;
    }
  }
  return count + 1;
}


x86 assembly (clang, -O0):
<ezplib_get_rule_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1050 <nvram_get@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <ezplib_get_rule_num+0x5f>
movl   $0xfffffffd,-0x4(%rbp)
jmp    120b <ezplib_get_rule_num+0xdb>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11a8 <ezplib_get_rule_num+0x78>
movl   $0x0,-0x4(%rbp)
jmp    120b <ezplib_get_rule_num+0xdb>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1202 <ezplib_get_rule_num+0xd2>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11ef <ezplib_get_rule_num+0xbf>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11f4 <ezplib_get_rule_num+0xc4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b6 <ezplib_get_rule_num+0x86>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ezplib_get_rule_num>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1050 <nvram_get@plt>
test   %rax,%rax
je     1188 <ezplib_get_rule_num+0x58>
mov    %rax,%rcx
mov    (%rax),%dl
test   %dl,%dl
je     118f <ezplib_get_rule_num+0x5f>
add    $0x1,%rcx
xor    %eax,%eax
jmp    117a <ezplib_get_rule_num+0x4a>
nopl   0x0(%rax)
add    $0x1,%eax
movzbl (%rcx),%edx
add    $0x1,%rcx
cmp    $0x7c,%dl
je     1170 <ezplib_get_rule_num+0x40>
test   %dl,%dl
jne    1173 <ezplib_get_rule_num+0x43>
add    $0x1,%eax
pop    %rbx
ret
mov    $0xfffffffd,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
define i32 @ezplib_get_rule_num(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 1
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i8* @nvram_get(i8* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %24, label %8
8: ; preds = %1
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %8, %17
%12 = phi i8 [ %21, %17 ], [ %9, %8 ]
%13 = phi i64 [ %19, %17 ], [ 0, %8 ]
%14 = phi i32 [ %18, %17 ], [ 0, %8 ]
switch i8 %12, label %17 [
i8 0, label %22
i8 124, label %15
]
15: ; preds = %11
%16 = add nsw i32 %14, 1
br label %17
17: ; preds = %11, %15
%18 = phi i32 [ %16, %15 ], [ %14, %11 ]
%19 = add nuw i64 %13, 1
%20 = getelementptr inbounds i8, i8* %6, i64 %19
%21 = load i8, i8* %20
br label %11
22: ; preds = %11
%23 = add nsw i32 %14, 1
br label %24
24: ; preds = %8, %1, %22
%25 = phi i32 [ %23, %22 ], [ -3, %1 ], [ 0, %8 ]
ret i32 %25
}