; LLVM IR from chrr/libECP :: src (ecp_array)

; 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.doubleArray = type { ptr, ptr }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.doubleArray_new = external hidden unnamed_addr constant [41 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local { ptr, ptr } @doubleArray_new(i64 noundef %0, ...) #0 {
  %2 = alloca %struct.doubleArray, align 8
  %3 = alloca i64, align 8
  %4 = alloca [1 x %struct.__va_list_tag], align 16
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 1, ptr %6, align 8, !tbaa !5
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = add i64 %7, 1
  %9 = call noalias ptr @calloc(i64 noundef %8, i64 noundef 8) #6
  %10 = getelementptr inbounds %struct.doubleArray, ptr %2, i32 0, i32 0
  store ptr %9, ptr %10, align 8, !tbaa !9
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.doubleArray, ptr %2, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds i64, ptr %13, i64 0
  store i64 %11, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %15)
  store i32 1, ptr %5, align 4, !tbaa !12
  br label %16

16:                                               ; preds = %61, %1
  %17 = load i32, ptr %5, align 4, !tbaa !12
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = icmp ule i64 %18, %19
  br i1 %20, label %21, label %64

21:                                               ; preds = %16
  %22 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  %23 = getelementptr inbounds %struct.__va_list_tag, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 16
  %25 = icmp ule i32 %24, 40
  br i1 %25, label %26, label %31

26:                                               ; preds = %21
  %27 = getelementptr inbounds %struct.__va_list_tag, ptr %22, i32 0, i32 3
  %28 = load ptr, ptr %27, align 16
  %29 = getelementptr i8, ptr %28, i32 %24
  %30 = add i32 %24, 8
  store i32 %30, ptr %23, align 16
  br label %35

31:                                               ; preds = %21
  %32 = getelementptr inbounds %struct.__va_list_tag, ptr %22, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8
  %34 = getelementptr i8, ptr %33, i32 8
  store ptr %34, ptr %32, align 8
  br label %35

35:                                               ; preds = %31, %26
  %36 = phi ptr [ %29, %26 ], [ %33, %31 ]
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.doubleArray, ptr %2, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !12
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i64, ptr %39, i64 %41
  store i64 %37, ptr %42, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.doubleArray, ptr %2, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = load i32, ptr %5, align 4, !tbaa !12
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i64, ptr %44, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = icmp ugt i64 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %35
  br label %52

51:                                               ; preds = %35
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 23, ptr noundef @__PRETTY_FUNCTION__.doubleArray_new) #7
  unreachable

52:                                               ; preds = %50
  %53 = getelementptr inbounds %struct.doubleArray, ptr %2, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !12
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i64, ptr %54, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = mul i64 %59, %58
  store i64 %60, ptr %6, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %52
  %62 = load i32, ptr %5, align 4, !tbaa !12
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !12
  br label %16, !llvm.loop !14

64:                                               ; preds = %16
  %65 = load i64, ptr %6, align 8, !tbaa !5
  %66 = call noalias ptr @calloc(i64 noundef %65, i64 noundef 8) #6
  %67 = getelementptr inbounds %struct.doubleArray, ptr %2, i32 0, i32 1
  store ptr %66, ptr %67, align 8, !tbaa !16
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %68

68:                                               ; preds = %79, %64
  %69 = load i32, ptr %5, align 4, !tbaa !12
  %70 = sext i32 %69 to i64
  %71 = load i64, ptr %6, align 8, !tbaa !5
  %72 = icmp ult i64 %70, %71
  br i1 %72, label %73, label %82

73:                                               ; preds = %68
  %74 = getelementptr inbounds %struct.doubleArray, ptr %2, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !16
  %76 = load i32, ptr %5, align 4, !tbaa !12
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %75, i64 %77
  store double 0.000000e+00, ptr %78, align 8, !tbaa !17
  br label %79

79:                                               ; preds = %73
  %80 = load i32, ptr %5, align 4, !tbaa !12
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %5, align 4, !tbaa !12
  br label %68, !llvm.loop !19

82:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #5
  %83 = load { ptr, ptr }, ptr %2, align 8
  ret { ptr, ptr } %83
}

; 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,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

; 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,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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { noreturn 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }
attributes #7 = { 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !11, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = distinct !{!19, !15}


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

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.doubleArray_new = external hidden unnamed_addr constant [41 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local { ptr, ptr } @doubleArray_new(i64 noundef %0, ...) local_unnamed_addr #0 {
  %2 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #6
  %3 = add i64 %0, 1
  %4 = tail call noalias ptr @calloc(i64 noundef %3, i64 noundef 8) #7
  store i64 %0, ptr %4, align 8, !tbaa !5
  call void @llvm.va_start.p0(ptr nonnull %2)
  %.not24 = icmp eq i64 %0, 0
  br i1 %.not24, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %1
  %5 = call noalias dereferenceable_or_null(8) ptr @calloc(i64 noundef 1, i64 noundef 8) #7
  br label %.lr.ph30.preheader

.lr.ph:                                           ; preds = %1
  %.promoted = load i32, ptr %2, align 16
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  %8 = load ptr, ptr %7, align 16
  %.promoted27 = load ptr, ptr %6, align 8
  br label %9

9:                                                ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %10 = phi ptr [ %.promoted27, %.lr.ph ], [ %20, %26 ]
  %.026 = phi i64 [ 1, %.lr.ph ], [ %27, %26 ]
  %11 = phi i32 [ %.promoted, %.lr.ph ], [ %21, %26 ]
  %12 = icmp ult i32 %11, 41
  br i1 %12, label %13, label %17

13:                                               ; preds = %9
  %14 = zext nneg i32 %11 to i64
  %15 = getelementptr i8, ptr %8, i64 %14
  %16 = add nuw nsw i32 %11, 8
  store i32 %16, ptr %2, align 16
  br label %19

17:                                               ; preds = %9
  %18 = getelementptr i8, ptr %10, i64 8
  store ptr %18, ptr %6, align 8
  br label %19

19:                                               ; preds = %17, %13
  %20 = phi ptr [ %10, %13 ], [ %18, %17 ]
  %21 = phi i32 [ %16, %13 ], [ %11, %17 ]
  %22 = phi ptr [ %15, %13 ], [ %10, %17 ]
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds i64, ptr %4, i64 %indvars.iv
  store i64 %23, ptr %24, align 8, !tbaa !5
  %.not22 = icmp eq i64 %23, 0
  br i1 %.not22, label %25, label %26

25:                                               ; preds = %19
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 23, ptr noundef nonnull @__PRETTY_FUNCTION__.doubleArray_new) #8
  unreachable

26:                                               ; preds = %19
  %27 = mul i64 %23, %.026
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv, %0
  br i1 %exitcond, label %._crit_edge, label %9, !llvm.loop !9

._crit_edge:                                      ; preds = %26
  %28 = call noalias ptr @calloc(i64 noundef %27, i64 noundef 8) #7
  %.not32 = icmp eq i64 %27, 0
  br i1 %.not32, label %._crit_edge31, label %.lr.ph30.preheader

.lr.ph30.preheader:                               ; preds = %._crit_edge.thread, %._crit_edge
  %29 = phi ptr [ %5, %._crit_edge.thread ], [ %28, %._crit_edge ]
  %.0.lcssa39 = phi i64 [ 1, %._crit_edge.thread ], [ %27, %._crit_edge ]
  %30 = shl nuw i64 %.0.lcssa39, 3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %29, i8 0, i64 %30, i1 false), !tbaa !11
  br label %._crit_edge31

._crit_edge31:                                    ; preds = %.lr.ph30.preheader, %._crit_edge
  %31 = phi ptr [ %29, %.lr.ph30.preheader ], [ %28, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #6
  %.fca.0.insert = insertvalue { ptr, ptr } poison, ptr %4, 0
  %.fca.1.insert = insertvalue { ptr, ptr } %.fca.0.insert, ptr %31, 1
  ret { ptr, ptr } %.fca.1.insert
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { noreturn 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass