; LLVM IR from Montimage/mmt-security :: src/lib (mmt_single_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"

%struct.mmt_single_sec_handler_struct = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, %struct.mmt_bit_t, i64, i8, ptr, i32 }
%struct.mmt_bit_t = type { [32 x i8] }
%struct.rule_info_struct = type { i32, i32, ptr, ptr, ptr, ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [35 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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mmt_set_ex_free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @mmt_single_sec_unregister(ptr noundef %0) #3 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %7

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

16:                                               ; preds = %7
  store i64 0, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %112

17:                                               ; preds = %7
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %63, %17
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 64, !tbaa !11
  %23 = icmp ult i64 %19, %22
  br i1 %23, label %24, label %66

24:                                               ; preds = %18
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %25, i32 0, i32 5
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds i64, ptr %27, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  br label %63

33:                                               ; preds = %24
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %34, i32 0, i32 9
  %36 = load i8, ptr %35, align 32, !tbaa !17, !range !18, !noundef !19
  %37 = trunc i8 %36 to i1
  br i1 %37, label %38, label %54

38:                                               ; preds = %33
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.rule_info_struct, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !21
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %47, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = load i64, ptr %4, align 8, !tbaa !9
  %51 = getelementptr inbounds i64, ptr %49, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %46, i64 noundef %52)
  br label %54

54:                                               ; preds = %38, %33
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %55, i32 0, i32 5
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = load i64, ptr %4, align 8, !tbaa !9
  %59 = getelementptr inbounds i64, ptr %57, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = add i64 %61, %60
  store i64 %62, ptr %5, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %54, %32
  %64 = load i64, ptr %4, align 8, !tbaa !9
  %65 = add i64 %64, 1
  store i64 %65, ptr %4, align 8, !tbaa !9
  br label %18, !llvm.loop !23

66:                                               ; preds = %18
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %67, i32 0, i32 10
  %69 = load ptr, ptr %68, align 8, !tbaa !25
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %75

71:                                               ; preds = %66
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %72, i32 0, i32 10
  %74 = load ptr, ptr %73, align 8, !tbaa !25
  call void @mmt_set_ex_free(ptr noundef %74)
  br label %75

75:                                               ; preds = %71, %66
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %89, %75
  %77 = load i64, ptr %4, align 8, !tbaa !9
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %78, i32 0, i32 0
  %80 = load i64, ptr %79, align 64, !tbaa !11
  %81 = icmp ult i64 %77, %80
  br i1 %81, label %82, label %92

82:                                               ; preds = %76
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %83, i32 0, i32 4
  %85 = load ptr, ptr %84, align 32, !tbaa !26
  %86 = load i64, ptr %4, align 8, !tbaa !9
  %87 = getelementptr inbounds ptr, ptr %85, i64 %86
  %88 = load ptr, ptr %87, align 8, !tbaa !5
  call void @rule_engine_free(ptr noundef %88)
  br label %89

89:                                               ; preds = %82
  %90 = load i64, ptr %4, align 8, !tbaa !9
  %91 = add i64 %90, 1
  store i64 %91, ptr %4, align 8, !tbaa !9
  br label %76, !llvm.loop !27

92:                                               ; preds = %76
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !20
  %96 = call i64 @mmt_mem_free(ptr noundef %95)
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %97, i32 0, i32 4
  %99 = load ptr, ptr %98, align 32, !tbaa !26
  %100 = call i64 @mmt_mem_free(ptr noundef %99)
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %101, i32 0, i32 6
  %103 = load ptr, ptr %102, align 16, !tbaa !28
  %104 = call i64 @mmt_mem_free(ptr noundef %103)
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %105, i32 0, i32 5
  %107 = load ptr, ptr %106, align 8, !tbaa !16
  %108 = call i64 @mmt_mem_free(ptr noundef %107)
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = call i64 @mmt_mem_free(ptr noundef %109)
  %111 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %111, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %112

112:                                              ; preds = %92, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %113 = load i64, ptr %2, align 8
  ret i64 %113
}

declare i32 @printf(ptr noundef, ...) #4

declare void @rule_engine_free(ptr noundef) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 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 = { "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 }

!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, !10, i64 0}
!12 = !{!"mmt_single_sec_handler_struct", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !10, i64 88, !14, i64 96, !6, i64 104, !15, i64 112}
!13 = !{!"", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !6, i64 40}
!17 = !{!12, !14, i64 96}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !6, i64 8}
!21 = !{!22, !15, i64 0}
!22 = !{!"rule_info_struct", !15, i64 0, !15, 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}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!12, !6, i64 104}
!26 = !{!12, !6, i64 32}
!27 = distinct !{!27, !24}
!28 = !{!12, !6, i64 48}


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

@.str = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mmt_set_ex_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @mmt_single_sec_unregister(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %61, label %.preheader, !prof !5

.preheader:                                       ; preds = %1
  %3 = load i64, ptr %0, align 64, !tbaa !6
  %.not39 = icmp eq i64 %3, 0
  br i1 %.not39, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %4, align 8, !tbaa !15
  br label %7

7:                                                ; preds = %.lr.ph, %28
  %.pre4244 = phi i64 [ %3, %.lr.ph ], [ %.pre4245, %28 ]
  %8 = phi i64 [ %3, %.lr.ph ], [ %29, %28 ]
  %9 = phi ptr [ %.pre, %.lr.ph ], [ %30, %28 ]
  %10 = phi ptr [ %.pre, %.lr.ph ], [ %31, %28 ]
  %.034 = phi i64 [ 0, %.lr.ph ], [ %.1, %28 ]
  %.02733 = phi i64 [ 0, %.lr.ph ], [ %32, %28 ]
  %11 = getelementptr inbounds i64, ptr %10, i64 %.02733
  %12 = load i64, ptr %11, align 8, !tbaa !16
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %28, label %14

14:                                               ; preds = %7
  %15 = load i8, ptr %5, align 32, !tbaa !17, !range !18, !noundef !19
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %17, label %23

17:                                               ; preds = %14
  %18 = load ptr, ptr %6, align 8, !tbaa !20
  %19 = getelementptr inbounds ptr, ptr %18, i64 %.02733
  %20 = load ptr, ptr %19, align 8, !tbaa !21
  %21 = load i32, ptr %20, align 8, !tbaa !22
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %21, i64 noundef %12)
  %.pre41 = load ptr, ptr %4, align 8, !tbaa !15
  %.pre42.pre = load i64, ptr %0, align 64, !tbaa !6
  br label %23

23:                                               ; preds = %17, %14
  %.pre42 = phi i64 [ %.pre42.pre, %17 ], [ %.pre4244, %14 ]
  %24 = phi ptr [ %.pre41, %17 ], [ %9, %14 ]
  %25 = getelementptr inbounds i64, ptr %24, i64 %.02733
  %26 = load i64, ptr %25, align 8, !tbaa !16
  %27 = add i64 %26, %.034
  br label %28

28:                                               ; preds = %7, %23
  %.pre4245 = phi i64 [ %.pre4244, %7 ], [ %.pre42, %23 ]
  %29 = phi i64 [ %8, %7 ], [ %.pre42, %23 ]
  %30 = phi ptr [ %9, %7 ], [ %24, %23 ]
  %31 = phi ptr [ %10, %7 ], [ %24, %23 ]
  %.1 = phi i64 [ %.034, %7 ], [ %27, %23 ]
  %32 = add nuw i64 %.02733, 1
  %33 = icmp ult i64 %32, %29
  br i1 %33, label %7, label %._crit_edge, !llvm.loop !24

._crit_edge:                                      ; preds = %28, %.preheader
  %34 = phi i64 [ 0, %.preheader ], [ %29, %28 ]
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ %.1, %28 ]
  %35 = getelementptr inbounds i8, ptr %0, i64 104
  %36 = load ptr, ptr %35, align 8, !tbaa !26
  %.not = icmp eq ptr %36, null
  br i1 %.not, label %38, label %37

37:                                               ; preds = %._crit_edge
  tail call void @mmt_set_ex_free(ptr noundef nonnull %36)
  %.pre43 = load i64, ptr %0, align 64, !tbaa !6
  br label %38

38:                                               ; preds = %37, %._crit_edge
  %39 = phi i64 [ %.pre43, %37 ], [ %34, %._crit_edge ]
  %.not40 = icmp eq i64 %39, 0
  br i1 %.not40, label %._crit_edge38, label %.lr.ph37

.lr.ph37:                                         ; preds = %38
  %40 = getelementptr inbounds i8, ptr %0, i64 32
  br label %41

41:                                               ; preds = %.lr.ph37, %41
  %.12835 = phi i64 [ 0, %.lr.ph37 ], [ %45, %41 ]
  %42 = load ptr, ptr %40, align 32, !tbaa !27
  %43 = getelementptr inbounds ptr, ptr %42, i64 %.12835
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  tail call void @rule_engine_free(ptr noundef %44) #4
  %45 = add nuw i64 %.12835, 1
  %46 = load i64, ptr %0, align 64, !tbaa !6
  %47 = icmp ult i64 %45, %46
  br i1 %47, label %41, label %._crit_edge38, !llvm.loop !28

._crit_edge38:                                    ; preds = %41, %38
  %48 = getelementptr inbounds i8, ptr %0, i64 8
  %49 = load ptr, ptr %48, align 8, !tbaa !20
  %50 = tail call i64 @mmt_mem_free(ptr noundef %49)
  %51 = getelementptr inbounds i8, ptr %0, i64 32
  %52 = load ptr, ptr %51, align 32, !tbaa !27
  %53 = tail call i64 @mmt_mem_free(ptr noundef %52)
  %54 = getelementptr inbounds i8, ptr %0, i64 48
  %55 = load ptr, ptr %54, align 16, !tbaa !29
  %56 = tail call i64 @mmt_mem_free(ptr noundef %55)
  %57 = getelementptr inbounds i8, ptr %0, i64 40
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = tail call i64 @mmt_mem_free(ptr noundef %58)
  %60 = tail call i64 @mmt_mem_free(ptr noundef nonnull %0)
  br label %61

61:                                               ; preds = %1, %._crit_edge38
  %.029 = phi i64 [ %.0.lcssa, %._crit_edge38 ], [ 0, %1 ]
  ret i64 %.029
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare void @rule_engine_free(ptr noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #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 = { nofree 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 #3 = { "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 }

!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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!7, !8, i64 0}
!7 = !{!"mmt_single_sec_handler_struct", !8, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !8, i64 88, !13, i64 96, !11, i64 104, !14, i64 112}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"", !9, i64 0}
!13 = !{!"_Bool", !9, i64 0}
!14 = !{!"int", !9, i64 0}
!15 = !{!7, !11, i64 40}
!16 = !{!8, !8, i64 0}
!17 = !{!7, !13, i64 96}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!7, !11, i64 8}
!21 = !{!11, !11, i64 0}
!22 = !{!23, !14, i64 0}
!23 = !{!"rule_info_struct", !14, i64 0, !14, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !9, i64 40, !9, i64 41, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!7, !11, i64 104}
!27 = !{!7, !11, i64 32}
!28 = distinct !{!28, !25}
!29 = !{!7, !11, i64 48}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass