; LLVM IR from Aeternum-Veritas/Merry :: merry (merry_request_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.MerryRequestQueue = type { i64, i64, ptr, ptr }
%struct.MerryRequestNode = type { %struct.MerryOSRequest, ptr }
%struct.MerryOSRequest = type { i64, ptr, i64, i8, i8, i64 }

@stdout = external global ptr, align 8
@.str = external hidden unnamed_addr constant [42 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @merry_request_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
  %12 = load ptr, ptr @stdout, align 8, !tbaa !9
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str, ptr noundef null) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  br label %14

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

16:                                               ; preds = %14
  br label %17

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

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

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

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

37:                                               ; preds = %24
  store i8 0, ptr %6, align 1, !tbaa !11
  br label %76

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

42:                                               ; preds = %60, %38
  %43 = load i64, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %3, align 8, !tbaa !5
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %47, label %46

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

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

55:                                               ; preds = %47
  store i8 0, ptr %6, align 1, !tbaa !11
  store i32 6, ptr %5, align 4
  br label %63

56:                                               ; preds = %47
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.MerryRequestNode, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  store ptr %59, ptr %7, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %56
  %61 = load i64, ptr %8, align 8, !tbaa !5
  %62 = add i64 %61, 1
  store i64 %62, ptr %8, align 8, !tbaa !5
  br label %42, !llvm.loop !19

63:                                               ; preds = %55, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %64

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

75:                                               ; preds = %64
  br label %76

76:                                               ; preds = %75, %37
  %77 = load i8, ptr %6, align 1, !tbaa !11
  %78 = zext i8 %77 to i32
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %80, label %127

80:                                               ; preds = %76
  %81 = load ptr, ptr @stderr, align 8, !tbaa !9
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str.2) #4
  br label %83

83:                                               ; preds = %80
  %84 = load ptr, ptr %4, align 8, !tbaa !9
  %85 = icmp eq ptr %84, null
  br i1 %85, label %86, label %87

86:                                               ; preds = %83
  br label %126

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

92:                                               ; preds = %87
  br label %126

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

97:                                               ; preds = %114, %93
  %98 = load i64, ptr %11, align 8, !tbaa !5
  %99 = load ptr, ptr %4, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.MerryRequestQueue, ptr %99, i32 0, i32 0
  %101 = load i64, ptr %100, align 8, !tbaa !12
  %102 = icmp ult i64 %98, %101
  br i1 %102, label %104, label %103

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

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

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

112:                                              ; preds = %110, %104
  %113 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %113, ptr %9, align 8, !tbaa !9
  br label %114

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

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

125:                                              ; preds = %117
  br label %126

126:                                              ; preds = %125, %92, %86
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %129

127:                                              ; preds = %76
  %128 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %128, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %129

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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #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 = { 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 = { 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 #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 = !{!"MerryRequestQueue", !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 = !{!"MerryRequestNode", !18, i64 0, !10, i64 40}
!18 = !{!"MerryOSRequest", !6, i64 0, !10, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !6, i64 32}
!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"

@stdout = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [42 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noalias noundef ptr @merry_request_queue_init(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @stdout, align 8, !tbaa !5
  %3 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str, ptr noundef null) #3
  %4 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %9

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

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

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

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

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

._crit_edge:                                      ; preds = %14, %.lr.ph, %.preheader
  %.036.lcssa = phi ptr [ %11, %.preheader ], [ %.03642, %.lr.ph ], [ %16, %14 ]
  %19 = getelementptr inbounds i8, ptr %.036.lcssa, i64 40
  store ptr %11, ptr %19, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %11, ptr %20, align 8, !tbaa !19
  br label %23

.critedge:                                        ; preds = %9
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.2) #5
  br label %23

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #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 #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 = { 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 #2 = { 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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = !{!"MerryRequestQueue", !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 40}
!17 = !{!"MerryRequestNode", !18, i64 0, !6, i64 40}
!18 = !{!"MerryOSRequest", !11, i64 0, !6, i64 8, !11, i64 16, !7, i64 24, !7, i64 25, !11, i64 32}
!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