; 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] }

; Function Attrs: nounwind uwtable
define dso_local void @mmt_single_sec_set_ignore_remain_flow(ptr noundef %0, i1 noundef zeroext %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  %7 = zext i1 %1 to i8
  store i8 %7, ptr %5, align 1, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  %8 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %9 = trunc i8 %8 to i1
  br i1 %9, label %10, label %15

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %11, i32 0, i32 10
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %21

15:                                               ; preds = %10, %3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %16, i32 0, i32 10
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  call void @mmt_set_ex_free(ptr noundef %18)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %19, i32 0, i32 10
  store ptr null, ptr %20, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %15, %10
  %22 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %23 = trunc i8 %22 to i1
  br i1 %23, label %24, label %30

24:                                               ; preds = %21
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = trunc i64 %25 to i32
  %27 = call ptr @mmt_set_ex_create(i32 noundef %26)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mmt_single_sec_handler_struct, ptr %28, i32 0, i32 10
  store ptr %27, ptr %29, align 8, !tbaa !15
  br label %30

30:                                               ; preds = %24, %21
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mmt_set_ex_create(i32 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" }

!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, !6, i64 104}
!16 = !{!"mmt_single_sec_handler_struct", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !17, i64 56, !12, i64 88, !10, i64 96, !6, i64 104, !18, i64 112}
!17 = !{!"", !7, i64 0}
!18 = !{!"int", !7, i64 0}


; 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 @mmt_single_sec_set_ignore_remain_flow(ptr nocapture noundef %0, i1 noundef zeroext %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 104
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  br i1 %1, label %6, label %7

6:                                                ; preds = %3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.thread, label %.thread6

.thread6:                                         ; preds = %6
  tail call void @mmt_set_ex_free(ptr noundef nonnull %5)
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %.thread

7:                                                ; preds = %3
  tail call void @mmt_set_ex_free(ptr noundef %5)
  br label %10

.thread:                                          ; preds = %6, %.thread6
  %8 = trunc i64 %2 to i32
  %9 = tail call ptr @mmt_set_ex_create(i32 noundef %8)
  br label %10

10:                                               ; preds = %7, %.thread
  %.sink = phi ptr [ null, %7 ], [ %9, %.thread ]
  store ptr %.sink, ptr %4, align 8, !tbaa !5
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mmt_set_ex_create(i32 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" }

!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, !10, i64 104}
!6 = !{!"mmt_single_sec_handler_struct", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !11, i64 56, !7, i64 88, !12, i64 96, !10, i64 104, !13, i64 112}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"int", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass