; LLVM IR from Aeternum-Veritas/Merry :: subsyshelpers/src (queue)

; 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 { i64, i64, ptr, ptr }
%struct.QueueNode = type { %struct.QueueItem, ptr }
%struct.QueueItem = type { i64, [4 x i64] }

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

12:                                               ; preds = %1
  %13 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %13, ptr %4, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %12
  br label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %124

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  store i8 1, ptr %6, align 1, !tbaa !11
  br label %20

20:                                               ; preds = %19
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.Queue, ptr %22, i32 0, i32 0
  store i64 %21, ptr %23, align 8, !tbaa !12
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Queue, ptr %24, i32 0, i32 1
  store i64 0, ptr %25, align 8, !tbaa !14
  %26 = call noalias ptr @malloc(i64 noundef 48) #5
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.Queue, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.Queue, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %20
  store i8 0, ptr %6, align 1, !tbaa !11
  br label %72

34:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.Queue, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  store ptr %37, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %56, %34
  %39 = load i64, ptr %8, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 6, ptr %5, align 4
  br label %59

43:                                               ; preds = %38
  %44 = call noalias ptr @malloc(i64 noundef 48) #5
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.QueueNode, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.QueueNode, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  store i8 0, ptr %6, align 1, !tbaa !11
  store i32 6, ptr %5, align 4
  br label %59

52:                                               ; preds = %43
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.QueueNode, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  store ptr %55, ptr %7, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %52
  %57 = load i64, ptr %8, align 8, !tbaa !5
  %58 = add i64 %57, 1
  store i64 %58, ptr %8, align 8, !tbaa !5
  br label %38, !llvm.loop !19

59:                                               ; preds = %51, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %4, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.Queue, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.QueueNode, ptr %64, i32 0, i32 1
  store ptr %63, ptr %65, align 8, !tbaa !16
  %66 = load ptr, ptr %4, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.Queue, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.Queue, ptr %69, i32 0, i32 3
  store ptr %68, ptr %70, align 8, !tbaa !21
  store i8 1, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %71

71:                                               ; preds = %60
  br label %72

72:                                               ; preds = %71, %33
  %73 = load i8, ptr %6, align 1, !tbaa !11
  %74 = zext i8 %73 to i32
  %75 = icmp eq i32 %74, 0
  br i1 %75, label %76, label %121

76:                                               ; preds = %72
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %4, align 8, !tbaa !9
  %79 = icmp eq ptr %78, null
  br i1 %79, label %80, label %81

80:                                               ; preds = %77
  br label %120

81:                                               ; preds = %77
  %82 = load ptr, ptr %4, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.Queue, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !15
  %85 = icmp eq ptr %84, null
  br i1 %85, label %86, label %87

86:                                               ; preds = %81
  br label %120

87:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %88 = load ptr, ptr %4, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.Queue, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !15
  store ptr %90, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %91

91:                                               ; preds = %108, %87
  %92 = load i64, ptr %11, align 8, !tbaa !5
  %93 = load ptr, ptr %4, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.Queue, ptr %93, i32 0, i32 0
  %95 = load i64, ptr %94, align 8, !tbaa !12
  %96 = icmp ult i64 %92, %95
  br i1 %96, label %98, label %97

97:                                               ; preds = %91
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %111

98:                                               ; preds = %91
  %99 = load ptr, ptr %9, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.QueueNode, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !16
  store ptr %101, ptr %10, align 8, !tbaa !9
  %102 = load ptr, ptr %9, align 8, !tbaa !9
  %103 = icmp ne ptr %102, null
  br i1 %103, label %104, label %106

104:                                              ; preds = %98
  %105 = load ptr, ptr %9, align 8, !tbaa !9
  call void @free(ptr noundef %105) #4
  br label %106

106:                                              ; preds = %104, %98
  %107 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %107, ptr %9, align 8, !tbaa !9
  br label %108

108:                                              ; preds = %106
  %109 = load i64, ptr %11, align 8, !tbaa !5
  %110 = add i64 %109, 1
  store i64 %110, ptr %11, align 8, !tbaa !5
  br label %91, !llvm.loop !22

111:                                              ; preds = %97
  %112 = load ptr, ptr %4, align 8, !tbaa !9
  %113 = getelementptr inbounds %struct.Queue, ptr %112, i32 0, i32 2
  store ptr null, ptr %113, align 8, !tbaa !15
  %114 = load ptr, ptr %4, align 8, !tbaa !9
  %115 = getelementptr inbounds %struct.Queue, ptr %114, i32 0, i32 3
  store ptr null, ptr %115, align 8, !tbaa !21
  %116 = load ptr, ptr %4, align 8, !tbaa !9
  %117 = getelementptr inbounds %struct.Queue, ptr %116, i32 0, i32 0
  store i64 0, ptr %117, align 8, !tbaa !12
  %118 = load ptr, ptr %4, align 8, !tbaa !9
  call void @free(ptr noundef %118) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %119

119:                                              ; preds = %111
  br label %120

120:                                              ; preds = %119, %86, %80
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %123

121:                                              ; preds = %72
  %122 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %122, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %123

123:                                              ; preds = %121, %120
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  br label %124

124:                                              ; preds = %123, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %125 = load ptr, ptr %2, align 8
  ret ptr %125
}

; 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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 "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 = { 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 = !{!"long", !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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"Queue", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !10, i64 16}
!16 = !{!17, !10, i64 40}
!17 = !{!"QueueNode", !18, i64 0, !10, i64 40}
!18 = !{!"QueueItem", !6, i64 0, !7, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!13, !10, i64 24}
!22 = distinct !{!22, !20}


; 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: nofree nounwind memory(write, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @queue_init(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #2
  %3 = icmp eq ptr %2, null
  br i1 %3, label %.critedge, label %4

4:                                                ; preds = %1
  store i64 %0, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 0, ptr %5, align 8, !tbaa !11
  %6 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #2
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %6, ptr %7, align 8, !tbaa !12
  %8 = icmp eq ptr %6, null
  br i1 %8, label %.critedge, label %.preheader

.preheader:                                       ; preds = %4
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

9:                                                ; preds = %.lr.ph
  %10 = add nuw i64 %.03543, 1
  %exitcond.not = icmp eq i64 %10, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader, %9
  %.03543 = phi i64 [ %10, %9 ], [ 0, %.preheader ]
  %.03642 = phi ptr [ %11, %9 ], [ %6, %.preheader ]
  %11 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #2
  %12 = getelementptr inbounds i8, ptr %.03642, i64 40
  store ptr %11, ptr %12, align 8, !tbaa !15
  %13 = icmp eq ptr %11, null
  br i1 %13, label %._crit_edge, label %9

._crit_edge:                                      ; preds = %9, %.lr.ph, %.preheader
  %.036.lcssa = phi ptr [ %6, %.preheader ], [ %.03642, %.lr.ph ], [ %11, %9 ]
  %14 = getelementptr inbounds i8, ptr %.036.lcssa, i64 40
  store ptr %6, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %6, ptr %15, align 8, !tbaa !18
  br label %.critedge

.critedge:                                        ; preds = %4, %._crit_edge, %1
  %.1 = phi ptr [ null, %1 ], [ %2, %._crit_edge ], [ null, %4 ]
  ret ptr %.1
}

; 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 memory(write, inaccessiblemem: readwrite) 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 0}
!6 = !{!"Queue", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long", !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, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 40}
!16 = !{!"QueueNode", !17, i64 0, !10, i64 40}
!17 = !{!"QueueItem", !7, i64 0, !8, i64 8}
!18 = !{!6, !10, i64 24}


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