; LLVM IR from sympiler/nasoq :: src/common/Util.ll (ZN5nasoq10make_lowerEmmPiS0_PdRmS2_RS0_S3_RS1_)

; 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: 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5nasoq10make_lowerEmmPiS0_PdRmS2_RS0_S3_RS1_(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %9) #3 {
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  store i64 %0, ptr %11, align 8, !tbaa !5
  store i64 %1, ptr %12, align 8, !tbaa !5
  store ptr %2, ptr %13, align 8, !tbaa !9
  store ptr %3, ptr %14, align 8, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !9
  store ptr %5, ptr %16, align 8, !tbaa !9
  store ptr %6, ptr %17, align 8, !tbaa !9
  store ptr %7, ptr %18, align 8, !tbaa !9
  store ptr %8, ptr %19, align 8, !tbaa !9
  store ptr %9, ptr %20, align 8, !tbaa !9
  %25 = load i64, ptr %11, align 8, !tbaa !5
  %26 = load ptr, ptr %16, align 8, !tbaa !9
  store i64 %25, ptr %26, align 8, !tbaa !5
  %27 = load i64, ptr %12, align 8, !tbaa !5
  %28 = load i64, ptr %11, align 8, !tbaa !5
  %29 = sub i64 %27, %28
  %30 = udiv i64 %29, 2
  %31 = load i64, ptr %11, align 8, !tbaa !5
  %32 = add i64 %30, %31
  %33 = load ptr, ptr %17, align 8, !tbaa !9
  store i64 %32, ptr %33, align 8, !tbaa !5
  %34 = load ptr, ptr %16, align 8, !tbaa !9
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = add i64 %35, 1
  %37 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %36, i64 4)
  %38 = extractvalue { i64, i1 } %37, 1
  %39 = extractvalue { i64, i1 } %37, 0
  %40 = select i1 %38, i64 -1, i64 %39
  %41 = call noalias noundef nonnull ptr @_Znam(i64 noundef %40) #4
  %42 = load ptr, ptr %18, align 8, !tbaa !9
  store ptr %41, ptr %42, align 8, !tbaa !9
  %43 = load ptr, ptr %18, align 8, !tbaa !9
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds i32, ptr %44, i64 0
  store i32 0, ptr %45, align 4, !tbaa !11
  %46 = load ptr, ptr %17, align 8, !tbaa !9
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %47, i64 4)
  %49 = extractvalue { i64, i1 } %48, 1
  %50 = extractvalue { i64, i1 } %48, 0
  %51 = select i1 %49, i64 -1, i64 %50
  %52 = call noalias noundef nonnull ptr @_Znam(i64 noundef %51) #4
  %53 = load ptr, ptr %19, align 8, !tbaa !9
  store ptr %52, ptr %53, align 8, !tbaa !9
  %54 = load ptr, ptr %17, align 8, !tbaa !9
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %55, i64 8)
  %57 = extractvalue { i64, i1 } %56, 1
  %58 = extractvalue { i64, i1 } %56, 0
  %59 = select i1 %57, i64 -1, i64 %58
  %60 = call noalias noundef nonnull ptr @_Znam(i64 noundef %59) #4
  %61 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %60, ptr %61, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  store i32 0, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  store i32 0, ptr %22, align 4, !tbaa !11
  br label %62

62:                                               ; preds = %127, %10
  %63 = load i32, ptr %22, align 4, !tbaa !11
  %64 = sext i32 %63 to i64
  %65 = load i64, ptr %11, align 8, !tbaa !5
  %66 = icmp ult i64 %64, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %62
  store i32 2, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  br label %130

68:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #5
  %69 = load ptr, ptr %13, align 8, !tbaa !9
  %70 = load i32, ptr %22, align 4, !tbaa !11
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !11
  store i32 %73, ptr %24, align 4, !tbaa !11
  br label %74

74:                                               ; preds = %116, %68
  %75 = load i32, ptr %24, align 4, !tbaa !11
  %76 = load ptr, ptr %13, align 8, !tbaa !9
  %77 = load i32, ptr %22, align 4, !tbaa !11
  %78 = add nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i32, ptr %76, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !11
  %82 = icmp slt i32 %75, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %74
  store i32 5, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #5
  br label %119

84:                                               ; preds = %74
  %85 = load ptr, ptr %14, align 8, !tbaa !9
  %86 = load i32, ptr %24, align 4, !tbaa !11
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i32, ptr %85, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !11
  %90 = load i32, ptr %22, align 4, !tbaa !11
  %91 = icmp sge i32 %89, %90
  br i1 %91, label %92, label %115

92:                                               ; preds = %84
  %93 = load ptr, ptr %14, align 8, !tbaa !9
  %94 = load i32, ptr %24, align 4, !tbaa !11
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i32, ptr %93, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !11
  %98 = load ptr, ptr %19, align 8, !tbaa !9
  %99 = load ptr, ptr %98, align 8, !tbaa !9
  %100 = load i32, ptr %21, align 4, !tbaa !11
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i32, ptr %99, i64 %101
  store i32 %97, ptr %102, align 4, !tbaa !11
  %103 = load ptr, ptr %15, align 8, !tbaa !9
  %104 = load i32, ptr %24, align 4, !tbaa !11
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds double, ptr %103, i64 %105
  %107 = load double, ptr %106, align 8, !tbaa !13
  %108 = load ptr, ptr %20, align 8, !tbaa !9
  %109 = load ptr, ptr %108, align 8, !tbaa !9
  %110 = load i32, ptr %21, align 4, !tbaa !11
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds double, ptr %109, i64 %111
  store double %107, ptr %112, align 8, !tbaa !13
  %113 = load i32, ptr %21, align 4, !tbaa !11
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %21, align 4, !tbaa !11
  br label %115

115:                                              ; preds = %92, %84
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %24, align 4, !tbaa !11
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %24, align 4, !tbaa !11
  br label %74, !llvm.loop !15

119:                                              ; preds = %83
  %120 = load i32, ptr %21, align 4, !tbaa !11
  %121 = load ptr, ptr %18, align 8, !tbaa !9
  %122 = load ptr, ptr %121, align 8, !tbaa !9
  %123 = load i32, ptr %22, align 4, !tbaa !11
  %124 = add nsw i32 %123, 1
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds i32, ptr %122, i64 %125
  store i32 %120, ptr %126, align 4, !tbaa !11
  br label %127

127:                                              ; preds = %119
  %128 = load i32, ptr %22, align 4, !tbaa !11
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %22, align 4, !tbaa !11
  br label %62, !llvm.loop !17

130:                                              ; preds = %67
  store i32 1, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  ret i32 1
}

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


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5nasoq10make_lowerEmmPiS0_PdRmS2_RS0_S3_RS1_(i64 noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef nonnull align 8 dereferenceable(8) %5, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %6, ptr nocapture noundef nonnull align 8 dereferenceable(8) %7, ptr nocapture noundef nonnull align 8 dereferenceable(8) %8, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %9) local_unnamed_addr #1 {
  store i64 %0, ptr %5, align 8, !tbaa !5
  %11 = sub i64 %1, %0
  %12 = lshr i64 %11, 1
  %13 = add i64 %12, %0
  store i64 %13, ptr %6, align 8, !tbaa !5
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = add i64 %14, 1
  %16 = icmp ugt i64 %15, 4611686018427387903
  %17 = shl i64 %15, 2
  %18 = select i1 %16, i64 -1, i64 %17
  %19 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %18) #2
  store ptr %19, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %19, align 4, !tbaa !11
  %20 = icmp ugt i64 %13, 4611686018427387903
  %21 = shl nuw i64 %13, 2
  %22 = select i1 %20, i64 -1, i64 %21
  %23 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %22) #2
  store ptr %23, ptr %8, align 8, !tbaa !9
  %24 = icmp ugt i64 %13, 2305843009213693951
  %25 = shl nuw i64 %13, 3
  %26 = select i1 %24, i64 -1, i64 %25
  %27 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %26) #2
  store ptr %27, ptr %9, align 8, !tbaa !9
  %.not50 = icmp eq i64 %0, 0
  br i1 %.not50, label %._crit_edge49, label %.lr.ph48

.lr.ph48:                                         ; preds = %10
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  br label %29

._crit_edge49:                                    ; preds = %._crit_edge, %10
  ret i32 1

29:                                               ; preds = %.lr.ph48, %._crit_edge
  %indvars.iv52 = phi i64 [ 0, %.lr.ph48 ], [ %indvars.iv.next53, %._crit_edge ]
  %.03745 = phi i32 [ 0, %.lr.ph48 ], [ %.1.lcssa, %._crit_edge ]
  %30 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv52
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %32 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next53
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = icmp slt i32 %31, %33
  br i1 %34, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %29
  %35 = load ptr, ptr %8, align 8
  %36 = sext i32 %31 to i64
  br label %38

._crit_edge:                                      ; preds = %50, %29
  %.1.lcssa = phi i32 [ %.03745, %29 ], [ %.2, %50 ]
  %37 = getelementptr inbounds i32, ptr %28, i64 %indvars.iv.next53
  store i32 %.1.lcssa, ptr %37, align 4, !tbaa !11
  %exitcond.not = icmp eq i64 %indvars.iv.next53, %0
  br i1 %exitcond.not, label %._crit_edge49, label %29, !llvm.loop !13

38:                                               ; preds = %.lr.ph, %50
  %39 = phi i32 [ %33, %.lr.ph ], [ %51, %50 ]
  %indvars.iv = phi i64 [ %36, %.lr.ph ], [ %indvars.iv.next, %50 ]
  %.141 = phi i32 [ %.03745, %.lr.ph ], [ %.2, %50 ]
  %40 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %.not = icmp sgt i64 %indvars.iv52, %42
  br i1 %.not, label %50, label %43

43:                                               ; preds = %38
  %44 = sext i32 %.141 to i64
  %45 = getelementptr inbounds i32, ptr %35, i64 %44
  store i32 %41, ptr %45, align 4, !tbaa !11
  %46 = getelementptr inbounds double, ptr %4, i64 %indvars.iv
  %47 = load double, ptr %46, align 8, !tbaa !15
  %48 = getelementptr inbounds double, ptr %27, i64 %44
  store double %47, ptr %48, align 8, !tbaa !15
  %49 = add nsw i32 %.141, 1
  %.pre = load i32, ptr %32, align 4, !tbaa !11
  br label %50

50:                                               ; preds = %38, %43
  %51 = phi i32 [ %.pre, %43 ], [ %39, %38 ]
  %.2 = phi i32 [ %49, %43 ], [ %.141, %38 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %52 = sext i32 %51 to i64
  %53 = icmp slt i64 %indvars.iv.next, %52
  br i1 %53, label %38, label %._crit_edge, !llvm.loop !17
}

attributes #0 = { nobuiltin 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 #1 = { mustprogress 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 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !14}


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