; LLVM IR from afrozchakure/Competitive-Programming-Solutions :: HackerRank/C (StudentsMarksSum)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @marks_summation(ptr noundef %0, i32 noundef %1, i8 noundef signext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  %10 = load i8, ptr %6, align 1, !tbaa !11
  %11 = sext i8 %10 to i32
  %12 = icmp eq i32 %11, 98
  br i1 %12, label %13, label %31

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %27, %13
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %30

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = add nsw i32 %25, %24
  store i32 %26, ptr %7, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %19
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = add nsw i32 %28, 2
  store i32 %29, ptr %8, align 4, !tbaa !9
  br label %14, !llvm.loop !12

30:                                               ; preds = %18
  br label %49

31:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %45, %31
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %48

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %38, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %7, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %37
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = add nsw i32 %46, 2
  store i32 %47, ptr %9, align 4, !tbaa !9
  br label %32, !llvm.loop !14

48:                                               ; preds = %36
  br label %49

49:                                               ; preds = %48, %30
  %50 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %50
}

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

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

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @marks_summation(ptr nocapture noundef readonly %0, i32 noundef %1, i8 noundef signext %2) local_unnamed_addr #0 {
  %4 = icmp eq i8 %2, 98
  br i1 %4, label %.preheader, label %.preheader15

.preheader15:                                     ; preds = %3
  %5 = icmp sgt i32 %1, 1
  br i1 %5, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader15
  %6 = zext nneg i32 %1 to i64
  %7 = add nsw i64 %6, -2
  %min.iters.check = icmp ult i64 %7, 16
  br i1 %min.iters.check, label %.lr.ph.preheader59, label %vector.ph

.lr.ph.preheader59:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.117.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %20, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %8 = lshr i64 %7, 1
  %9 = add nuw i64 %8, 1
  %n.mod.vf = and i64 %9, 7
  %10 = icmp eq i64 %n.mod.vf, 0
  %11 = select i1 %10, i64 8, i64 %n.mod.vf
  %n.vec = sub i64 %9, %11
  %12 = shl i64 %n.vec, 1
  %ind.end = or disjoint i64 %12, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %17, %vector.body ]
  %vec.phi33 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]
  %13 = shl i64 %index, 1
  %offset.idx = or disjoint i64 %13, 1
  %14 = or disjoint i64 %13, 9
  %15 = getelementptr inbounds i32, ptr %0, i64 %offset.idx
  %16 = getelementptr inbounds i32, ptr %0, i64 %14
  %wide.vec = load <8 x i32>, ptr %15, align 4, !tbaa !5
  %wide.vec34 = load <8 x i32>, ptr %16, align 4, !tbaa !5
  %strided.vec = shufflevector <8 x i32> %wide.vec, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec35 = shufflevector <8 x i32> %wide.vec34, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %17 = add <4 x i32> %strided.vec, %vec.phi
  %18 = add <4 x i32> %strided.vec35, %vec.phi33
  %index.next = add nuw i64 %index, 8
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %18, %17
  %20 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br label %.lr.ph.preheader59

.preheader:                                       ; preds = %3
  %21 = icmp sgt i32 %1, 0
  br i1 %21, label %.lr.ph21.preheader, label %.loopexit

.lr.ph21.preheader:                               ; preds = %.preheader
  %22 = zext nneg i32 %1 to i64
  %min.iters.check38 = icmp ult i32 %1, 17
  br i1 %min.iters.check38, label %.lr.ph21.preheader56, label %vector.ph39

vector.ph39:                                      ; preds = %.lr.ph21.preheader
  %23 = add nsw i64 %22, -1
  %24 = lshr i64 %23, 1
  %25 = add nuw i64 %24, 1
  %n.mod.vf40 = and i64 %25, 7
  %26 = icmp eq i64 %n.mod.vf40, 0
  %27 = select i1 %26, i64 8, i64 %n.mod.vf40
  %n.vec41 = sub i64 %25, %27
  %ind.end42 = shl i64 %n.vec41, 1
  br label %vector.body44

vector.body44:                                    ; preds = %vector.body44, %vector.ph39
  %index45 = phi i64 [ 0, %vector.ph39 ], [ %index.next53, %vector.body44 ]
  %vec.phi46 = phi <4 x i32> [ zeroinitializer, %vector.ph39 ], [ %31, %vector.body44 ]
  %vec.phi47 = phi <4 x i32> [ zeroinitializer, %vector.ph39 ], [ %32, %vector.body44 ]
  %offset.idx48 = shl i64 %index45, 1
  %28 = or disjoint i64 %offset.idx48, 8
  %29 = getelementptr inbounds i32, ptr %0, i64 %offset.idx48
  %30 = getelementptr inbounds i32, ptr %0, i64 %28
  %wide.vec49 = load <8 x i32>, ptr %29, align 4, !tbaa !5
  %wide.vec50 = load <8 x i32>, ptr %30, align 4, !tbaa !5
  %strided.vec51 = shufflevector <8 x i32> %wide.vec49, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec52 = shufflevector <8 x i32> %wide.vec50, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %31 = add <4 x i32> %strided.vec51, %vec.phi46
  %32 = add <4 x i32> %strided.vec52, %vec.phi47
  %index.next53 = add nuw i64 %index45, 8
  %33 = icmp eq i64 %index.next53, %n.vec41
  br i1 %33, label %middle.block36, label %vector.body44, !llvm.loop !13

middle.block36:                                   ; preds = %vector.body44
  %bin.rdx54 = add <4 x i32> %32, %31
  %34 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx54)
  br label %.lr.ph21.preheader56

.lr.ph21.preheader56:                             ; preds = %middle.block36, %.lr.ph21.preheader
  %indvars.iv26.ph = phi i64 [ 0, %.lr.ph21.preheader ], [ %ind.end42, %middle.block36 ]
  %.01419.ph = phi i32 [ 0, %.lr.ph21.preheader ], [ %34, %middle.block36 ]
  br label %.lr.ph21

.lr.ph21:                                         ; preds = %.lr.ph21.preheader56, %.lr.ph21
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %.lr.ph21 ], [ %indvars.iv26.ph, %.lr.ph21.preheader56 ]
  %.01419 = phi i32 [ %37, %.lr.ph21 ], [ %.01419.ph, %.lr.ph21.preheader56 ]
  %35 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv26
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %36, %.01419
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 2
  %38 = icmp ult i64 %indvars.iv.next27, %22
  br i1 %38, label %.lr.ph21, label %.loopexit, !llvm.loop !14

.lr.ph:                                           ; preds = %.lr.ph.preheader59, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader59 ]
  %.117 = phi i32 [ %41, %.lr.ph ], [ %.117.ph, %.lr.ph.preheader59 ]
  %39 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = add nsw i32 %40, %.117
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %42 = icmp ult i64 %indvars.iv.next, %6
  br i1 %42, label %.lr.ph, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph21, %.preheader15, %.preheader
  %.2 = phi i32 [ 0, %.preheader ], [ 0, %.preheader15 ], [ %37, %.lr.ph21 ], [ %41, %.lr.ph ]
  ret i32 %.2
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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 speculatable willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11, !12}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10, !12, !11}


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