; LLVM IR from HarshCasper/NeoAlgo :: C/operating_system (priority_sjf)

; 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.queue = type { i32, i32, i32, ptr }

@q = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @push(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = call noalias ptr @malloc(i64 noundef 24) #4
  store ptr %10, ptr %7, align 8, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load ptr, ptr %7, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.queue, ptr %12, i32 0, i32 1
  store i32 %11, ptr %13, align 4, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.queue, ptr %15, i32 0, i32 2
  store i32 %14, ptr %16, align 8, !tbaa !13
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.queue, ptr %18, i32 0, i32 0
  store i32 %17, ptr %19, align 8, !tbaa !14
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.queue, ptr %20, i32 0, i32 3
  store ptr null, ptr %21, align 8, !tbaa !15
  %22 = load ptr, ptr @q, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %26

24:                                               ; preds = %3
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %25, ptr @q, align 8, !tbaa !9
  br label %89

26:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %27 = load ptr, ptr @q, align 8, !tbaa !9
  store ptr %27, ptr %8, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %63, %26
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %37

31:                                               ; preds = %28
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.queue, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br label %37

37:                                               ; preds = %31, %28
  %38 = phi i1 [ false, %28 ], [ %36, %31 ]
  br i1 %38, label %39, label %64

39:                                               ; preds = %37
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.queue, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %50

45:                                               ; preds = %39
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %46, ptr %9, align 8, !tbaa !9
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.queue, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  store ptr %49, ptr %8, align 8, !tbaa !9
  br label %63

50:                                               ; preds = %39
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.queue, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !14
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = icmp sgt i32 %53, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %50
  br label %64

57:                                               ; preds = %50
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %58, ptr %9, align 8, !tbaa !9
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.queue, ptr %59, i32 0, i32 3
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  store ptr %61, ptr %8, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %57
  br label %63

63:                                               ; preds = %62, %45
  br label %28, !llvm.loop !16

64:                                               ; preds = %56, %37
  %65 = load ptr, ptr %8, align 8, !tbaa !9
  %66 = load ptr, ptr @q, align 8, !tbaa !9
  %67 = icmp eq ptr %65, %66
  br i1 %67, label %68, label %73

68:                                               ; preds = %64
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.queue, ptr %70, i32 0, i32 3
  store ptr %69, ptr %71, align 8, !tbaa !15
  %72 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %72, ptr @q, align 8, !tbaa !9
  br label %88

73:                                               ; preds = %64
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = icmp eq ptr %74, null
  br i1 %75, label %76, label %80

76:                                               ; preds = %73
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = load ptr, ptr %9, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.queue, ptr %78, i32 0, i32 3
  store ptr %77, ptr %79, align 8, !tbaa !15
  br label %87

80:                                               ; preds = %73
  %81 = load ptr, ptr %8, align 8, !tbaa !9
  %82 = load ptr, ptr %7, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.queue, ptr %82, i32 0, i32 3
  store ptr %81, ptr %83, align 8, !tbaa !15
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  %85 = load ptr, ptr %9, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.queue, ptr %85, i32 0, i32 3
  store ptr %84, ptr %86, align 8, !tbaa !15
  br label %87

87:                                               ; preds = %80, %76
  br label %88

88:                                               ; preds = %87, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %89

89:                                               ; preds = %88, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind 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 #3 = { nounwind }
attributes #4 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"queue", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

@q = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local void @push(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #2
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %1, ptr %6, align 8, !tbaa !11
  store i32 %2, ptr %4, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr null, ptr %7, align 8, !tbaa !13
  %8 = load ptr, ptr @q, align 8, !tbaa !14
  %9 = icmp eq ptr %8, null
  br i1 %9, label %23, label %.preheader.preheader

.preheader.preheader:                             ; preds = %3
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %.not3448 = icmp sgt i32 %11, %1
  br i1 %.not3448, label %.critedge, label %.lr.ph

.preheader:                                       ; preds = %19
  %12 = getelementptr inbounds i8, ptr %.130, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %.not34 = icmp sgt i32 %13, %1
  br i1 %.not34, label %.critedge, label %.lr.ph, !llvm.loop !15

.lr.ph:                                           ; preds = %.preheader.preheader, %.preheader
  %14 = phi i32 [ %13, %.preheader ], [ %11, %.preheader.preheader ]
  %.0293950 = phi ptr [ %.130, %.preheader ], [ %8, %.preheader.preheader ]
  %.04049 = phi ptr [ %.0293950, %.preheader ], [ undef, %.preheader.preheader ]
  %15 = icmp slt i32 %14, %1
  br i1 %15, label %19, label %16

16:                                               ; preds = %.lr.ph
  %17 = load i32, ptr %.0293950, align 8, !tbaa !12
  %18 = icmp sgt i32 %17, %2
  br i1 %18, label %.critedge, label %19

19:                                               ; preds = %16, %.lr.ph
  %.130.in = getelementptr inbounds i8, ptr %.0293950, i64 16
  %.130 = load ptr, ptr %.130.in, align 8, !tbaa !13
  %.not = icmp eq ptr %.130, null
  br i1 %.not, label %.thread, label %.preheader, !llvm.loop !15

.critedge:                                        ; preds = %.preheader, %16, %.preheader.preheader
  %.040.lcssa = phi ptr [ undef, %.preheader.preheader ], [ %.0293950, %.preheader ], [ %.04049, %16 ]
  %.02939.lcssa = phi ptr [ %8, %.preheader.preheader ], [ %.130, %.preheader ], [ %.0293950, %16 ]
  %20 = icmp eq ptr %.02939.lcssa, %8
  store ptr %.02939.lcssa, ptr %7, align 8, !tbaa !13
  br i1 %20, label %23, label %21

.thread:                                          ; preds = %19
  %.130.in.le = getelementptr inbounds i8, ptr %.0293950, i64 16
  br label %23

21:                                               ; preds = %.critedge
  %22 = getelementptr inbounds i8, ptr %.040.lcssa, i64 16
  br label %23

23:                                               ; preds = %.critedge, %3, %21, %.thread
  %q.sink = phi ptr [ %22, %21 ], [ %.130.in.le, %.thread ], [ @q, %3 ], [ @q, %.critedge ]
  store ptr %4, ptr %q.sink, align 8, !tbaa !14
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #2 = { nounwind 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 4}
!6 = !{!"queue", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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