; LLVM IR from Thre4dripper/DSA-Programs :: 06. Circular Doubly Linked Lists/Insertion.ll (Z11insertAtEndiPP4Node)

; 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.Node = type { i32, 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(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: mustprogress uwtable
define dso_local void @_Z11insertAtEndiPP4Node(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  store ptr %6, ptr %5, align 8, !tbaa !9
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 0
  store i32 %7, ptr %9, align 8, !tbaa !11
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.Node, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp eq ptr %13, %15
  br i1 %16, label %17, label %32

17:                                               ; preds = %2
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.Node, ptr %20, i32 0, i32 1
  store ptr %18, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Node, ptr %24, i32 0, i32 2
  store ptr %22, ptr %25, align 8, !tbaa !14
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.Node, ptr %27, i32 0, i32 1
  store ptr %26, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Node, ptr %30, i32 0, i32 2
  store ptr %29, ptr %31, align 8, !tbaa !14
  br label %99

32:                                               ; preds = %2
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = getelementptr inbounds %struct.Node, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.Node, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = icmp eq ptr %38, %42
  br i1 %43, label %44, label %69

44:                                               ; preds = %32
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.Node, ptr %49, i32 0, i32 1
  store ptr %48, ptr %50, align 8, !tbaa !13
  %51 = load ptr, ptr %4, align 8, !tbaa !9
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.Node, ptr %55, i32 0, i32 2
  store ptr %54, ptr %56, align 8, !tbaa !14
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = getelementptr inbounds %struct.Node, ptr %61, i32 0, i32 1
  store ptr %57, ptr %62, align 8, !tbaa !13
  %63 = load ptr, ptr %5, align 8, !tbaa !9
  %64 = load ptr, ptr %4, align 8, !tbaa !9
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.Node, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = getelementptr inbounds %struct.Node, ptr %67, i32 0, i32 2
  store ptr %63, ptr %68, align 8, !tbaa !14
  br label %98

69:                                               ; preds = %32
  %70 = load ptr, ptr %4, align 8, !tbaa !9
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.Node, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !13
  %74 = load ptr, ptr %5, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.Node, ptr %74, i32 0, i32 1
  store ptr %73, ptr %75, align 8, !tbaa !13
  %76 = load ptr, ptr %4, align 8, !tbaa !9
  %77 = load ptr, ptr %76, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.Node, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !13
  %80 = getelementptr inbounds %struct.Node, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !14
  %82 = load ptr, ptr %5, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.Node, ptr %82, i32 0, i32 2
  store ptr %81, ptr %83, align 8, !tbaa !14
  %84 = load ptr, ptr %5, align 8, !tbaa !9
  %85 = load ptr, ptr %4, align 8, !tbaa !9
  %86 = load ptr, ptr %85, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.Node, ptr %86, i32 0, i32 1
  %88 = load ptr, ptr %87, align 8, !tbaa !13
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !14
  %91 = getelementptr inbounds %struct.Node, ptr %90, i32 0, i32 1
  store ptr %84, ptr %91, align 8, !tbaa !13
  %92 = load ptr, ptr %5, align 8, !tbaa !9
  %93 = load ptr, ptr %4, align 8, !tbaa !9
  %94 = load ptr, ptr %93, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct.Node, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !13
  %97 = getelementptr inbounds %struct.Node, ptr %96, i32 0, i32 2
  store ptr %92, ptr %97, align 8, !tbaa !14
  br label %98

98:                                               ; preds = %69, %44
  br label %99

99:                                               ; preds = %98, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { mustprogress 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 #3 = { nounwind }
attributes #4 = { builtin allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Node", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, 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"

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11insertAtEndiPP4Node(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #2
  store i32 %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %1, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = icmp eq ptr %6, %4
  br i1 %7, label %8, label %12

8:                                                ; preds = %2
  store ptr %3, ptr %5, align 8, !tbaa !12
  %9 = load ptr, ptr %1, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %3, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %3, ptr %11, align 8, !tbaa !12
  br label %30

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = icmp eq ptr %14, %6
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %6, ptr %16, align 8, !tbaa !12
  br i1 %15, label %17, label %22

17:                                               ; preds = %12
  %18 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %6, ptr %18, align 8, !tbaa !13
  store ptr %3, ptr %13, align 8, !tbaa !12
  %19 = load ptr, ptr %1, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  br label %30

22:                                               ; preds = %12
  %23 = getelementptr inbounds i8, ptr %6, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %24, ptr %25, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %24, i64 8
  store ptr %3, ptr %26, align 8, !tbaa !12
  %27 = load ptr, ptr %1, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %17, %22, %8
  %.sink29 = phi ptr [ %21, %17 ], [ %29, %22 ], [ %3, %8 ]
  %31 = getelementptr inbounds i8, ptr %.sink29, i64 16
  store ptr %3, ptr %31, align 8, !tbaa !13
  ret void
}

attributes #0 = { nobuiltin allocsize(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 = { mustprogress 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 = { builtin allocsize(0) }

!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 0}
!6 = !{!"_ZTS4Node", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 16}


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