; LLVM IR from jingweizhanghuai/Morn :: src/util/morn_graph.ll (GraphMapWrite)

; 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.HandleGraphRoute = type { i32, ptr, ptr, i32, ptr, ptr, i32, i32, ptr }
%struct.MChainNode = type { ptr, ptr, ptr }
%struct.MObject = type { i32, %union.anon }
%union.anon = type { 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
declare dso_local void @_GraphListAppend(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @_GraphNodeSeek(ptr noundef, float noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @_GraphMapWrite(ptr noundef %0, ptr noundef %1, float noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store float %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.HandleGraphRoute, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = call ptr @mChainNode(ptr noundef %15, ptr noundef null, i32 noundef 8)
  store ptr %16, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MChainNode, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  store ptr %19, ptr %10, align 8, !tbaa !5
  %20 = load float, ptr %7, align 4, !tbaa !9
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds float, ptr %21, i64 0
  store float %20, ptr %22, align 4, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds float, ptr %24, i64 1
  store i32 %23, ptr %25, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.MChainNode, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  store ptr %28, ptr %11, align 8, !tbaa !5
  %29 = load float, ptr %7, align 4, !tbaa !9
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MChainNode, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load float, ptr %32, align 4, !tbaa !9
  %34 = fcmp ole float %29, %33
  br i1 %34, label %43, label %35

35:                                               ; preds = %4
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.HandleGraphRoute, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = getelementptr inbounds %struct.MObject, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = icmp eq ptr %36, %41
  br i1 %42, label %43, label %46

43:                                               ; preds = %35, %4
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  call void @mChainNodeInsert(ptr noundef %44, ptr noundef %45, ptr noundef null)
  br label %53

46:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load float, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !11
  %50 = call ptr @_GraphNodeSeek(ptr noundef %47, float noundef %48, i32 noundef %49)
  store ptr %50, ptr %12, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  call void @mChainNodeInsert(ptr noundef null, ptr noundef %51, ptr noundef %52)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %53

53:                                               ; preds = %46, %43
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.HandleGraphRoute, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !19
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 8, !tbaa !19
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.HandleGraphRoute, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !19
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.HandleGraphRoute, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 8, !tbaa !20
  %64 = mul nsw i32 %63, 2
  %65 = icmp sge i32 %60, %64
  br i1 %65, label %66, label %68

66:                                               ; preds = %53
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_GraphListAppend(ptr noundef %67)
  br label %68

68:                                               ; preds = %66, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

declare ptr @mChainNode(ptr noundef, ptr noundef, i32 noundef) #2

declare void @mChainNodeInsert(ptr noundef, ptr noundef, ptr noundef) #2

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 = { "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 = !{!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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"HandleGraphRoute", !12, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !12, i64 52, !6, i64 56}
!15 = !{!16, !6, i64 0}
!16 = !{!"MChainNode", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!16, !6, i64 16}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !12, i64 0}
!20 = !{!14, !12, 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"

; Function Attrs: nounwind uwtable
declare dso_local void @_GraphListAppend(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @_GraphNodeSeek(ptr noundef, float noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @_GraphMapWrite(ptr noundef %0, ptr noundef %1, float noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @mChainNode(ptr noundef %6, ptr noundef null, i32 noundef 8) #2
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  store float %2, ptr %8, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 %3, ptr %9, align 4, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load float, ptr %12, align 4, !tbaa !13
  %14 = fcmp ult float %13, %2
  br i1 %14, label %15, label %20

15:                                               ; preds = %4
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = icmp eq ptr %11, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15, %4
  tail call void @mChainNodeInsert(ptr noundef nonnull %1, ptr noundef nonnull %7, ptr noundef null) #2
  br label %23

21:                                               ; preds = %15
  %22 = tail call ptr @_GraphNodeSeek(ptr noundef nonnull %0, float noundef %2, i32 noundef %3)
  tail call void @mChainNodeInsert(ptr noundef null, ptr noundef nonnull %7, ptr noundef %22) #2
  br label %23

23:                                               ; preds = %21, %20
  %24 = load i32, ptr %0, align 8, !tbaa !18
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %0, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  %27 = load i32, ptr %26, align 8, !tbaa !19
  %28 = shl nsw i32 %27, 1
  %.not = icmp slt i32 %25, %28
  br i1 %.not, label %30, label %29

29:                                               ; preds = %23
  tail call void @_GraphListAppend(ptr noundef nonnull %0)
  br label %30

30:                                               ; preds = %29, %23
  ret void
}

declare ptr @mChainNode(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @mChainNodeInsert(ptr noundef, ptr noundef, 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 = { "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, !10, i64 8}
!6 = !{!"HandleGraphRoute", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 52, !10, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"MChainNode", !10, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !10, i64 16}
!17 = !{!8, !8, i64 0}
!18 = !{!6, !7, i64 0}
!19 = !{!6, !7, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass