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

; 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"

@rules_count = external hidden global i64, align 8
@rules = external hidden global [100000 x ptr], align 16
@is_init = external hidden global i8, align 1
@.str.1 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1

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

declare void @mmt_sec_log(i32 noundef, ptr noundef, ...) #1

; 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
declare dso_local void @_filter_rules(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @mmt_sec_init(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %1
  %8 = load i8, ptr @is_init, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc i8 %8 to i1
  %10 = zext i1 %9 to i32
  %11 = icmp eq i32 %10, 0
  %12 = xor i1 %11, true
  %13 = xor i1 %12, true
  %14 = xor i1 %13, true
  %15 = zext i1 %14 to i32
  %16 = sext i32 %15 to i64
  %17 = call i64 @llvm.expect.i64(i64 %16, i64 0)
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %7
  call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 4, ptr noundef @.str.1)
  call void @exit(i32 noundef 0) #6
  unreachable

20:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %21 = call zeroext i1 (...) @mmt_sec_load_default_config()
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  store i8 1, ptr @is_init, align 1, !tbaa !9
  %22 = call i64 @load_mmt_sec_rules(ptr noundef %5)
  store i64 %22, ptr @rules_count, align 8, !tbaa !13
  store i64 0, ptr %4, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %34, %20
  %24 = load i64, ptr %4, align 8, !tbaa !13
  %25 = load i64, ptr @rules_count, align 8, !tbaa !13
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %27, label %37

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %4, align 8, !tbaa !13
  %30 = getelementptr inbounds ptr, ptr %28, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = load i64, ptr %4, align 8, !tbaa !13
  %33 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %32
  store ptr %31, ptr %33, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %27
  %35 = load i64, ptr %4, align 8, !tbaa !13
  %36 = add i64 %35, 1
  store i64 %36, ptr %4, align 8, !tbaa !13
  br label %23, !llvm.loop !15

37:                                               ; preds = %23
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_filter_rules(ptr noundef %38)
  %39 = load i64, ptr @rules_count, align 8, !tbaa !13
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 2, ptr noundef @.str.2)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %43

42:                                               ; preds = %37
  call void @_get_unique_proto_attts()
  call void @_update_rules_hash()
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %43

43:                                               ; preds = %42, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  %44 = load i32, ptr %2, align 4
  ret i32 %44
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

declare zeroext i1 @mmt_sec_load_default_config(...) #1

declare i64 @load_mmt_sec_rules(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @_get_unique_proto_attts() #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @_update_rules_hash() #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { noreturn nounwind "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 #5 = { 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 #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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
@is_init = external hidden local_unnamed_addr global i8, align 1
@.str.1 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1

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

declare void @mmt_sec_log(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; 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
declare dso_local void @_filter_rules(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @mmt_sec_init(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = load i8, ptr @is_init, align 1, !tbaa !5, !range !9, !noundef !10
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %5, label %4, !prof !11

4:                                                ; preds = %1
  tail call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 4, ptr noundef nonnull @.str.1) #5
  tail call void @exit(i32 noundef 0) #6
  unreachable

5:                                                ; preds = %1
  %6 = tail call zeroext i1 (...) @mmt_sec_load_default_config() #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store i8 1, ptr @is_init, align 1, !tbaa !5
  %7 = call i64 @load_mmt_sec_rules(ptr noundef nonnull %2) #5
  store i64 %7, ptr @rules_count, align 8, !tbaa !12
  %.not7 = icmp eq i64 %7, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %8 = load ptr, ptr %2, align 8, !tbaa !14
  %min.iters.check = icmp ult i64 %7, 6
  %9 = ptrtoint ptr %8 to i64
  %10 = sub i64 ptrtoint (ptr @rules to i64), %9
  %diff.check = icmp ult i64 %10, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %7, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %11 = getelementptr inbounds ptr, ptr %8, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <2 x ptr>, ptr %11, align 8, !tbaa !14
  %wide.load8 = load <2 x ptr>, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store <2 x ptr> %wide.load, ptr %13, align 16, !tbaa !14
  store <2 x ptr> %wide.load8, ptr %14, align 16, !tbaa !14
  %index.next = add nuw i64 %index, 4
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %7, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.06.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %7, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.06.prol = phi i64 [ %19, %scalar.ph.prol ], [ %.06.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %16 = getelementptr inbounds ptr, ptr %8, i64 %.06.prol
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %.06.prol
  store ptr %17, ptr %18, align 8, !tbaa !14
  %19 = add nuw i64 %.06.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !20

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.06.unr = phi i64 [ %.06.ph, %scalar.ph.preheader ], [ %19, %scalar.ph.prol ]
  %20 = sub i64 %.06.ph, %7
  %21 = icmp ugt i64 %20, -4
  br i1 %21, label %._crit_edge, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.06 = phi i64 [ %37, %scalar.ph ], [ %.06.unr, %scalar.ph.prol.loopexit ]
  %22 = getelementptr inbounds ptr, ptr %8, i64 %.06
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %.06
  store ptr %23, ptr %24, align 8, !tbaa !14
  %25 = add nuw i64 %.06, 1
  %26 = getelementptr inbounds ptr, ptr %8, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %25
  store ptr %27, ptr %28, align 8, !tbaa !14
  %29 = add nuw i64 %.06, 2
  %30 = getelementptr inbounds ptr, ptr %8, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %29
  store ptr %31, ptr %32, align 8, !tbaa !14
  %33 = add nuw i64 %.06, 3
  %34 = getelementptr inbounds ptr, ptr %8, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = getelementptr inbounds [100000 x ptr], ptr @rules, i64 0, i64 %33
  store ptr %35, ptr %36, align 8, !tbaa !14
  %37 = add nuw i64 %.06, 4
  %exitcond.not.3 = icmp eq i64 %37, %7
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %5
  call void @_filter_rules(ptr noundef %0)
  %38 = load i64, ptr @rules_count, align 8, !tbaa !12
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %._crit_edge
  call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 2, ptr noundef nonnull @.str.2) #5
  br label %42

41:                                               ; preds = %._crit_edge
  call void @_get_unique_proto_attts()
  call void @_update_rules_hash()
  br label %42

42:                                               ; preds = %41, %40
  %.05 = phi i32 [ 1, %40 ], [ 0, %41 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret i32 %.05
}

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

declare zeroext i1 @mmt_sec_load_default_config(...) local_unnamed_addr #1

declare i64 @load_mmt_sec_rules(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @_get_unique_proto_attts() local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @_update_rules_hash() local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { noreturn nounwind "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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !17, !18}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass