; LLVM IR from Montimage/mmt-security :: src/lib (mmt_smp_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_smp_sec_handler_struct = type { i64, ptr, ptr, ptr, i8, [31 x i8] }

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

; Function Attrs: nounwind uwtable
define dso_local i64 @mmt_smp_sec_unregister(ptr noundef %0, i1 noundef zeroext %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %11 = zext i1 %1 to i8
  store i8 %11, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  br label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  %15 = xor i1 %14, true
  %16 = xor i1 %15, true
  %17 = zext i1 %16 to i32
  %18 = sext i32 %17 to i64
  %19 = call i64 @llvm.expect.i64(i64 %18, i64 0)
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %12
  store i64 0, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %96

22:                                               ; preds = %12
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %25 = trunc i8 %24 to i1
  call void @_mmt_smp_sec_stop(ptr noundef %23, i1 noundef zeroext %25)
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %60, %22
  %27 = load i64, ptr %6, align 8, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 64, !tbaa !15
  %31 = icmp ult i64 %27, %30
  br i1 %31, label %32, label %63

32:                                               ; preds = %26
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = load i64, ptr %6, align 8, !tbaa !11
  %37 = getelementptr inbounds ptr, ptr %35, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = call i64 @mmt_single_sec_get_processed_messages(ptr noundef %38)
  store i64 %39, ptr %9, align 8, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = load i64, ptr %6, align 8, !tbaa !11
  %44 = getelementptr inbounds ptr, ptr %42, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = call i64 @mmt_single_sec_unregister(ptr noundef %45)
  store i64 %46, ptr %8, align 8, !tbaa !11
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %47, i32 0, i32 4
  %49 = load i8, ptr %48, align 32, !tbaa !18, !range !13, !noundef !14
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %56

51:                                               ; preds = %32
  %52 = load i64, ptr %6, align 8, !tbaa !11
  %53 = add i64 %52, 1
  %54 = load i64, ptr %9, align 8, !tbaa !11
  %55 = load i64, ptr %8, align 8, !tbaa !11
  call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 0, ptr noundef @.str, i64 noundef %53, i64 noundef %54, i64 noundef %55)
  br label %56

56:                                               ; preds = %51, %32
  %57 = load i64, ptr %8, align 8, !tbaa !11
  %58 = load i64, ptr %7, align 8, !tbaa !11
  %59 = add i64 %58, %57
  store i64 %59, ptr %7, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %56
  %61 = load i64, ptr %6, align 8, !tbaa !11
  %62 = add i64 %61, 1
  store i64 %62, ptr %6, align 8, !tbaa !11
  br label %26, !llvm.loop !19

63:                                               ; preds = %26
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %77, %63
  %65 = load i64, ptr %6, align 8, !tbaa !11
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %66, i32 0, i32 0
  %68 = load i64, ptr %67, align 64, !tbaa !15
  %69 = icmp ult i64 %65, %68
  br i1 %69, label %70, label %80

70:                                               ; preds = %64
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !21
  %74 = load i64, ptr %6, align 8, !tbaa !11
  %75 = getelementptr inbounds ptr, ptr %73, i64 %74
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  call void @ring_free(ptr noundef %76)
  br label %77

77:                                               ; preds = %70
  %78 = load i64, ptr %6, align 8, !tbaa !11
  %79 = add i64 %78, 1
  store i64 %79, ptr %6, align 8, !tbaa !11
  br label %64, !llvm.loop !22

80:                                               ; preds = %64
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %81, i32 0, i32 3
  %83 = load ptr, ptr %82, align 8, !tbaa !21
  %84 = call i64 @mmt_mem_free(ptr noundef %83)
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !17
  %88 = call i64 @mmt_mem_free(ptr noundef %87)
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.mmt_smp_sec_handler_struct, ptr %89, i32 0, i32 2
  %91 = load ptr, ptr %90, align 16, !tbaa !23
  %92 = call i64 @mmt_mem_free(ptr noundef %91)
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = call i64 @mmt_mem_free(ptr noundef %93)
  %95 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %95, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %96

96:                                               ; preds = %80, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %97 = load i64, ptr %3, align 8
  ret i64 %97
}

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

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

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

declare i64 @mmt_single_sec_get_processed_messages(ptr noundef) #4

declare i64 @mmt_single_sec_unregister(ptr noundef) #4

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

declare void @ring_free(ptr noundef) #4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !12, i64 0}
!16 = !{!"mmt_smp_sec_handler_struct", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!17 = !{!16, !6, i64 8}
!18 = !{!16, !10, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!16, !6, i64 24}
!22 = distinct !{!22, !20}
!23 = !{!16, !6, i64 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"

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

; Function Attrs: nounwind uwtable
define dso_local i64 @mmt_smp_sec_unregister(ptr noundef %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %43, label %4, !prof !5

4:                                                ; preds = %2
  tail call void @_mmt_smp_sec_stop(ptr noundef nonnull %0, i1 noundef zeroext %1)
  %5 = load i64, ptr %0, align 64, !tbaa !6
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  br label %10

.preheader:                                       ; preds = %._crit_edge34
  %8 = icmp eq i64 %24, 0
  br i1 %8, label %._crit_edge, label %.lr.ph32

.lr.ph32:                                         ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  br label %26

10:                                               ; preds = %.lr.ph, %._crit_edge34
  %.02630 = phi i64 [ 0, %.lr.ph ], [ %21, %._crit_edge34 ]
  %.02729 = phi i64 [ 0, %.lr.ph ], [ %23, %._crit_edge34 ]
  %11 = load ptr, ptr %6, align 8, !tbaa !13
  %12 = getelementptr inbounds ptr, ptr %11, i64 %.02630
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = tail call i64 @mmt_single_sec_get_processed_messages(ptr noundef %13) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !13
  %16 = getelementptr inbounds ptr, ptr %15, i64 %.02630
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = tail call i64 @mmt_single_sec_unregister(ptr noundef %17) #3
  %19 = load i8, ptr %7, align 32, !tbaa !15, !range !16, !noundef !17
  %20 = trunc nuw i8 %19 to i1
  %21 = add nuw i64 %.02630, 1
  br i1 %20, label %22, label %._crit_edge34

22:                                               ; preds = %10
  tail call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 0, ptr noundef nonnull @.str, i64 noundef %21, i64 noundef %14, i64 noundef %18) #3
  br label %._crit_edge34

._crit_edge34:                                    ; preds = %10, %22
  %23 = add i64 %18, %.02729
  %24 = load i64, ptr %0, align 64, !tbaa !6
  %25 = icmp ult i64 %21, %24
  br i1 %25, label %10, label %.preheader, !llvm.loop !18

26:                                               ; preds = %.lr.ph32, %26
  %.131 = phi i64 [ 0, %.lr.ph32 ], [ %30, %26 ]
  %27 = load ptr, ptr %9, align 8, !tbaa !20
  %28 = getelementptr inbounds ptr, ptr %27, i64 %.131
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  tail call void @ring_free(ptr noundef %29) #3
  %30 = add nuw i64 %.131, 1
  %31 = load i64, ptr %0, align 64, !tbaa !6
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %26, label %._crit_edge, !llvm.loop !21

._crit_edge:                                      ; preds = %26, %4, %.preheader
  %.027.lcssa37 = phi i64 [ %23, %.preheader ], [ 0, %4 ], [ %23, %26 ]
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  %35 = tail call i64 @mmt_mem_free(ptr noundef %34)
  %36 = getelementptr inbounds i8, ptr %0, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = tail call i64 @mmt_mem_free(ptr noundef %37)
  %39 = getelementptr inbounds i8, ptr %0, i64 16
  %40 = load ptr, ptr %39, align 16, !tbaa !22
  %41 = tail call i64 @mmt_mem_free(ptr noundef %40)
  %42 = tail call i64 @mmt_mem_free(ptr noundef nonnull %0)
  br label %43

43:                                               ; preds = %2, %._crit_edge
  %.0 = phi i64 [ %.027.lcssa37, %._crit_edge ], [ 0, %2 ]
  ret i64 %.0
}

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

declare i64 @mmt_single_sec_get_processed_messages(ptr noundef) local_unnamed_addr #2

declare i64 @mmt_single_sec_unregister(ptr noundef) local_unnamed_addr #2

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

declare void @ring_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mmt_mem_free(ptr noundef) local_unnamed_addr #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 = { 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_smp_sec_handler_struct", !8, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_Bool", !9, i64 0}
!13 = !{!7, !11, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!7, !12, i64 32}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!7, !11, i64 24}
!21 = distinct !{!21, !19}
!22 = !{!7, !11, i64 16}


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