; LLVM IR from Dev-XYS/Algorithms :: Skip-List.ll (Z6insertii)

; 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, i32, ptr, ptr }

@head = external dso_local global [20 x ptr], align 16

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertii(i32 noundef %0, i32 noundef %1) #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %16, %2
  %13 = call i32 @rand() #5
  %14 = and i32 %13, 1
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %12
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !9

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [20 x ptr], ptr @head, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  store ptr %23, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [20 x ptr], ptr @head, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr null, ptr %8, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %79, %19
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = icmp sge i32 %29, 0
  br i1 %30, label %31, label %82

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %43, %31
  %33 = load ptr, ptr %7, align 8, !tbaa !11
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %41

35:                                               ; preds = %32
  %36 = load ptr, ptr %7, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.node, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br label %41

41:                                               ; preds = %35, %32
  %42 = phi i1 [ false, %32 ], [ %40, %35 ]
  br i1 %42, label %43, label %48

43:                                               ; preds = %41
  %44 = load ptr, ptr %7, align 8, !tbaa !11
  store ptr %44, ptr %6, align 8, !tbaa !11
  %45 = load ptr, ptr %7, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  store ptr %47, ptr %7, align 8, !tbaa !11
  br label %32, !llvm.loop !16

48:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %49 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(24) %49)
          to label %50 unwind label %73

50:                                               ; preds = %48
  store ptr %49, ptr %9, align 8, !tbaa !11
  %51 = load ptr, ptr %7, align 8, !tbaa !11
  %52 = load ptr, ptr %9, align 8, !tbaa !11
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !15
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 0
  store i32 %54, ptr %56, align 8, !tbaa !13
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !11
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 1
  store i32 %57, ptr %59, align 4, !tbaa !17
  %60 = load ptr, ptr %9, align 8, !tbaa !11
  %61 = load ptr, ptr %6, align 8, !tbaa !11
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 2
  store ptr %60, ptr %62, align 8, !tbaa !15
  %63 = load ptr, ptr %6, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.node, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !18
  store ptr %65, ptr %6, align 8, !tbaa !11
  %66 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %66, ptr %7, align 8, !tbaa !11
  %67 = load ptr, ptr %8, align 8, !tbaa !11
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %77

69:                                               ; preds = %50
  %70 = load ptr, ptr %9, align 8, !tbaa !11
  %71 = load ptr, ptr %8, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.node, ptr %71, i32 0, i32 3
  store ptr %70, ptr %72, align 8, !tbaa !18
  br label %77

73:                                               ; preds = %48
  %74 = landingpad { ptr, i32 }
          cleanup
  %75 = extractvalue { ptr, i32 } %74, 0
  store ptr %75, ptr %10, align 8
  %76 = extractvalue { ptr, i32 } %74, 1
  store i32 %76, ptr %11, align 4
  call void @_ZdlPvm(ptr noundef %49, i64 noundef 24) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %83

77:                                               ; preds = %69, %50
  %78 = load ptr, ptr %9, align 8, !tbaa !11
  store ptr %78, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %79

79:                                               ; preds = %77
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr %5, align 4, !tbaa !5
  br label %28, !llvm.loop !19

82:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void

83:                                               ; preds = %73
  %84 = load ptr, ptr %10, align 8
  %85 = load i32, ptr %11, align 4
  %86 = insertvalue { ptr, i32 } poison, ptr %84, 0
  %87 = insertvalue { ptr, i32 } %86, i32 %85, 1
  resume { ptr, i32 } %87
}

; Function Attrs: nounwind
declare i32 @rand() #4

declare void @_ZN4nodeC1Ev(ptr)

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 = { nobuiltin nounwind "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(argmem: readwrite) }
attributes #3 = { 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 #4 = { nounwind "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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !12, i64 8, !12, i64 16}
!15 = !{!14, !12, i64 8}
!16 = distinct !{!16, !10}
!17 = !{!14, !6, i64 4}
!18 = !{!14, !12, i64 16}
!19 = distinct !{!19, !10}


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

@head = external dso_local local_unnamed_addr global [20 x ptr], align 16

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  br label %3

3:                                                ; preds = %3, %2
  %.0 = phi i32 [ 0, %2 ], [ %7, %3 ]
  %4 = tail call i32 @rand() #4
  %5 = and i32 %4, 1
  %6 = icmp eq i32 %5, 0
  %7 = add nuw nsw i32 %.0, 1
  br i1 %6, label %3, label %.preheader.preheader, !llvm.loop !5

.preheader.preheader:                             ; preds = %3
  %8 = zext nneg i32 %.0 to i64
  %9 = getelementptr inbounds [20 x ptr], ptr @head, i64 0, i64 %8
  %10 = load ptr, ptr %9, align 8, !tbaa !7
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %28
  %.140 = phi i32 [ %29, %28 ], [ %.0, %.preheader.preheader ]
  %.02539 = phi ptr [ %23, %28 ], [ %10, %.preheader.preheader ]
  %.02938 = phi ptr [ %17, %28 ], [ null, %.preheader.preheader ]
  %.not31 = icmp eq ptr %.02539, null
  br i1 %.not31, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %11 = load i32, ptr %.02539, align 8, !tbaa !11
  %12 = icmp slt i32 %11, %0
  br i1 %12, label %.lr.ph45, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph45
  %13 = load i32, ptr %16, align 8, !tbaa !11
  %14 = icmp slt i32 %13, %0
  br i1 %14, label %.lr.ph45, label %.critedge, !llvm.loop !14

.lr.ph45:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.1283244 = phi ptr [ %16, %.lr.ph ], [ %.02539, %.lr.ph.preheader ]
  %15 = getelementptr inbounds i8, ptr %.1283244, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph45, %.lr.ph, %.lr.ph.preheader, %.preheader
  %.128.lcssa = phi ptr [ null, %.preheader ], [ %.02539, %.lr.ph.preheader ], [ %16, %.lr.ph ], [ null, %.lr.ph45 ]
  %.126.lcssa = phi ptr [ null, %.preheader ], [ %.02539, %.lr.ph.preheader ], [ %.1283244, %.lr.ph ], [ %.1283244, %.lr.ph45 ]
  %17 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #5
  invoke void @_ZN4nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(24) %17)
          to label %18 unwind label %26

18:                                               ; preds = %.critedge
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %.128.lcssa, ptr %19, align 8, !tbaa !15
  store i32 %0, ptr %17, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %17, i64 4
  store i32 %1, ptr %20, align 4, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %.126.lcssa, i64 8
  store ptr %17, ptr %21, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %.126.lcssa, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %.not30 = icmp eq ptr %.02938, null
  br i1 %.not30, label %28, label %24

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %.02938, i64 16
  store ptr %17, ptr %25, align 8, !tbaa !17
  br label %28

26:                                               ; preds = %.critedge
  %27 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %17, i64 noundef 24) #6
  resume { ptr, i32 } %27

28:                                               ; preds = %24, %18
  %29 = add nsw i32 %.140, -1
  %30 = icmp sgt i32 %.140, 0
  br i1 %30, label %.preheader, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %28
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

declare void @_ZN4nodeC1Ev(ptr) local_unnamed_addr

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 = { nobuiltin nounwind "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 "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 }
attributes #5 = { builtin allocsize(0) }
attributes #6 = { builtin 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS4node", !13, i64 0, !13, i64 4, !8, i64 8, !8, i64 16}
!13 = !{!"int", !9, i64 0}
!14 = distinct !{!14, !6}
!15 = !{!12, !8, i64 8}
!16 = !{!12, !13, i64 4}
!17 = !{!12, !8, i64 16}
!18 = distinct !{!18, !6}


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