; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Grid.ll (ZN6R2Grid18RasterizeGridPointEdddi)

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

%class.R2Grid = type { %class.R2Affine, %class.R2Affine, double, ptr, [2 x i32], i32, i32 }
%class.R2Affine = type <{ %class.R2Transformation, %class.R3Matrix, i32, [4 x i8] }>
%class.R2Transformation = type { ptr }
%class.R3Matrix = type { [3 x [3 x double]] }

; 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 uwtable
declare dso_local void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef, double noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid18RasterizeGridPointEdddi(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1, double noundef %2, double noundef %3, i32 noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !9
  store double %2, ptr %8, align 8, !tbaa !9
  store double %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  %17 = load ptr, ptr %6, align 8
  %18 = load double, ptr %7, align 8, !tbaa !9
  %19 = fcmp olt double %18, 0.000000e+00
  br i1 %19, label %28, label %20

20:                                               ; preds = %5
  %21 = load double, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds %class.R2Grid, ptr %17, i32 0, i32 4
  %23 = getelementptr inbounds [2 x i32], ptr %22, i64 0, i64 0
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = sub nsw i32 %24, 1
  %26 = sitofp i32 %25 to double
  %27 = fcmp ogt double %21, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %20, %5
  br label %110

29:                                               ; preds = %20
  %30 = load double, ptr %8, align 8, !tbaa !9
  %31 = fcmp olt double %30, 0.000000e+00
  br i1 %31, label %40, label %32

32:                                               ; preds = %29
  %33 = load double, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds %class.R2Grid, ptr %17, i32 0, i32 4
  %35 = getelementptr inbounds [2 x i32], ptr %34, i64 0, i64 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = sub nsw i32 %36, 1
  %38 = sitofp i32 %37 to double
  %39 = fcmp ogt double %33, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %32, %29
  br label %110

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %42 = load double, ptr %7, align 8, !tbaa !9
  %43 = fptosi double %42 to i32
  store i32 %43, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %44 = load double, ptr %8, align 8, !tbaa !9
  %45 = fptosi double %44 to i32
  store i32 %45, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %46 = load i32, ptr %11, align 4, !tbaa !11
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %48 = load i32, ptr %12, align 4, !tbaa !11
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %14, align 4, !tbaa !11
  %50 = load i32, ptr %13, align 4, !tbaa !11
  %51 = getelementptr inbounds %class.R2Grid, ptr %17, i32 0, i32 4
  %52 = getelementptr inbounds [2 x i32], ptr %51, i64 0, i64 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = icmp sge i32 %50, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %41
  %56 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %56, ptr %13, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %55, %41
  %58 = load i32, ptr %14, align 4, !tbaa !11
  %59 = getelementptr inbounds %class.R2Grid, ptr %17, i32 0, i32 4
  %60 = getelementptr inbounds [2 x i32], ptr %59, i64 0, i64 1
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = icmp sge i32 %58, %61
  br i1 %62, label %63, label %65

63:                                               ; preds = %57
  %64 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %64, ptr %14, align 4, !tbaa !11
  br label %65

65:                                               ; preds = %63, %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %66 = load double, ptr %7, align 8, !tbaa !9
  %67 = load i32, ptr %11, align 4, !tbaa !11
  %68 = sitofp i32 %67 to double
  %69 = fsub double %66, %68
  store double %69, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  %70 = load double, ptr %8, align 8, !tbaa !9
  %71 = load i32, ptr %12, align 4, !tbaa !11
  %72 = sitofp i32 %71 to double
  %73 = fsub double %70, %72
  store double %73, ptr %16, align 8, !tbaa !9
  %74 = load i32, ptr %11, align 4, !tbaa !11
  %75 = load i32, ptr %12, align 4, !tbaa !11
  %76 = load double, ptr %9, align 8, !tbaa !9
  %77 = load double, ptr %15, align 8, !tbaa !9
  %78 = fsub double 1.000000e+00, %77
  %79 = fmul double %76, %78
  %80 = load double, ptr %16, align 8, !tbaa !9
  %81 = fsub double 1.000000e+00, %80
  %82 = fmul double %79, %81
  %83 = load i32, ptr %10, align 4, !tbaa !11
  call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %17, i32 noundef %74, i32 noundef %75, double noundef %82, i32 noundef %83)
  %84 = load i32, ptr %11, align 4, !tbaa !11
  %85 = load i32, ptr %14, align 4, !tbaa !11
  %86 = load double, ptr %9, align 8, !tbaa !9
  %87 = load double, ptr %15, align 8, !tbaa !9
  %88 = fsub double 1.000000e+00, %87
  %89 = fmul double %86, %88
  %90 = load double, ptr %16, align 8, !tbaa !9
  %91 = fmul double %89, %90
  %92 = load i32, ptr %10, align 4, !tbaa !11
  call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %17, i32 noundef %84, i32 noundef %85, double noundef %91, i32 noundef %92)
  %93 = load i32, ptr %13, align 4, !tbaa !11
  %94 = load i32, ptr %12, align 4, !tbaa !11
  %95 = load double, ptr %9, align 8, !tbaa !9
  %96 = load double, ptr %15, align 8, !tbaa !9
  %97 = fmul double %95, %96
  %98 = load double, ptr %16, align 8, !tbaa !9
  %99 = fsub double 1.000000e+00, %98
  %100 = fmul double %97, %99
  %101 = load i32, ptr %10, align 4, !tbaa !11
  call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %17, i32 noundef %93, i32 noundef %94, double noundef %100, i32 noundef %101)
  %102 = load i32, ptr %13, align 4, !tbaa !11
  %103 = load i32, ptr %14, align 4, !tbaa !11
  %104 = load double, ptr %9, align 8, !tbaa !9
  %105 = load double, ptr %15, align 8, !tbaa !9
  %106 = fmul double %104, %105
  %107 = load double, ptr %16, align 8, !tbaa !9
  %108 = fmul double %106, %107
  %109 = load i32, ptr %10, align 4, !tbaa !11
  call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %17, i32 noundef %102, i32 noundef %103, double noundef %108, i32 noundef %109)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %110

