; LLVM IR from libprima/prima :: c (prima)

; 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.prima_problem_t = type { i32, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, i32, ptr, ptr, i32, double, ptr }
%struct.prima_result_t = type { ptr, double, double, ptr, i32, i32, i8, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @prima_init_result(ptr noundef %0, ptr noundef byval(%struct.prima_problem_t) align 8 %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %2
  store i32 113, ptr %3, align 4
  br label %85

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 56, i1 false)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.prima_result_t, ptr %12, i32 0, i32 1
  store double 0x7FF8000000000000, ptr %13, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.prima_result_t, ptr %14, i32 0, i32 2
  store double 0x7FF8000000000000, ptr %15, align 8, !tbaa !14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.prima_result_t, ptr %16, i32 0, i32 4
  store i32 0, ptr %17, align 8, !tbaa !15
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.prima_result_t, ptr %18, i32 0, i32 5
  store i32 115, ptr %19, align 4, !tbaa !16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.prima_result_t, ptr %20, i32 0, i32 7
  store ptr null, ptr %21, align 8, !tbaa !17
  %22 = getelementptr inbounds %struct.prima_problem_t, ptr %1, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = sext i32 %23 to i64
  %25 = mul i64 %24, 8
  %26 = call noalias ptr @malloc(i64 noundef %25) #5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.prima_result_t, ptr %27, i32 0, i32 0
  store ptr %26, ptr %28, align 8, !tbaa !20
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.prima_result_t, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %10
  store i32 103, ptr %3, align 4
  br label %85

34:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !21
  br label %35

35:                                               ; preds = %48, %34
  %36 = load i32, ptr %5, align 4, !tbaa !21
  %37 = getelementptr inbounds %struct.prima_problem_t, ptr %1, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !18
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %51

41:                                               ; preds = %35
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.prima_result_t, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = load i32, ptr %5, align 4, !tbaa !21
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  store double 0x7FF8000000000000, ptr %47, align 8, !tbaa !22
  br label %48

48:                                               ; preds = %41
  %49 = load i32, ptr %5, align 4, !tbaa !21
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %5, align 4, !tbaa !21
  br label %35, !llvm.loop !23

51:                                               ; preds = %40
  %52 = getelementptr inbounds %struct.prima_problem_t, ptr %1, i32 0, i32 12
  %53 = load i32, ptr %52, align 8, !tbaa !25
  %54 = sext i32 %53 to i64
  %55 = mul i64 %54, 8
  %56 = call noalias ptr @malloc(i64 noundef %55) #5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.prima_result_t, ptr %57, i32 0, i32 3
  store ptr %56, ptr %58, align 8, !tbaa !26
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.prima_result_t, ptr %59, i32 0, i32 3
  %61 = load ptr, ptr %60, align 8, !tbaa !26
  %62 = icmp ne ptr %61, null
  br i1 %62, label %67, label %63

63:                                               ; preds = %51
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.prima_result_t, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !20
  call void @free(ptr noundef %66) #6
  store i32 103, ptr %3, align 4
  br label %85

67:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !21
  br label %68

68:                                               ; preds = %81, %67
  %69 = load i32, ptr %6, align 4, !tbaa !21
  %70 = getelementptr inbounds %struct.prima_problem_t, ptr %1, i32 0, i32 12
  %71 = load i32, ptr %70, align 8, !tbaa !25
  %72 = icmp slt i32 %69, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %84

74:                                               ; preds = %68
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.prima_result_t, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !26
  %78 = load i32, ptr %6, align 4, !tbaa !21
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  store double 0x7FF8000000000000, ptr %80, align 8, !tbaa !22
  br label %81

81:                                               ; preds = %74
  %82 = load i32, ptr %6, align 4, !tbaa !21
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %6, align 4, !tbaa !21
  br label %68, !llvm.loop !27

84:                                               ; preds = %73
  store i32 0, ptr %3, align 4
  br label %85

85:                                               ; preds = %84, %63, %33, %9
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

; 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.start.p0(i64 immarg, ptr nocapture) #3

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

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 allocsize(0) }
attributes #6 = { 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 8}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !12, i64 36, !13, i64 40, !6, i64 48}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !12, i64 32}
!16 = !{!10, !12, i64 36}
!17 = !{!10, !6, i64 48}
!18 = !{!19, !12, i64 0}
!19 = !{!"", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !6, i64 80, !6, i64 88, !12, i64 96, !11, i64 104, !6, i64 112}
!20 = !{!10, !6, i64 0}
!21 = !{!12, !12, i64 0}
!22 = !{!11, !11, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!19, !12, i64 96}
!26 = !{!10, !6, i64 24}
!27 = distinct !{!27, !24}


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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 114) i32 @prima_init_result(ptr noundef writeonly %0, ptr nocapture noundef readonly byval(%struct.prima_problem_t) align 8 %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %4, i8 0, i64 24, i1 false)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 115, ptr %6, align 4, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr null, ptr %7, align 8, !tbaa !14
  %8 = load i32, ptr %1, align 8, !tbaa !15
  %9 = sext i32 %8 to i64
  %10 = shl nsw i64 %9, 3
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #4
  store ptr %11, ptr %0, align 8, !tbaa !17
  %.not23 = icmp eq ptr %11, null
  br i1 %.not23, label %.loopexit, label %.preheader25

.preheader25:                                     ; preds = %3
  %12 = icmp sgt i32 %8, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader25
  %wide.trip.count = zext nneg i32 %8 to i64
  %min.iters.check = icmp ult i32 %8, 4
  br i1 %min.iters.check, label %.lr.ph.preheader47, label %vector.ph

.lr.ph.preheader47:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %13 = getelementptr inbounds double, ptr %11, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>, ptr %13, align 8, !tbaa !5
  store <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>, ptr %14, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader47

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %.preheader25
  %16 = getelementptr inbounds i8, ptr %1, i64 96
  %17 = load i32, ptr %16, align 8, !tbaa !22
  %18 = sext i32 %17 to i64
  %19 = shl nsw i64 %18, 3
  %20 = tail call noalias ptr @malloc(i64 noundef %19) #4
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %20, ptr %21, align 8, !tbaa !23
  %.not24 = icmp eq ptr %20, null
  br i1 %.not24, label %27, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %22 = icmp sgt i32 %17, 0
  br i1 %22, label %.lr.ph28.preheader, label %.loopexit

.lr.ph28.preheader:                               ; preds = %.preheader
  %wide.trip.count33 = zext nneg i32 %17 to i64
  %min.iters.check37 = icmp ult i32 %17, 4
  br i1 %min.iters.check37, label %.lr.ph28.preheader46, label %vector.ph38

.lr.ph28.preheader46:                             ; preds = %middle.block35, %.lr.ph28.preheader
  %indvars.iv30.ph = phi i64 [ 0, %.lr.ph28.preheader ], [ %n.vec40, %middle.block35 ]
  br label %.lr.ph28

vector.ph38:                                      ; preds = %.lr.ph28.preheader
  %n.vec40 = and i64 %wide.trip.count33, 2147483644
  br label %vector.body42

vector.body42:                                    ; preds = %vector.body42, %vector.ph38
  %index43 = phi i64 [ 0, %vector.ph38 ], [ %index.next44, %vector.body42 ]
  %23 = getelementptr inbounds double, ptr %20, i64 %index43
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  store <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>, ptr %23, align 8, !tbaa !5
  store <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>, ptr %24, align 8, !tbaa !5
  %index.next44 = add nuw i64 %index43, 4
  %25 = icmp eq i64 %index.next44, %n.vec40
  br i1 %25, label %middle.block35, label %vector.body42, !llvm.loop !24

middle.block35:                                   ; preds = %vector.body42
  %cmp.n45 = icmp eq i64 %n.vec40, %wide.trip.count33
  br i1 %cmp.n45, label %.loopexit, label %.lr.ph28.preheader46

.lr.ph:                                           ; preds = %.lr.ph.preheader47, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader47 ]
  %26 = getelementptr inbounds double, ptr %11, i64 %indvars.iv
  store double 0x7FF8000000000000, ptr %26, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !25

27:                                               ; preds = %._crit_edge
  tail call void @free(ptr noundef nonnull %11) #5
  br label %.loopexit

.lr.ph28:                                         ; preds = %.lr.ph28.preheader46, %.lr.ph28
  %indvars.iv30 = phi i64 [ %indvars.iv.next31, %.lr.ph28 ], [ %indvars.iv30.ph, %.lr.ph28.preheader46 ]
  %28 = getelementptr inbounds double, ptr %20, i64 %indvars.iv30
  store double 0x7FF8000000000000, ptr %28, align 8, !tbaa !5
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count33
  br i1 %exitcond34.not, label %.loopexit, label %.lr.ph28, !llvm.loop !26

.loopexit:                                        ; preds = %.lr.ph28, %middle.block35, %.preheader, %3, %2, %27
  %.021 = phi i32 [ 103, %27 ], [ 113, %2 ], [ 103, %3 ], [ 0, %.preheader ], [ 0, %middle.block35 ], [ 0, %.lr.ph28 ]
  ret i32 %.021
}

; 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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 36}
!10 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !12, i64 32, !12, i64 36, !13, i64 40, !11, i64 48}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !11, i64 48}
!15 = !{!16, !12, i64 0}
!16 = !{!"", !12, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !11, i64 56, !11, i64 64, !12, i64 72, !11, i64 80, !11, i64 88, !12, i64 96, !6, i64 104, !11, i64 112}
!17 = !{!10, !11, i64 0}
!18 = distinct !{!18, !19, !20, !21}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = !{!16, !12, i64 96}
!23 = !{!10, !11, i64 24}
!24 = distinct !{!24, !19, !20, !21}
!25 = distinct !{!25, !19, !21, !20}
!26 = distinct !{!26, !19, !21, !20}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass