; LLVM IR from Aeternum-Veritas/Merry :: merry (merry_task_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.MerryTaskQueue = type { i64, i64, ptr, ptr }
%struct.MerryTaskNode = type { %struct.MerryTask, ptr }
%struct.MerryTask = type { ptr, i64, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [48 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @merry_task_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 %21

18:                                               ; preds = %15
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str) #4
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %128

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

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

35:                                               ; preds = %22
  store i8 0, ptr %6, align 1, !tbaa !11
  br label %74

36:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.MerryTaskQueue, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  store ptr %39, 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 %40

40:                                               ; preds = %58, %36
  %41 = load i64, ptr %8, align 8, !tbaa !5
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 6, ptr %5, align 4
  br label %61

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

53:                                               ; preds = %45
  store i8 0, ptr %6, align 1, !tbaa !11
  store i32 6, ptr %5, align 4
  br label %61

54:                                               ; preds = %45
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.MerryTaskNode, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  store ptr %57, ptr %7, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %54
  %59 = load i64, ptr %8, align 8, !tbaa !5
  %60 = add i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !5
  br label %40, !llvm.loop !19

61:                                               ; preds = %53, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.MerryTaskQueue, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  %66 = load ptr, ptr %7, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.MerryTaskNode, ptr %66, i32 0, i32 1
  store ptr %65, ptr %67, align 8, !tbaa !16
  %68 = load ptr, ptr %4, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.MerryTaskQueue, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = load ptr, ptr %4, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.MerryTaskQueue, ptr %71, i32 0, i32 3
  store ptr %70, ptr %72, 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 %73

73:                                               ; preds = %62
  br label %74

74:                                               ; preds = %73, %35
  %75 = load i8, ptr %6, align 1, !tbaa !11
  %76 = zext i8 %75 to i32
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %78, label %125

78:                                               ; preds = %74
  %79 = load ptr, ptr @stderr, align 8, !tbaa !9
  %80 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %79, ptr noundef @.str.1) #4
  br label %81

81:                                               ; preds = %78
  %82 = load ptr, ptr %4, align 8, !tbaa !9
  %83 = icmp eq ptr %82, null
  br i1 %83, label %84, label %85

84:                                               ; preds = %81
  br label %124

85:                                               ; preds = %81
  %86 = load ptr, ptr %4, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.MerryTaskQueue, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !15
  %89 = icmp eq ptr %88, null
  br i1 %89, label %90, label %91

90:                                               ; preds = %85
  br label %124

91:                                               ; preds = %85
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %92 = load ptr, ptr %4, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.MerryTaskQueue, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8, !tbaa !15
  store ptr %94, 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 %95

95:                                               ; preds = %112, %91
  %96 = load i64, ptr %11, align 8, !tbaa !5
  %97 = load ptr, ptr %4, align 8, !tbaa !9
  %98 = getelementptr inbounds %struct.MerryTaskQueue, ptr %97, i32 0, i32 0
  %99 = load i64, ptr %98, align 8, !tbaa !12
  %100 = icmp ult i64 %96, %99
  br i1 %100, label %102, label %101

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

102:                                              ; preds = %95
  %103 = load ptr, ptr %9, align 8, !tbaa !9
  %104 = getelementptr inbounds %struct.MerryTaskNode, ptr %103, i32 0, i32 1
  %105 = load ptr, ptr %104, align 8, !tbaa !16
  store ptr %105, ptr %10, align 8, !tbaa !9
  %106 = load ptr, ptr %9, align 8, !tbaa !9
  %107 = icmp ne ptr %106, null
  br i1 %107, label %108, label %110

108:                                              ; preds = %102
  %109 = load ptr, ptr %9, align 8, !tbaa !9
  call void @free(ptr noundef %109) #4
  br label %110

110:                                              ; preds = %108, %102
  %111 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %111, ptr %9, align 8, !tbaa !9
  br label %112

112:                                              ; preds = %110
  %113 = load i64, ptr %11, align 8, !tbaa !5
  %114 = add i64 %113, 1
  store i64 %114, ptr %11, align 8, !tbaa !5
  br label %95, !llvm.loop !22

115:                                              ; preds = %101
  %116 = load ptr, ptr %4, align 8, !tbaa !9
  %117 = getelementptr inbounds %struct.MerryTaskQueue, ptr %116, i32 0, i32 2
  store ptr null, ptr %117, align 8, !tbaa !15
  %118 = load ptr, ptr %4, align 8, !tbaa !9
  %119 = getelementptr inbounds %struct.MerryTaskQueue, ptr %118, i32 0, i32 3
  store ptr null, ptr %119, align 8, !tbaa !21
  %120 = load ptr, ptr %4, align 8, !tbaa !9
  %121 = getelementptr inbounds %struct.MerryTaskQueue, ptr %120, i32 0, i32 0
  store i64 0, ptr %121, align 8, !tbaa !12
  %122 = load ptr, ptr %4, align 8, !tbaa !9
  call void @free(ptr noundef %122) #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 %123

123:                                              ; preds = %115
  br label %124

124:                                              ; preds = %123, %90, %84
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %127

125:                                              ; preds = %74
  %126 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %126, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %127

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

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

; 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; 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 = !{!"MerryTaskQueue", !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 24}
!17 = !{!"MerryTaskNode", !18, i64 0, !10, i64 24}
!18 = !{!"MerryTask", !10, i64 0, !6, i64 8, !10, i64 16}
!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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [48 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noalias noundef ptr @merry_task_queue_init(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %7

4:                                                ; preds = %1
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str) #4
  br label %21

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

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

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

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

._crit_edge:                                      ; preds = %12, %.lr.ph, %.preheader
  %.036.lcssa = phi ptr [ %9, %.preheader ], [ %.03642, %.lr.ph ], [ %14, %12 ]
  %17 = getelementptr inbounds i8, ptr %.036.lcssa, i64 24
  store ptr %9, ptr %17, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %9, ptr %18, align 8, !tbaa !19
  br label %21

.critedge:                                        ; preds = %7
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.1) #4
  br label %21

21:                                               ; preds = %._crit_edge, %.critedge, %4
  %.1 = phi ptr [ null, %4 ], [ null, %.critedge ], [ %2, %._crit_edge ]
  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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 = { nofree 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 #3 = { nounwind allocsize(0) }
attributes #4 = { cold 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"MerryTaskQueue", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 24}
!17 = !{!"MerryTaskNode", !18, i64 0, !6, i64 24}
!18 = !{!"MerryTask", !6, i64 0, !11, i64 8, !6, i64 16}
!19 = !{!10, !6, i64 24}


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