110:                                              ; preds = %65, %40, %28
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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: mustprogress uwtable
declare dso_local void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef, double noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid18RasterizeGridPointEdddi(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1, double noundef %2, double noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = fcmp olt double %1, 0.000000e+00
  br i1 %6, label %37, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 192
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = add nsw i32 %9, -1
  %11 = sitofp i32 %10 to double
  %12 = fcmp olt double %11, %1
  %13 = fcmp olt double %2, 0.000000e+00
  %or.cond = or i1 %13, %12
  br i1 %or.cond, label %37, label %14

14:                                               ; preds = %7
  %15 = getelementptr inbounds i8, ptr %0, i64 196
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  %18 = sitofp i32 %17 to double
  %19 = fcmp olt double %18, %2
  br i1 %19, label %37, label %20

20:                                               ; preds = %14
  %21 = fptosi double %1 to i32
  %22 = fptosi double %2 to i32
  %23 = add nsw i32 %21, 1
  %24 = add nsw i32 %22, 1
  %.not = icmp slt i32 %23, %9
  %spec.select = select i1 %.not, i32 %23, i32 %21
  %.not46 = icmp slt i32 %24, %16
  %.041 = select i1 %.not46, i32 %24, i32 %22
  %25 = sitofp i32 %21 to double
  %26 = fsub double %1, %25
  %27 = sitofp i32 %22 to double
  %28 = fsub double %2, %27
  %29 = fsub double 1.000000e+00, %26
  %30 = fmul double %29, %3
  %31 = fsub double 1.000000e+00, %28
  %32 = fmul double %30, %31
  tail call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %21, i32 noundef %22, double noundef %32, i32 noundef %4)
  %33 = fmul double %28, %30
  tail call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %21, i32 noundef %.041, double noundef %33, i32 noundef %4)
  %34 = fmul double %26, %3
  %35 = fmul double %34, %31
  tail call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %spec.select, i32 noundef %22, double noundef %35, i32 noundef %4)
  %36 = fmul double %34, %28
  tail call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %spec.select, i32 noundef %.041, double noundef %36, i32 noundef %4)
  br label %37

37:                                               ; preds = %14, %5, %7, %20
  ret void
}

attributes #0 = { 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" }

!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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass