; LLVM IR from SanLiWuXun/2phase-LBM-DNS :: LBMDNS.ll (Z7Calc_IBv)

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

@POS = external dso_local global [300 x [2 x double]], align 16
@IB = external dso_local global [201 x [801 x [2 x i32]]], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7Calc_IBv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %35, %0
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 200
  br i1 %11, label %12, label %38

12:                                               ; preds = %9
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %31, %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 800
  br i1 %15, label %16, label %34

16:                                               ; preds = %13
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %18
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [801 x [2 x i32]], ptr %19, i64 0, i64 %21
  %23 = getelementptr inbounds [2 x i32], ptr %22, i64 0, i64 0
  store i32 0, ptr %23, align 8, !tbaa !5
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %25
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [801 x [2 x i32]], ptr %26, i64 0, i64 %28
  %30 = getelementptr inbounds [2 x i32], ptr %29, i64 0, i64 1
  store i32 -1, ptr %30, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %16
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

34:                                               ; preds = %13
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %1, align 4, !tbaa !5
  br label %9, !llvm.loop !11

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

39:                                               ; preds = %114, %38
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = icmp slt i32 %40, 300
  br i1 %41, label %42, label %117

42:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 5.500000e+00, ptr %8, align 8, !tbaa !12
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [300 x [2 x double]], ptr @POS, i64 0, i64 %44
  %46 = getelementptr inbounds [2 x double], ptr %45, i64 0, i64 0
  %47 = load double, ptr %46, align 16, !tbaa !12
  %48 = load double, ptr %8, align 8, !tbaa !12
  %49 = fsub double %47, %48
  %50 = call double @llvm.floor.f64(double %49)
  %51 = fptosi double %50 to i32
  store i32 %51, ptr %4, align 4, !tbaa !5
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [300 x [2 x double]], ptr @POS, i64 0, i64 %53
  %55 = getelementptr inbounds [2 x double], ptr %54, i64 0, i64 0
  %56 = load double, ptr %55, align 16, !tbaa !12
  %57 = load double, ptr %8, align 8, !tbaa !12
  %58 = fadd double %56, %57
  %59 = call double @llvm.ceil.f64(double %58)
  %60 = fptosi double %59 to i32
  store i32 %60, ptr %5, align 4, !tbaa !5
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [300 x [2 x double]], ptr @POS, i64 0, i64 %62
  %64 = getelementptr inbounds [2 x double], ptr %63, i64 0, i64 1
  %65 = load double, ptr %64, align 8, !tbaa !12
  %66 = load double, ptr %8, align 8, !tbaa !12
  %67 = fadd double %65, %66
  %68 = call double @llvm.ceil.f64(double %67)
  %69 = fptosi double %68 to i32
  store i32 %69, ptr %6, align 4, !tbaa !5
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [300 x [2 x double]], ptr @POS, i64 0, i64 %71
  %73 = getelementptr inbounds [2 x double], ptr %72, i64 0, i64 1
  %74 = load double, ptr %73, align 8, !tbaa !12
  %75 = load double, ptr %8, align 8, !tbaa !12
  %76 = fsub double %74, %75
  %77 = call double @llvm.floor.f64(double %76)
  %78 = fptosi double %77 to i32
  store i32 %78, ptr %7, align 4, !tbaa !5
  %79 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %79, ptr %1, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %110, %42
  %81 = load i32, ptr %1, align 4, !tbaa !5
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = icmp sle i32 %81, %82
  br i1 %83, label %84, label %113

84:                                               ; preds = %80
  %85 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %85, ptr %2, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %106, %84
  %87 = load i32, ptr %2, align 4, !tbaa !5
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = icmp sle i32 %87, %88
  br i1 %89, label %90, label %109

90:                                               ; preds = %86
  %91 = load i32, ptr %1, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %92
  %94 = load i32, ptr %2, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [801 x [2 x i32]], ptr %93, i64 0, i64 %95
  %97 = getelementptr inbounds [2 x i32], ptr %96, i64 0, i64 0
  store i32 1, ptr %97, align 8, !tbaa !5
  %98 = load i32, ptr %3, align 4, !tbaa !5
  %99 = load i32, ptr %1, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %100
  %102 = load i32, ptr %2, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [801 x [2 x i32]], ptr %101, i64 0, i64 %103
  %105 = getelementptr inbounds [2 x i32], ptr %104, i64 0, i64 1
  store i32 %98, ptr %105, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %90
  %107 = load i32, ptr %2, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %2, align 4, !tbaa !5
  br label %86, !llvm.loop !14

109:                                              ; preds = %86
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %1, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %1, align 4, !tbaa !5
  br label %80, !llvm.loop !15

113:                                              ; preds = %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %114

114:                                              ; preds = %113
  %115 = load i32, ptr %3, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %3, align 4, !tbaa !5
  br label %39, !llvm.loop !16

117:                                              ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

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

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

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


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

@POS = external dso_local local_unnamed_addr global [300 x [2 x double]], align 16
@IB = external dso_local local_unnamed_addr global [201 x [801 x [2 x i32]]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7Calc_IBv() local_unnamed_addr #0 {
  br label %vector.ph

vector.ph:                                        ; preds = %scalar.ph, %0
  %indvars.iv47 = phi i64 [ 0, %0 ], [ %indvars.iv.next48, %scalar.ph ]
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %1 = or disjoint i64 %index, 2
  %2 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv47, i64 %index
  %3 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv47, i64 %1
  store <4 x i32> <i32 0, i32 -1, i32 0, i32 -1>, ptr %2, align 8, !tbaa !5
  store <4 x i32> <i32 0, i32 -1, i32 0, i32 -1>, ptr %3, align 8, !tbaa !5
  %index.next = or disjoint i64 %index, 4
  %4 = or disjoint i64 %index, 6
  %5 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv47, i64 %index.next
  %6 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv47, i64 %4
  store <4 x i32> <i32 0, i32 -1, i32 0, i32 -1>, ptr %5, align 8, !tbaa !5
  store <4 x i32> <i32 0, i32 -1, i32 0, i32 -1>, ptr %6, align 8, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 8
  %7 = icmp eq i64 %index.next.1, 800
  br i1 %7, label %scalar.ph, label %vector.body, !llvm.loop !9

scalar.ph:                                        ; preds = %vector.body
  %8 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv47, i64 800
  store i32 0, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 -1, ptr %9, align 4, !tbaa !5
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next48, 201
  br i1 %exitcond50.not, label %.preheader34, label %vector.ph, !llvm.loop !13

.preheader34:                                     ; preds = %scalar.ph, %._crit_edge42
  %indvars.iv60 = phi i64 [ %indvars.iv.next61, %._crit_edge42 ], [ 0, %scalar.ph ]
  %10 = getelementptr inbounds [300 x [2 x double]], ptr @POS, i64 0, i64 %indvars.iv60
  %11 = load <2 x double>, ptr %10, align 16, !tbaa !14
  %12 = fadd <2 x double> %11, <double 5.500000e+00, double 5.500000e+00>
  %13 = tail call <2 x double> @llvm.ceil.v2f64(<2 x double> %12)
  %14 = fptosi <2 x double> %13 to <2 x i32>
  %15 = fadd <2 x double> %11, <double -5.500000e+00, double -5.500000e+00>
  %16 = tail call <2 x double> @llvm.floor.v2f64(<2 x double> %15)
  %17 = fptosi <2 x double> %16 to <2 x i32>
  %18 = icmp sgt <2 x i32> %17, %14
  %19 = extractelement <2 x i1> %18, i64 0
  %20 = extractelement <2 x i1> %18, i64 1
  %or.cond = select i1 %19, i1 true, i1 %20
  br i1 %or.cond, label %._crit_edge42, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader34
  %21 = extractelement <2 x i32> %17, i64 1
  %22 = sext i32 %21 to i64
  %23 = extractelement <2 x i32> %14, i64 1
  %24 = add i32 %23, 1
  %25 = extractelement <2 x i32> %17, i64 0
  %26 = sext i32 %25 to i64
  %27 = extractelement <2 x i32> %14, i64 0
  %28 = add i32 %27, 1
  %29 = trunc nuw nsw i64 %indvars.iv60 to i32
  %30 = sub i32 %23, %21
  %31 = zext i32 %30 to i64
  %32 = add nuw nsw i64 %31, 1
  %min.iters.check = icmp ult i32 %30, 3
  %n.vec = and i64 %32, 8589934588
  %ind.end = add nsw i64 %n.vec, %22
  %broadcast.splatinsert = insertelement <2 x i32> poison, i32 %29, i64 0
  %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> poison, <2 x i32> zeroinitializer
  %interleaved.vec = shufflevector <2 x i32> <i32 1, i32 1>, <2 x i32> %broadcast.splat, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  %cmp.n = icmp eq i64 %32, %n.vec
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv55 = phi i64 [ %26, %.preheader.preheader ], [ %indvars.iv.next56, %._crit_edge ]
  br i1 %min.iters.check, label %scalar.ph65.preheader, label %vector.body68

vector.body68:                                    ; preds = %.preheader, %vector.body68
  %index69 = phi i64 [ %index.next71, %vector.body68 ], [ 0, %.preheader ]
  %offset.idx = add i64 %index69, %22
  %33 = add i64 %offset.idx, 2
  %34 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv55, i64 %offset.idx
  %35 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv55, i64 %33
  store <4 x i32> %interleaved.vec, ptr %34, align 8, !tbaa !5
  store <4 x i32> %interleaved.vec, ptr %35, align 8, !tbaa !5
  %index.next71 = add nuw i64 %index69, 4
  %36 = icmp eq i64 %index.next71, %n.vec
  br i1 %36, label %middle.block64, label %vector.body68, !llvm.loop !16

middle.block64:                                   ; preds = %vector.body68
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph65.preheader

scalar.ph65.preheader:                            ; preds = %middle.block64, %.preheader
  %indvars.iv51.ph = phi i64 [ %22, %.preheader ], [ %ind.end, %middle.block64 ]
  br label %scalar.ph65

scalar.ph65:                                      ; preds = %scalar.ph65.preheader, %scalar.ph65
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %scalar.ph65 ], [ %indvars.iv51.ph, %scalar.ph65.preheader ]
  %37 = getelementptr inbounds [201 x [801 x [2 x i32]]], ptr @IB, i64 0, i64 %indvars.iv55, i64 %indvars.iv51
  store i32 1, ptr %37, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 4
  store i32 %29, ptr %38, align 4, !tbaa !5
  %indvars.iv.next52 = add nsw i64 %indvars.iv51, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next52 to i32
  %exitcond54.not = icmp eq i32 %24, %lftr.wideiv
  br i1 %exitcond54.not, label %._crit_edge, label %scalar.ph65, !llvm.loop !17

._crit_edge:                                      ; preds = %scalar.ph65, %middle.block64
  %indvars.iv.next56 = add nsw i64 %indvars.iv55, 1
  %lftr.wideiv58 = trunc i64 %indvars.iv.next56 to i32
  %exitcond59.not = icmp eq i32 %28, %lftr.wideiv58
  br i1 %exitcond59.not, label %._crit_edge42, label %.preheader, !llvm.loop !18

._crit_edge42:                                    ; preds = %._crit_edge, %.preheader34
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %exitcond63.not = icmp eq i64 %indvars.iv.next61, 300
  br i1 %exitcond63.not, label %39, label %.preheader34, !llvm.loop !19

39:                                               ; preds = %._crit_edge42
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.floor.v2f64(<2 x double>) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.ceil.v2f64(<2 x double>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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++ 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}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !10, !11, !12}
!17 = distinct !{!17, !10, !12, !11}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass