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

; 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_engine_struct = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, ptr, ptr, i64, i64 }

; 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

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

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

14:                                               ; preds = %5
  store i32 1, ptr %4, align 4
  br label %77

15:                                               ; preds = %5
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %30, %15
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.rule_engine_struct, ptr %18, i32 0, i32 5
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = icmp ult i64 %17, %21
  br i1 %22, label %23, label %33

23:                                               ; preds = %16
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rule_engine_struct, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 16, !tbaa !14
  %27 = load i64, ptr %3, align 8, !tbaa !9
  %28 = getelementptr inbounds ptr, ptr %26, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  call void @free_link_list(ptr noundef %29, i1 noundef zeroext true)
  br label %30

30:                                               ; preds = %23
  %31 = load i64, ptr %3, align 8, !tbaa !9
  %32 = add i64 %31, 1
  store i64 %32, ptr %3, align 8, !tbaa !9
  br label %16, !llvm.loop !15

33:                                               ; preds = %16
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.rule_engine_struct, ptr %34, i32 0, i32 5
  store i32 0, ptr %35, align 8, !tbaa !11
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rule_engine_struct, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 16, !tbaa !14
  %39 = call i64 @mmt_mem_free(ptr noundef %38)
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %54, %33
  %41 = load i64, ptr %3, align 8, !tbaa !9
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rule_engine_struct, ptr %42, i32 0, i32 6
  %44 = load i32, ptr %43, align 4, !tbaa !17
  %45 = zext i32 %44 to i64
  %46 = icmp ult i64 %41, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %40
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.rule_engine_struct, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load i64, ptr %3, align 8, !tbaa !9
  %52 = getelementptr inbounds ptr, ptr %50, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  call void @free_link_list_and_data(ptr noundef %53, ptr noundef @fsm_free)
  br label %54

54:                                               ; preds = %47
  %55 = load i64, ptr %3, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %3, align 8, !tbaa !9
  br label %40, !llvm.loop !19

57:                                               ; preds = %40
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.rule_engine_struct, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = call i64 @mmt_mem_free(ptr noundef %60)
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rule_engine_struct, ptr %62, i32 0, i32 10
  %64 = load ptr, ptr %63, align 64, !tbaa !20
  %65 = call i64 @mmt_mem_free(ptr noundef %64)
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.rule_engine_struct, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 32, !tbaa !21
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %74

70:                                               ; preds = %57
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.rule_engine_struct, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 32, !tbaa !21
  call void @mmt_array_free(ptr noundef %73, ptr noundef @free_message_t)
  br label %74

74:                                               ; preds = %70, %57
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = call i64 @mmt_mem_free(ptr noundef %75)
  store i32 0, ptr %4, align 4
  br label %77

77:                                               ; preds = %74, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  %78 = load i32, ptr %4, align 4
  switch i32 %78, label %80 [
    i32 0, label %79
    i32 1, label %79
  ]

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

80:                                               ; preds = %77
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @free_link_list(ptr noundef, i1 noundef zeroext) #3

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

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

declare void @fsm_free(ptr noundef) #4

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @mmt_array_free(ptr noundef, ptr noundef) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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 = { "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 = { alwaysinline 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 = { 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, !13, i64 40}
!12 = !{!"rule_engine_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !6, i64 56, !6, i64 64, !10, i64 72, !10, i64 80}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !13, i64 44}
!18 = !{!12, !6, i64 24}
!19 = distinct !{!19, !16}
!20 = !{!12, !6, i64 64}
!21 = !{!12, !6, i64 32}


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

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

.preheader:                                       ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load i32, ptr %3, align 8, !tbaa !6
  %.not24 = icmp eq i32 %4, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %.019 = phi i64 [ 0, %.lr.ph ], [ %10, %6 ]
  %7 = load ptr, ptr %5, align 16, !tbaa !13
  %8 = getelementptr inbounds ptr, ptr %7, i64 %.019
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  tail call void @free_link_list(ptr noundef %9, i1 noundef zeroext true)
  %10 = add nuw nsw i64 %.019, 1
  %11 = load i32, ptr %3, align 8, !tbaa !6
  %12 = zext i32 %11 to i64
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %6, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %6, %.preheader
  store i32 0, ptr %3, align 8, !tbaa !6
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 16, !tbaa !13
  %16 = tail call i64 @mmt_mem_free(ptr noundef %15)
  %17 = getelementptr inbounds i8, ptr %0, i64 44
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %.not25 = icmp eq i32 %18, 0
  br i1 %.not25, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %._crit_edge
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  br label %20

20:                                               ; preds = %.lr.ph22, %20
  %.120 = phi i64 [ 0, %.lr.ph22 ], [ %24, %20 ]
  %21 = load ptr, ptr %19, align 8, !tbaa !18
  %22 = getelementptr inbounds ptr, ptr %21, i64 %.120
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  tail call void @free_link_list_and_data(ptr noundef %23, ptr noundef nonnull @fsm_free)
  %24 = add nuw nsw i64 %.120, 1
  %25 = load i32, ptr %17, align 4, !tbaa !17
  %26 = zext i32 %25 to i64
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %20, label %._crit_edge23, !llvm.loop !19

._crit_edge23:                                    ; preds = %20, %._crit_edge
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  %30 = tail call i64 @mmt_mem_free(ptr noundef %29)
  %31 = getelementptr inbounds i8, ptr %0, i64 64
  %32 = load ptr, ptr %31, align 64, !tbaa !20
  %33 = tail call i64 @mmt_mem_free(ptr noundef %32)
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  %35 = load ptr, ptr %34, align 32, !tbaa !21
  %.not = icmp eq ptr %35, null
  br i1 %.not, label %37, label %36

36:                                               ; preds = %._crit_edge23
  tail call void @mmt_array_free(ptr noundef nonnull %35, ptr noundef nonnull @free_message_t)
  br label %37

37:                                               ; preds = %36, %._crit_edge23
  %38 = tail call i64 @mmt_mem_free(ptr noundef nonnull %0)
  br label %39

39:                                               ; preds = %1, %37
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @free_link_list(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @free_link_list_and_data(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @fsm_free(ptr noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @mmt_array_free(ptr noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { 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 = { 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 #2 = { "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 = { alwaysinline 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" }

!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, !11, i64 40}
!7 = !{!"rule_engine_struct", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !8, i64 56, !8, i64 64, !12, i64 72, !12, i64 80}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!7, !8, i64 16}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!7, !11, i64 44}
!18 = !{!7, !8, i64 24}
!19 = distinct !{!19, !16}
!20 = !{!7, !8, i64 64}
!21 = !{!7, !8, i64 32}


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