; LLVM IR from sscollis/lns3d :: util (wgrid)

; 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 [4 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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

declare i32 @fclose(ptr noundef) #1

; 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 @wgrid2d_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca float, align 4
  %17 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %18 = load ptr, ptr %12, align 8, !tbaa !5
  %19 = call noalias ptr @fopen(ptr noundef %18, ptr noundef @.str)
  store ptr %19, ptr %17, align 8, !tbaa !5
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %17, align 8, !tbaa !5
  %22 = call i64 @fwrite(ptr noundef %20, i64 noundef 4, i64 noundef 1, ptr noundef %21)
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %17, align 8, !tbaa !5
  %25 = call i64 @fwrite(ptr noundef %23, i64 noundef 4, i64 noundef 1, ptr noundef %24)
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %56, %6
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %59

31:                                               ; preds = %26
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %32

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

37:                                               ; preds = %32
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load i32, ptr %14, align 4, !tbaa !9
  %42 = mul nsw i32 %40, %41
  %43 = add nsw i32 %38, %42
  store i32 %43, ptr %15, align 4, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = fptrunc double %48 to float
  store float %49, ptr %16, align 4, !tbaa !13
  %50 = load ptr, ptr %17, align 8, !tbaa !5
  %51 = call i64 @fwrite(ptr noundef %16, i64 noundef 4, i64 noundef 1, ptr noundef %50)
  br label %52

52:                                               ; preds = %37
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %13, align 4, !tbaa !9
  br label %32, !llvm.loop !15

55:                                               ; preds = %32
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %14, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %14, align 4, !tbaa !9
  br label %26, !llvm.loop !17

59:                                               ; preds = %26
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %90, %59
  %61 = load i32, ptr %14, align 4, !tbaa !9
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = icmp slt i32 %61, %63
  br i1 %64, label %65, label %93

65:                                               ; preds = %60
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %86, %65
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = icmp slt i32 %67, %69
  br i1 %70, label %71, label %89

71:                                               ; preds = %66
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = mul nsw i32 %74, %75
  %77 = add nsw i32 %72, %76
  store i32 %77, ptr %15, align 4, !tbaa !9
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = load i32, ptr %15, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds double, ptr %78, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !11
  %83 = fptrunc double %82 to float
  store float %83, ptr %16, align 4, !tbaa !13
  %84 = load ptr, ptr %17, align 8, !tbaa !5
  %85 = call i64 @fwrite(ptr noundef %16, i64 noundef 4, i64 noundef 1, ptr noundef %84)
  br label %86

86:                                               ; preds = %71
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %13, align 4, !tbaa !9
  br label %66, !llvm.loop !18

89:                                               ; preds = %66
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %14, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %14, align 4, !tbaa !9
  br label %60, !llvm.loop !19

93:                                               ; preds = %60
  %94 = load ptr, ptr %17, align 8, !tbaa !5
  %95 = call i32 @fclose(ptr noundef %94)
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

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

@.str = external hidden unnamed_addr constant [4 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: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @wgrid2d_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, ptr nocapture noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5) local_unnamed_addr #2 {
  %7 = alloca float, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %8 = tail call noalias ptr @fopen(ptr noundef %5, ptr noundef nonnull @.str)
  %9 = tail call i64 @fwrite(ptr noundef %2, i64 noundef 4, i64 noundef 1, ptr noundef %8)
  %10 = tail call i64 @fwrite(ptr noundef %3, i64 noundef 4, i64 noundef 1, ptr noundef %8)
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.preheader32.lr.ph, label %._crit_edge39

.preheader32.lr.ph:                               ; preds = %6
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.preheader32, label %._crit_edge39

.preheader32:                                     ; preds = %.preheader32.lr.ph, %._crit_edge
  %15 = phi i32 [ %31, %._crit_edge ], [ %11, %.preheader32.lr.ph ]
  %16 = phi i32 [ %32, %._crit_edge ], [ %13, %.preheader32.lr.ph ]
  %.02934 = phi i32 [ %33, %._crit_edge ], [ 0, %.preheader32.lr.ph ]
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph, label %._crit_edge

.preheader31:                                     ; preds = %._crit_edge
  %18 = icmp sgt i32 %31, 0
  br i1 %18, label %.preheader.lr.ph, label %._crit_edge39

.preheader.lr.ph:                                 ; preds = %.preheader31
  %.pr = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp sgt i32 %.pr, 0
  br i1 %19, label %.preheader, label %._crit_edge39

.lr.ph:                                           ; preds = %.preheader32, %.lr.ph
  %.033 = phi i32 [ %28, %.lr.ph ], [ 0, %.preheader32 ]
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = mul nsw i32 %20, %.02934
  %22 = add nsw i32 %21, %.033
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = fptrunc double %25 to float
  store float %26, ptr %7, align 4, !tbaa !11
  %27 = call i64 @fwrite(ptr noundef nonnull %7, i64 noundef 4, i64 noundef 1, ptr noundef %8)
  %28 = add nuw nsw i32 %.033, 1
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader32
  %31 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %15, %.preheader32 ]
  %32 = phi i32 [ %29, %._crit_edge.loopexit ], [ %16, %.preheader32 ]
  %33 = add nuw nsw i32 %.02934, 1
  %34 = icmp slt i32 %33, %31
  br i1 %34, label %.preheader32, label %.preheader31, !llvm.loop !15

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge37
  %35 = phi i32 [ %49, %._crit_edge37 ], [ %31, %.preheader.lr.ph ]
  %36 = phi i32 [ %50, %._crit_edge37 ], [ %.pr, %.preheader.lr.ph ]
  %.13038 = phi i32 [ %51, %._crit_edge37 ], [ 0, %.preheader.lr.ph ]
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %.preheader, %.lr.ph36
  %.135 = phi i32 [ %46, %.lr.ph36 ], [ 0, %.preheader ]
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = mul nsw i32 %38, %.13038
  %40 = add nsw i32 %39, %.135
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %1, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !9
  %44 = fptrunc double %43 to float
  store float %44, ptr %7, align 4, !tbaa !11
  %45 = call i64 @fwrite(ptr noundef nonnull %7, i64 noundef 4, i64 noundef 1, ptr noundef %8)
  %46 = add nuw nsw i32 %.135, 1
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %.lr.ph36, label %._crit_edge37.loopexit, !llvm.loop !17

._crit_edge37.loopexit:                           ; preds = %.lr.ph36
  %.pre42 = load i32, ptr %3, align 4, !tbaa !5
  br label %._crit_edge37

._crit_edge37:                                    ; preds = %._crit_edge37.loopexit, %.preheader
  %49 = phi i32 [ %.pre42, %._crit_edge37.loopexit ], [ %35, %.preheader ]
  %50 = phi i32 [ %47, %._crit_edge37.loopexit ], [ %36, %.preheader ]
  %51 = add nuw nsw i32 %.13038, 1
  %52 = icmp slt i32 %51, %49
  br i1 %52, label %.preheader, label %._crit_edge39, !llvm.loop !18

._crit_edge39:                                    ; preds = %._crit_edge37, %.preheader32.lr.ph, %6, %.preheader.lr.ph, %.preheader31
  %53 = tail call i32 @fclose(ptr noundef %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nofree 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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14, !16}
!16 = !{!"llvm.loop.unswitch.partial.disable"}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14, !16}


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