; LLVM IR from ryanlayer/giggle :: src (pq)

; 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.priority = type { i32, [50 x i8] }
%struct.pri_queue_t = type { ptr, i32, i32 }
%struct.q_elem_t = type { ptr, %struct.priority }

@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1

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

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr 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: nounwind uwtable
define dso_local void @priq_push(ptr noundef %0, ptr noundef %1, ptr noundef byval(%struct.priority) align 8 %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.pri_queue_t, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.pri_queue_t, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = icmp sge i32 %11, %14
  br i1 %15, label %16, label %36

16:                                               ; preds = %3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.pri_queue_t, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = mul nsw i32 %19, 2
  store i32 %20, ptr %18, align 4, !tbaa !12
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.pri_queue_t, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.pri_queue_t, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = sext i32 %26 to i64
  %28 = mul i64 64, %27
  %29 = call ptr @realloc(ptr noundef %23, i64 noundef %28) #6
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.pri_queue_t, ptr %30, i32 0, i32 0
  store ptr %29, ptr %31, align 8, !tbaa !13
  store ptr %29, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %16
  call void (i32, ptr, ...) @err(i32 noundef 71, ptr noundef @.str.2) #7
  unreachable

35:                                               ; preds = %16
  br label %40

36:                                               ; preds = %3
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.pri_queue_t, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  store ptr %39, ptr %6, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %36, %35
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.pri_queue_t, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 8, !tbaa !9
  store i32 %43, ptr %7, align 4, !tbaa !14
  br label %45

45:                                               ; preds = %59, %40
  %46 = load i32, ptr %7, align 4, !tbaa !14
  %47 = sdiv i32 %46, 2
  store i32 %47, ptr %8, align 4, !tbaa !14
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %57

49:                                               ; preds = %45
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !14
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.q_elem_t, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.q_elem_t, ptr %53, i32 0, i32 1
  %55 = call i32 @pricmp(ptr noundef byval(%struct.priority) align 8 %2, ptr noundef byval(%struct.priority) align 8 %54)
  %56 = icmp slt i32 %55, 0
  br label %57

57:                                               ; preds = %49, %45
  %58 = phi i1 [ false, %45 ], [ %56, %49 ]
  br i1 %58, label %59, label %69

59:                                               ; preds = %57
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !14
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.q_elem_t, ptr %60, i64 %62
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load i32, ptr %8, align 4, !tbaa !14
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.q_elem_t, ptr %64, i64 %66
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %63, ptr align 8 %67, i64 64, i1 false), !tbaa.struct !15
  %68 = load i32, ptr %8, align 4, !tbaa !14
  store i32 %68, ptr %7, align 4, !tbaa !14
  br label %45, !llvm.loop !17

69:                                               ; preds = %57
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !14
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct.q_elem_t, ptr %71, i64 %73
  %75 = getelementptr inbounds %struct.q_elem_t, ptr %74, i32 0, i32 0
  store ptr %70, ptr %75, align 8, !tbaa !19
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !14
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds %struct.q_elem_t, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct.q_elem_t, ptr %79, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %80, ptr align 8 %2, i64 56, i1 false), !tbaa.struct !22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  ret void
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @pricmp(ptr noundef byval(%struct.priority) align 8, ptr noundef byval(%struct.priority) align 8) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 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 allocsize(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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }
attributes #7 = { noreturn }

!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, !11, i64 8}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!10, !6, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{i64 0, i64 8, !5, i64 8, i64 4, !14, i64 12, i64 50, !16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !6, i64 0}
!20 = !{!"", !6, i64 0, !21, i64 8}
!21 = !{!"", !11, i64 0, !7, i64 4}
!22 = !{i64 0, i64 4, !14, i64 4, i64 50, !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"

%struct.priority = type { i32, [50 x i8] }
%struct.q_elem_t = type { ptr, %struct.priority }

@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @priq_push(ptr nocapture noundef %0, ptr noundef %1, ptr noundef byval(%struct.priority) align 8 %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %.not = icmp slt i32 %5, %7
  br i1 %.not, label %16, label %8

8:                                                ; preds = %3
  %9 = shl nsw i32 %7, 1
  store i32 %9, ptr %6, align 4, !tbaa !11
  %10 = load ptr, ptr %0, align 8, !tbaa !12
  %11 = sext i32 %9 to i64
  %12 = shl nsw i64 %11, 6
  %13 = tail call ptr @realloc(ptr noundef %10, i64 noundef %12) #4
  store ptr %13, ptr %0, align 8, !tbaa !12
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %._crit_edge

._crit_edge:                                      ; preds = %8
  %.pre = load i32, ptr %4, align 8, !tbaa !5
  br label %18

15:                                               ; preds = %8
  tail call void (i32, ptr, ...) @err(i32 noundef 71, ptr noundef nonnull @.str.2) #5
  unreachable

16:                                               ; preds = %3
  %17 = load ptr, ptr %0, align 8, !tbaa !12
  br label %18

18:                                               ; preds = %._crit_edge, %16
  %19 = phi i32 [ %.pre, %._crit_edge ], [ %5, %16 ]
  %.0 = phi ptr [ %13, %._crit_edge ], [ %17, %16 ]
  %20 = add i32 %19, 1
  store i32 %20, ptr %4, align 8, !tbaa !5
  %.not2527 = icmp ult i32 %20, 3
  br i1 %.not2527, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %18, %27
  %.02128 = phi i32 [ %21, %27 ], [ %19, %18 ]
  %21 = sdiv i32 %.02128, 2
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.q_elem_t, ptr %.0, i64 %22
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = tail call i32 @pricmp(ptr noundef nonnull byval(%struct.priority) align 8 %2, ptr noundef nonnull byval(%struct.priority) align 8 %24)
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %.critedge

27:                                               ; preds = %.lr.ph
  %28 = sext i32 %.02128 to i64
  %29 = getelementptr inbounds %struct.q_elem_t, ptr %.0, i64 %28
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %29, ptr noundef nonnull align 8 dereferenceable(64) %23, i64 64, i1 false), !tbaa.struct !13
  %.021.off = add nsw i32 %21, 1
  %.not25 = icmp ult i32 %.021.off, 3
  br i1 %.not25, label %.critedge, label %.lr.ph, !llvm.loop !17

.critedge:                                        ; preds = %.lr.ph, %27, %18
  %.021.lcssa = phi i32 [ %19, %18 ], [ %21, %27 ], [ %.02128, %.lr.ph ]
  %30 = sext i32 %.021.lcssa to i64
  %31 = getelementptr inbounds %struct.q_elem_t, ptr %.0, i64 %30
  store ptr %1, ptr %31, align 8, !tbaa !19
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %32, ptr noundef nonnull align 8 dereferenceable(56) %2, i64 56, i1 false), !tbaa.struct !22
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @pricmp(ptr noundef byval(%struct.priority) align 8, ptr noundef byval(%struct.priority) align 8) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { noreturn "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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(1) }
attributes #5 = { noreturn 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 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!13 = !{i64 0, i64 8, !14, i64 8, i64 4, !15, i64 12, i64 50, !16}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !10, i64 0}
!16 = !{!8, !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !7, i64 0}
!20 = !{!"", !7, i64 0, !21, i64 8}
!21 = !{!"", !10, i64 0, !8, i64 4}
!22 = !{i64 0, i64 4, !15, i64 4, i64 50, !16}


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