; LLVM IR from Montimage/mmt-security :: src/lib/mmt_security.ll (filter_rules)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.rule_info_struct = type { i32, i32, ptr, ptr, ptr, ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr }

@rules_count = external hidden global i64, align 8
@rules = external hidden global [100000 x ptr], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @_filter_rules(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %16, label %12

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #5
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %12, %1
  store i32 1, ptr %9, align 4
  br label %75

17:                                               ; preds = %12
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call i64 @expand_number_range(ptr noundef %18, ptr noundef %3)
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %72

23:                                               ; preds = %17
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sub nsw i32 %24, 1
  store i32 %25, ptr %6, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %68, %23
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %71

29:                                               ; preds = %26
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  store i32 %34, ptr %4, align 4, !tbaa !9
  %35 = load i64, ptr @rules_count, align 8, !tbaa !11
  %36 = icmp eq i64 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %29
  store i32 1, ptr %9, align 4
  br label %75

38:                                               ; preds = %29
  %39 = load i64, ptr @rules_count, align 8, !tbaa !11
  %40 = sub i64 %39, 1
  %41 = trunc i64 %40 to i32
  store i32 %41, ptr %7, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %64, %38
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp sge i32 %43, 0
  br i1 %44, label %45, label %67

45:                                               ; preds = %42
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rule_info_struct, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !13
  %53 = icmp eq i32 %46, %52
  br i1 %53, label %54, label %63

54:                                               ; preds = %45
  %55 = load i64, ptr @rules_count, align 8, !tbaa !11
  %56 = add i64 %55, -1
  store i64 %56, ptr @rules_count, align 8, !tbaa !11
  %57 = load i64, ptr @rules_count, align 8, !tbaa !11
  %58 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %61
  store ptr %59, ptr %62, align 8, !tbaa !5
  br label %67

63:                                               ; preds = %45
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr %7, align 4, !tbaa !9
  br label %42, !llvm.loop !15

67:                                               ; preds = %54, %42
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %6, align 4, !tbaa !9
  br label %26, !llvm.loop !17

71:                                               ; preds = %26
  br label %72

72:                                               ; preds = %71, %17
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = call i64 @mmt_mem_free(ptr noundef %73)
  store i32 0, ptr %9, align 4
  br label %75

75:                                               ; preds = %72, %37, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %76 = load i32, ptr %9, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  ret void

78:                                               ; preds = %75
  unreachable
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @expand_number_range(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mmt_mem_free(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind willreturn memory(read) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"rule_info_struct", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !7, i64 41, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@rules_count = external hidden local_unnamed_addr global i64, align 8
@rules = external hidden local_unnamed_addr global [100000 x ptr], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @_filter_rules(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.loopexit17, label %4

4:                                                ; preds = %1
  %char0 = load i8, ptr %0, align 1
  %5 = icmp eq i8 %char0, 0
  br i1 %5, label %.loopexit17, label %6

6:                                                ; preds = %4
  %7 = call i64 @expand_number_range(ptr noundef nonnull %0, ptr noundef nonnull %2)
  %8 = trunc i64 %7 to i32
  %9 = icmp sgt i32 %8, 0
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br i1 %9, label %.preheader, label %.loopexit16

.preheader:                                       ; preds = %6
  %rules_count.promoted = load i64, ptr @rules_count, align 8, !tbaa !9
  %10 = and i64 %7, 2147483647
  br label %11

11:                                               ; preds = %.preheader, %.loopexit
  %indvars.iv22 = phi i64 [ %10, %.preheader ], [ %indvars.iv.next23, %.loopexit ]
  %12 = phi i64 [ %rules_count.promoted, %.preheader ], [ %32, %.loopexit ]
  %indvars.iv.next23 = add nsw i64 %indvars.iv22, -1
  %13 = getelementptr inbounds i32, ptr %.pre, i64 %indvars.iv.next23
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp eq i64 %12, 0
  br i1 %15, label %.loopexit17, label %16

16:                                               ; preds = %11
  %17 = and i64 %12, 4294967295
  br label %18

18:                                               ; preds = %21, %16
  %indvars.iv = phi i64 [ %indvars.iv.next, %21 ], [ %17, %16 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %19 = and i64 %indvars.iv.next, 2147483648
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %.loopexit

21:                                               ; preds = %18
  %22 = and i64 %indvars.iv.next, 2147483647
  %23 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp eq i32 %14, %25
  br i1 %26, label %27, label %18, !llvm.loop !15

27:                                               ; preds = %21
  %28 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %22
  %29 = add i64 %12, -1
  store i64 %29, ptr @rules_count, align 8, !tbaa !9
  %30 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %28, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %18, %27
  %32 = phi i64 [ %29, %27 ], [ %12, %18 ]
  %33 = icmp sgt i64 %indvars.iv22, 1
  br i1 %33, label %11, label %.loopexit16, !llvm.loop !17

.loopexit16:                                      ; preds = %.loopexit, %6
  %34 = call i64 @mmt_mem_free(ptr noundef %.pre)
  br label %.loopexit17

.loopexit17:                                      ; preds = %11, %1, %4, %.loopexit16
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @expand_number_range(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mmt_mem_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"rule_info_struct", !12, i64 0, !12, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !7, i64 41, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass