; LLVM IR from libxsmm/libxsmm :: samples/nek (stream_update_kernels)

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

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__.stream_vector_set_ = external hidden unnamed_addr constant [63 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @stream_init(i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @stream_vector_set_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %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 ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp ne ptr null, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %14

13:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 94, ptr noundef @__PRETTY_FUNCTION__.stream_vector_set_) #5
  unreachable

14:                                               ; preds = %12
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp ne ptr null, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 95, ptr noundef @__PRETTY_FUNCTION__.stream_vector_set_) #5
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = ptrtoint ptr %22 to i64
  call void @stream_init(i32 noundef %21, i64 noundef %23, ptr noundef %8, ptr noundef %9)
  br label %24

24:                                               ; preds = %35, %19
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %24
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %31, i64 %33
  store double %30, ptr %34, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %28
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !9
  br label %24, !llvm.loop !13

38:                                               ; preds = %24
  br label %39

39:                                               ; preds = %50, %38
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %53

43:                                               ; preds = %39
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  store double %45, ptr %49, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %43
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !9
  br label %39, !llvm.loop !15

53:                                               ; preds = %39
  br label %54

54:                                               ; preds = %66, %53
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp slt i32 %55, %57
  br i1 %58, label %59, label %69

59:                                               ; preds = %54
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load double, ptr %60, align 8, !tbaa !11
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  store double %61, ptr %65, align 8, !tbaa !11
  br label %66

66:                                               ; preds = %59
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !9
  br label %54, !llvm.loop !16

69:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { 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 = { 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, !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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__.stream_vector_set_ = external hidden unnamed_addr constant [63 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @stream_init(i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local void @stream_vector_set_(ptr noundef readonly %0, ptr noundef %1, ptr noundef readonly %2) local_unnamed_addr #3 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %6, label %7

6:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 94, ptr noundef nonnull @__PRETTY_FUNCTION__.stream_vector_set_) #5
  unreachable

7:                                                ; preds = %3
  %.not21 = icmp eq ptr %0, null
  br i1 %.not21, label %8, label %9

8:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 95, ptr noundef nonnull @__PRETTY_FUNCTION__.stream_vector_set_) #5
  unreachable

9:                                                ; preds = %7
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = ptrtoint ptr %1 to i64
  call void @stream_init(i32 noundef %10, i64 noundef %11, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph.preheader, label %.preheader22

.lr.ph.preheader:                                 ; preds = %9
  %wide.trip.count = zext nneg i32 %12 to i64
  %.pre = load double, ptr %0, align 8, !tbaa !9
  %min.iters.check = icmp ult i32 %12, 4
  br i1 %min.iters.check, label %.lr.ph.preheader71, label %vector.ph

.lr.ph.preheader71:                               ; 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
  %broadcast.splatinsert = insertelement <2 x double> poison, double %.pre, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

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

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

.preheader22:                                     ; preds = %.lr.ph, %middle.block, %9
  %.0.lcssa = phi i32 [ 0, %9 ], [ %12, %middle.block ], [ %12, %.lr.ph ]
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp slt i32 %.0.lcssa, %17
  br i1 %18, label %.lr.ph25.preheader, label %.preheader

.lr.ph25.preheader:                               ; preds = %.preheader22
  %19 = zext nneg i32 %.0.lcssa to i64
  %wide.trip.count34 = zext i32 %17 to i64
  %.pre39 = load double, ptr %0, align 8, !tbaa !9
  %20 = sub nsw i64 %wide.trip.count34, %19
  %min.iters.check43 = icmp ult i64 %20, 4
  br i1 %min.iters.check43, label %.lr.ph25.preheader70, label %vector.ph44

.lr.ph25.preheader70:                             ; preds = %middle.block41, %.lr.ph25.preheader
  %indvars.iv31.ph = phi i64 [ %19, %.lr.ph25.preheader ], [ %ind.end, %middle.block41 ]
  br label %.lr.ph25

vector.ph44:                                      ; preds = %.lr.ph25.preheader
  %n.vec46 = and i64 %20, -4
  %ind.end = add nsw i64 %n.vec46, %19
  %broadcast.splatinsert50 = insertelement <2 x double> poison, double %.pre39, i64 0
  %broadcast.splat51 = shufflevector <2 x double> %broadcast.splatinsert50, <2 x double> poison, <2 x i32> zeroinitializer
  %invariant.gep = getelementptr double, ptr %1, i64 %19
  br label %vector.body48

vector.body48:                                    ; preds = %vector.body48, %vector.ph44
  %index49 = phi i64 [ 0, %vector.ph44 ], [ %index.next52, %vector.body48 ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %index49
  %21 = getelementptr inbounds i8, ptr %gep, i64 16
  store <2 x double> %broadcast.splat51, ptr %gep, align 8, !tbaa !9
  store <2 x double> %broadcast.splat51, ptr %21, align 8, !tbaa !9
  %index.next52 = add nuw i64 %index49, 4
  %22 = icmp eq i64 %index.next52, %n.vec46
  br i1 %22, label %middle.block41, label %vector.body48, !llvm.loop !15

middle.block41:                                   ; preds = %vector.body48
  %cmp.n53 = icmp eq i64 %20, %n.vec46
  br i1 %cmp.n53, label %.preheader, label %.lr.ph25.preheader70

.lr.ph:                                           ; preds = %.lr.ph.preheader71, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader71 ]
  %23 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  store double %.pre, ptr %23, align 8, !tbaa !9
  %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 %.preheader22, label %.lr.ph, !llvm.loop !16

.preheader:                                       ; preds = %.lr.ph25, %middle.block41, %.preheader22
  %.1.lcssa = phi i32 [ %.0.lcssa, %.preheader22 ], [ %17, %middle.block41 ], [ %17, %.lr.ph25 ]
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp slt i32 %.1.lcssa, %24
  br i1 %25, label %.lr.ph28.preheader, label %._crit_edge

.lr.ph28.preheader:                               ; preds = %.preheader
  %26 = zext i32 %.1.lcssa to i64
  %.pre40 = load double, ptr %0, align 8, !tbaa !9
  %27 = xor i32 %.1.lcssa, -1
  %28 = add i32 %24, %27
  %29 = zext i32 %28 to i64
  %30 = add nuw nsw i64 %29, 1
  %min.iters.check56 = icmp ult i32 %28, 3
  br i1 %min.iters.check56, label %.lr.ph28.preheader69, label %vector.ph57

.lr.ph28.preheader69:                             ; preds = %middle.block54, %.lr.ph28.preheader
  %indvars.iv36.ph = phi i64 [ %26, %.lr.ph28.preheader ], [ %ind.end60, %middle.block54 ]
  br label %.lr.ph28

vector.ph57:                                      ; preds = %.lr.ph28.preheader
  %n.vec59 = and i64 %30, 8589934588
  %ind.end60 = add nuw nsw i64 %n.vec59, %26
  %broadcast.splatinsert65 = insertelement <2 x double> poison, double %.pre40, i64 0
  %broadcast.splat66 = shufflevector <2 x double> %broadcast.splatinsert65, <2 x double> poison, <2 x i32> zeroinitializer
  %invariant.gep72 = getelementptr double, ptr %1, i64 %26
  br label %vector.body62

vector.body62:                                    ; preds = %vector.body62, %vector.ph57
  %index63 = phi i64 [ 0, %vector.ph57 ], [ %index.next67, %vector.body62 ]
  %gep73 = getelementptr double, ptr %invariant.gep72, i64 %index63
  %31 = getelementptr inbounds i8, ptr %gep73, i64 16
  store <2 x double> %broadcast.splat66, ptr %gep73, align 8, !tbaa !9
  store <2 x double> %broadcast.splat66, ptr %31, align 8, !tbaa !9
  %index.next67 = add nuw i64 %index63, 4
  %32 = icmp eq i64 %index.next67, %n.vec59
  br i1 %32, label %middle.block54, label %vector.body62, !llvm.loop !17

middle.block54:                                   ; preds = %vector.body62
  %cmp.n68 = icmp eq i64 %30, %n.vec59
  br i1 %cmp.n68, label %._crit_edge, label %.lr.ph28.preheader69

.lr.ph25:                                         ; preds = %.lr.ph25.preheader70, %.lr.ph25
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %.lr.ph25 ], [ %indvars.iv31.ph, %.lr.ph25.preheader70 ]
  %33 = getelementptr inbounds double, ptr %1, i64 %indvars.iv31
  store double %.pre39, ptr %33, align 8, !tbaa !9
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count34
  br i1 %exitcond35.not, label %.preheader, label %.lr.ph25, !llvm.loop !18

.lr.ph28:                                         ; preds = %.lr.ph28.preheader69, %.lr.ph28
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %.lr.ph28 ], [ %indvars.iv36.ph, %.lr.ph28.preheader69 ]
  %34 = getelementptr inbounds double, ptr %1, i64 %indvars.iv36
  store double %.pre40, ptr %34, align 8, !tbaa !9
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %35 = trunc nuw i64 %indvars.iv.next37 to i32
  %36 = icmp sgt i32 %24, %35
  br i1 %36, label %.lr.ph28, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph28, %middle.block54, %.preheader
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { 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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !13, !14}
!16 = distinct !{!16, !12, !14, !13}
!17 = distinct !{!17, !12, !13, !14}
!18 = distinct !{!18, !12, !14, !13}
!19 = distinct !{!19, !12, !14, !13}


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