; LLVM IR from harharkh/sb_desc :: src (vector)

; 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.sb_vec = type { i64, ptr, i8 }

@sb_error_log = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.100 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.101 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @abort() #1

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

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

; Function Attrs: nounwind uwtable
define dso_local double @sb_vec_sum(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %28, label %9

9:                                                ; preds = %6
  %10 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %9
  %13 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %16

14:                                               ; preds = %9
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %14, %12
  %17 = phi ptr [ %13, %12 ], [ %15, %14 ]
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef @.str.100) #5
  %19 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  %22 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %25

23:                                               ; preds = %16
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %23, %21
  %26 = phi ptr [ %22, %21 ], [ %24, %23 ]
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str.1) #5
  call void @abort() #6
  unreachable

28:                                               ; preds = %6
  br label %29

29:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.sb_vec, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  store ptr %32, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store double 0.000000e+00, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !14
  br label %33

33:                                               ; preds = %47, %29
  %34 = load i64, ptr %5, align 8, !tbaa !14
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.sb_vec, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = icmp ult i64 %34, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %50

40:                                               ; preds = %33
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !14
  %43 = getelementptr inbounds double, ptr %41, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !12
  %45 = load double, ptr %4, align 8, !tbaa !12
  %46 = fadd double %45, %44
  store double %46, ptr %4, align 8, !tbaa !12
  br label %47

47:                                               ; preds = %40
  %48 = load i64, ptr %5, align 8, !tbaa !14
  %49 = add i64 %48, 1
  store i64 %49, ptr %5, align 8, !tbaa !14
  br label %33, !llvm.loop !16

50:                                               ; preds = %39
  br label %51

51:                                               ; preds = %50
  %52 = load double, ptr %4, align 8, !tbaa !12
  %53 = call i1 @llvm.is.fpclass.f64(double %52, i32 504)
  br i1 %53, label %73, label %54

54:                                               ; preds = %51
  %55 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %61

59:                                               ; preds = %54
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %59, %57
  %62 = phi ptr [ %58, %57 ], [ %60, %59 ]
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.101) #5
  %64 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %68

66:                                               ; preds = %61
  %67 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %70

68:                                               ; preds = %61
  %69 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %68, %66
  %71 = phi ptr [ %67, %66 ], [ %69, %68 ]
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str.1) #5
  call void @abort() #6
  unreachable

73:                                               ; preds = %51
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = load double, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret double %76
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i1 @llvm.is.fpclass.f64(double, i32 immarg) #4

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


; 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"

@sb_error_log = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.100 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.101 = external hidden unnamed_addr constant [27 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local double @sb_vec_sum(ptr noundef readonly %0) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %11

2:                                                ; preds = %1
  %3 = load ptr, ptr @sb_error_log, align 8
  %.not11 = icmp eq ptr %3, null
  %4 = load ptr, ptr @stderr, align 8
  %5 = select i1 %.not11, ptr %4, ptr %3
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.100) #4
  %7 = load ptr, ptr @sb_error_log, align 8
  %.not12 = icmp eq ptr %7, null
  %8 = load ptr, ptr @stderr, align 8
  %9 = select i1 %.not12, ptr %8, ptr %7
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.1) #4
  tail call void @abort() #5
  unreachable

11:                                               ; preds = %1
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = load i64, ptr %0, align 8, !tbaa !11
  %.not17 = icmp eq i64 %14, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %11
  %xtraiter = and i64 %14, 7
  %15 = icmp ult i64 %14, 8
  br i1 %15, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %14, -8
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %52, %.lr.ph ]
  %.016.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %53, %.lr.ph ]
  %.0915.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %52, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.016.epil = phi i64 [ %19, %.lr.ph.epil ], [ %.016.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.0915.epil = phi double [ %18, %.lr.ph.epil ], [ %.0915.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %16 = getelementptr inbounds double, ptr %13, i64 %.016.epil
  %17 = load double, ptr %16, align 8, !tbaa !12
  %18 = fadd double %.0915.epil, %17
  %19 = add nuw i64 %.016.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %11
  %.09.lcssa = phi double [ 0.000000e+00, %11 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %18, %.lr.ph.epil ]
  %20 = tail call double @llvm.fabs.f64(double %.09.lcssa)
  %21 = fcmp ueq double %20, 0x7FF0000000000000
  br i1 %21, label %54, label %63

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.016 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %53, %.lr.ph ]
  %.0915 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %52, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %22 = getelementptr inbounds double, ptr %13, i64 %.016
  %23 = load double, ptr %22, align 8, !tbaa !12
  %24 = fadd double %.0915, %23
  %25 = or disjoint i64 %.016, 1
  %26 = getelementptr inbounds double, ptr %13, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !12
  %28 = fadd double %24, %27
  %29 = or disjoint i64 %.016, 2
  %30 = getelementptr inbounds double, ptr %13, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !12
  %32 = fadd double %28, %31
  %33 = or disjoint i64 %.016, 3
  %34 = getelementptr inbounds double, ptr %13, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !12
  %36 = fadd double %32, %35
  %37 = or disjoint i64 %.016, 4
  %38 = getelementptr inbounds double, ptr %13, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !12
  %40 = fadd double %36, %39
  %41 = or disjoint i64 %.016, 5
  %42 = getelementptr inbounds double, ptr %13, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !12
  %44 = fadd double %40, %43
  %45 = or disjoint i64 %.016, 6
  %46 = getelementptr inbounds double, ptr %13, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !12
  %48 = fadd double %44, %47
  %49 = or disjoint i64 %.016, 7
  %50 = getelementptr inbounds double, ptr %13, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !12
  %52 = fadd double %48, %51
  %53 = add nuw i64 %.016, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !16

54:                                               ; preds = %._crit_edge
  %55 = load ptr, ptr @sb_error_log, align 8
  %.not13 = icmp eq ptr %55, null
  %56 = load ptr, ptr @stderr, align 8
  %57 = select i1 %.not13, ptr %56, ptr %55
  %58 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef nonnull @.str.101) #4
  %59 = load ptr, ptr @sb_error_log, align 8
  %.not14 = icmp eq ptr %59, null
  %60 = load ptr, ptr @stderr, align 8
  %61 = select i1 %.not14, ptr %60, ptr %59
  %62 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef nonnull @.str.1) #4
  tail call void @abort() #5
  unreachable

63:                                               ; preds = %._crit_edge
  ret double %.09.lcssa
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !8, i64 16}
!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 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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