; LLVM IR from Montimage/mmt-security :: src/lib/mmt_map_t.ll (mmt_map_clone_node_and_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

declare ptr @mmt_mem_alloc(i64 noundef) #1

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local void @_mmt_map_clone_node_and_data(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  br label %11

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

20:                                               ; preds = %11
  store i32 1, ptr %10, align 4
  br label %89

21:                                               ; preds = %11
  %22 = call ptr @mmt_mem_alloc(i64 noundef 32)
  store ptr %22, ptr %9, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %23, i32 0, i32 1
  store ptr null, ptr %24, align 8, !tbaa !9
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %25, i32 0, i32 0
  store ptr null, ptr %26, align 8, !tbaa !11
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %37

29:                                               ; preds = %21
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !12
  %34 = call ptr %30(ptr noundef %33)
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %35, i32 0, i32 2
  store ptr %34, ptr %36, align 8, !tbaa !12
  br label %43

37:                                               ; preds = %21
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !12
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %41, i32 0, i32 2
  store ptr %40, ptr %42, align 8, !tbaa !12
  br label %43

43:                                               ; preds = %37, %29
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %54

46:                                               ; preds = %43
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = call ptr %47(ptr noundef %50)
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %52, i32 0, i32 3
  store ptr %51, ptr %53, align 8, !tbaa !13
  br label %60

54:                                               ; preds = %43
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %58, i32 0, i32 3
  store ptr %57, ptr %59, align 8, !tbaa !13
  br label %60

60:                                               ; preds = %54, %46
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %61, ptr %62, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %75

67:                                               ; preds = %60
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_mmt_map_clone_node_and_data(ptr noundef %69, ptr noundef %72, ptr noundef %73, ptr noundef %74)
  br label %75

75:                                               ; preds = %67, %60
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %88

80:                                               ; preds = %75
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.mmt_map_node_struct, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_mmt_map_clone_node_and_data(ptr noundef %82, ptr noundef %85, ptr noundef %86, ptr noundef %87)
  br label %88

88:                                               ; preds = %80, %75
  store i32 0, ptr %10, align 4
  br label %89

89:                                               ; preds = %88, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %90 = load i32, ptr %10, align 4
  switch i32 %90, label %92 [
    i32 0, label %91
    i32 1, label %91
  ]

91:                                               ; preds = %89, %89
  ret void

92:                                               ; preds = %89
  unreachable
}

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


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

declare ptr @mmt_mem_alloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @_mmt_map_clone_node_and_data(ptr nocapture noundef writeonly %0, ptr noundef readonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %2, null
  %.not31 = icmp eq ptr %3, null
  br i1 %.not, label %.split.us, label %.split

.split.us:                                        ; preds = %4
  br i1 %.not31, label %tailrecurse.us.us, label %tailrecurse.us

tailrecurse.us.us:                                ; preds = %.split.us, %14
  %.tr.us.us = phi ptr [ %8, %14 ], [ %0, %.split.us ]
  %.tr34.us.us = phi ptr [ %16, %14 ], [ %1, %.split.us ]
  %5 = icmp eq ptr %.tr34.us.us, null
  br i1 %5, label %.split38.us, label %6, !prof !5

6:                                                ; preds = %tailrecurse.us.us
  %7 = tail call ptr @mmt_mem_alloc(i64 noundef 32) #3
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = getelementptr inbounds i8, ptr %.tr34.us.us, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  %10 = getelementptr inbounds i8, ptr %7, i64 16
  %11 = load <2 x ptr>, ptr %9, align 8, !tbaa !6
  store <2 x ptr> %11, ptr %10, align 8, !tbaa !6
  store ptr %7, ptr %.tr.us.us, align 8, !tbaa !6
  %12 = load ptr, ptr %.tr34.us.us, align 8, !tbaa !10
  %.not32.us.us = icmp eq ptr %12, null
  br i1 %.not32.us.us, label %14, label %13

13:                                               ; preds = %6
  tail call void @_mmt_map_clone_node_and_data(ptr noundef nonnull %7, ptr noundef nonnull %12, ptr noundef null, ptr noundef null)
  br label %14

14:                                               ; preds = %13, %6
  %15 = getelementptr inbounds i8, ptr %.tr34.us.us, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %.not33.us.us = icmp eq ptr %16, null
  br i1 %.not33.us.us, label %.split38.us, label %tailrecurse.us.us

tailrecurse.us:                                   ; preds = %.split.us, %30
  %.tr.us = phi ptr [ %20, %30 ], [ %0, %.split.us ]
  %.tr34.us = phi ptr [ %32, %30 ], [ %1, %.split.us ]
  %17 = icmp eq ptr %.tr34.us, null
  br i1 %17, label %.split38.us, label %18, !prof !5

18:                                               ; preds = %tailrecurse.us
  %19 = tail call ptr @mmt_mem_alloc(i64 noundef 32) #3
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = getelementptr inbounds i8, ptr %.tr34.us, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %19, i8 0, i64 16, i1 false)
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %19, i64 16
  store ptr %22, ptr %23, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %.tr34.us, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = tail call ptr %3(ptr noundef %25) #3
  %27 = getelementptr inbounds i8, ptr %19, i64 24
  store ptr %26, ptr %27, align 8, !tbaa !14
  store ptr %19, ptr %.tr.us, align 8, !tbaa !6
  %28 = load ptr, ptr %.tr34.us, align 8, !tbaa !10
  %.not32.us = icmp eq ptr %28, null
  br i1 %.not32.us, label %30, label %29

29:                                               ; preds = %18
  tail call void @_mmt_map_clone_node_and_data(ptr noundef nonnull %19, ptr noundef nonnull %28, ptr noundef null, ptr noundef nonnull %3)
  br label %30

30:                                               ; preds = %29, %18
  %31 = getelementptr inbounds i8, ptr %.tr34.us, i64 8
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %.not33.us = icmp eq ptr %32, null
  br i1 %.not33.us, label %.split38.us, label %tailrecurse.us

.split:                                           ; preds = %4
  br i1 %.not31, label %tailrecurse.us39, label %tailrecurse

tailrecurse.us39:                                 ; preds = %.split, %46
  %.tr.us40 = phi ptr [ %36, %46 ], [ %0, %.split ]
  %.tr34.us41 = phi ptr [ %48, %46 ], [ %1, %.split ]
  %33 = icmp eq ptr %.tr34.us41, null
  br i1 %33, label %.split38.us, label %34, !prof !5

34:                                               ; preds = %tailrecurse.us39
  %35 = tail call ptr @mmt_mem_alloc(i64 noundef 32) #3
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = getelementptr inbounds i8, ptr %.tr34.us41, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %35, i8 0, i64 16, i1 false)
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = tail call ptr %2(ptr noundef %38) #3
  %40 = getelementptr inbounds i8, ptr %35, i64 16
  store ptr %39, ptr %40, align 8, !tbaa !13
  %41 = getelementptr inbounds i8, ptr %.tr34.us41, i64 24
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = getelementptr inbounds i8, ptr %35, i64 24
  store ptr %42, ptr %43, align 8, !tbaa !14
  store ptr %35, ptr %.tr.us40, align 8, !tbaa !6
  %44 = load ptr, ptr %.tr34.us41, align 8, !tbaa !10
  %.not32.us42 = icmp eq ptr %44, null
  br i1 %.not32.us42, label %46, label %45

45:                                               ; preds = %34
  tail call void @_mmt_map_clone_node_and_data(ptr noundef nonnull %35, ptr noundef nonnull %44, ptr noundef nonnull %2, ptr noundef null)
  br label %46

46:                                               ; preds = %45, %34
  %47 = getelementptr inbounds i8, ptr %.tr34.us41, i64 8
  %48 = load ptr, ptr %47, align 8, !tbaa !12
  %.not33.us43 = icmp eq ptr %48, null
  br i1 %.not33.us43, label %.split38.us, label %tailrecurse.us39

tailrecurse:                                      ; preds = %.split, %63
  %.tr = phi ptr [ %52, %63 ], [ %0, %.split ]
  %.tr34 = phi ptr [ %65, %63 ], [ %1, %.split ]
  %49 = icmp eq ptr %.tr34, null
  br i1 %49, label %.split38.us, label %50, !prof !5

50:                                               ; preds = %tailrecurse
  %51 = tail call ptr @mmt_mem_alloc(i64 noundef 32) #3
  %52 = getelementptr inbounds i8, ptr %51, i64 8
  %53 = getelementptr inbounds i8, ptr %.tr34, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %51, i8 0, i64 16, i1 false)
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = tail call ptr %2(ptr noundef %54) #3
  %56 = getelementptr inbounds i8, ptr %51, i64 16
  store ptr %55, ptr %56, align 8, !tbaa !13
  %57 = getelementptr inbounds i8, ptr %.tr34, i64 24
  %58 = load ptr, ptr %57, align 8, !tbaa !14
  %59 = tail call ptr %3(ptr noundef %58) #3
  %60 = getelementptr inbounds i8, ptr %51, i64 24
  store ptr %59, ptr %60, align 8, !tbaa !14
  store ptr %51, ptr %.tr, align 8, !tbaa !6
  %61 = load ptr, ptr %.tr34, align 8, !tbaa !10
  %.not32 = icmp eq ptr %61, null
  br i1 %.not32, label %63, label %62

62:                                               ; preds = %50
  tail call void @_mmt_map_clone_node_and_data(ptr noundef nonnull %51, ptr noundef nonnull %61, ptr noundef nonnull %2, ptr noundef nonnull %3)
  br label %63

63:                                               ; preds = %62, %50
  %64 = getelementptr inbounds i8, ptr %.tr34, i64 8
  %65 = load ptr, ptr %64, align 8, !tbaa !12
  %.not33 = icmp eq ptr %65, null
  br i1 %.not33, label %.split38.us, label %tailrecurse

.split38.us:                                      ; preds = %63, %tailrecurse, %46, %tailrecurse.us39, %30, %tailrecurse.us, %14, %tailrecurse.us.us
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"mmt_map_node_struct", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!12 = !{!11, !7, i64 8}
!13 = !{!11, !7, i64 16}
!14 = !{!11, !7, i64 24}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass