; LLVM IR from Montimage/mmt-security :: src/lib/mmt_map_t.ll (mmt_map_get_data)

; 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_map_node_struct = type { ptr, ptr, ptr, ptr }

; 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: nounwind uwtable
define dso_local ptr @_mmt_map_get_data(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %58

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call i32 %14(ptr noundef %15, ptr noundef %18)
  store i32 %19, ptr %8, align 4, !tbaa !11
  %20 = load i32, ptr %8, align 4, !tbaa !11
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %26

22:                                               ; preds = %13
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  store ptr %25, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %57

26:                                               ; preds = %13
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %42

29:                                               ; preds = %26
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %41

34:                                               ; preds = %29
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = call ptr @_mmt_map_get_data(ptr noundef %35, ptr noundef %38, ptr noundef %39)
  store ptr %40, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %57

41:                                               ; preds = %29
  br label %55

42:                                               ; preds = %26
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %54

47:                                               ; preds = %42
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call ptr @_mmt_map_get_data(ptr noundef %48, ptr noundef %51, ptr noundef %52)
  store ptr %53, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %57

54:                                               ; preds = %42
  br label %55

55:                                               ; preds = %54, %41
  br label %56

56:                                               ; preds = %55
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %57

57:                                               ; preds = %56, %47, %34, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %58

58:                                               ; preds = %57, %12
  %59 = load ptr, ptr %4, align 8
  ret ptr %59
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 16}
!10 = !{!"mmt_map_node_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !6, i64 8}


; 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 ptr @_mmt_map_get_data(ptr nocapture noundef readonly %0, ptr noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %1, null
  br i1 %4, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call i32 %0(ptr noundef %2, ptr noundef %6) #1
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.lr.ph._crit_edge, label %.lr.ph29

.lr.ph._crit_edge:                                ; preds = %tailrecurse.backedge, %.lr.ph.preheader
  %.tr2023.lcssa = phi ptr [ %1, %.lr.ph.preheader ], [ %.tr20.be, %tailrecurse.backedge ]
  %9 = getelementptr inbounds i8, ptr %.tr2023.lcssa, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  br label %.loopexit

.lr.ph29:                                         ; preds = %.lr.ph.preheader, %tailrecurse.backedge
  %11 = phi i32 [ %17, %tailrecurse.backedge ], [ %7, %.lr.ph.preheader ]
  %.tr202328 = phi ptr [ %.tr20.be, %tailrecurse.backedge ], [ %1, %.lr.ph.preheader ]
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %19

13:                                               ; preds = %.lr.ph29
  %14 = load ptr, ptr %.tr202328, align 8, !tbaa !11
  %.not19 = icmp eq ptr %14, null
  br i1 %.not19, label %.loopexit, label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %13, %19
  %.tr20.be = phi ptr [ %14, %13 ], [ %21, %19 ]
  %15 = getelementptr inbounds i8, ptr %.tr20.be, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = tail call i32 %0(ptr noundef %2, ptr noundef %16) #1
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %.lr.ph._crit_edge, label %.lr.ph29

19:                                               ; preds = %.lr.ph29
  %20 = getelementptr inbounds i8, ptr %.tr202328, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %.loopexit, label %tailrecurse.backedge

.loopexit:                                        ; preds = %19, %13, %3, %.lr.ph._crit_edge
  %.1 = phi ptr [ %10, %.lr.ph._crit_edge ], [ null, %3 ], [ null, %13 ], [ null, %19 ]
  ret ptr %.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 = { 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, !7, i64 16}
!6 = !{!"mmt_map_node_struct", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 24}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass