; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3Grid.ll (ZN6R3Grid18RasterizeGridValueEiiidi)

; 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.R3Grid = type { %class.R3Affine, %class.R3Affine, double, double, ptr, [3 x i32], i32, i32, i32 }
%class.R3Affine = type { %class.R3Transformation, %class.R4Matrix, %class.R4Matrix, %class.RNFlags }
%class.R3Transformation = type { ptr }
%class.R4Matrix = type { [4 x [4 x double]] }
%class.RNFlags = type { i64 }

@.str.31 = external hidden unnamed_addr constant [43 x i8], align 1

declare void @_Z7RNAbortPKcz(ptr noundef, ...) #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592), i32 noundef, i32 noundef, i32 noundef, double noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Grid18RasterizeGridValueEiiidi(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4, i32 noundef %5) #2 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store double %4, ptr %11, align 8, !tbaa !11
  store i32 %5, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %23, label %16

16:                                               ; preds = %6
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.R3Grid, ptr %13, i32 0, i32 5
  %19 = getelementptr inbounds [3 x i32], ptr %18, i64 0, i64 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = icmp sgt i32 %17, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %16, %6
  br label %74

24:                                               ; preds = %16
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %34, label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = getelementptr inbounds %class.R3Grid, ptr %13, i32 0, i32 5
  %30 = getelementptr inbounds [3 x i32], ptr %29, i64 0, i64 1
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = sub nsw i32 %31, 1
  %33 = icmp sgt i32 %28, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %27, %24
  br label %74

35:                                               ; preds = %27
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %45, label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = getelementptr inbounds %class.R3Grid, ptr %13, i32 0, i32 5
  %41 = getelementptr inbounds [3 x i32], ptr %40, i64 0, i64 2
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = sub nsw i32 %42, 1
  %44 = icmp sgt i32 %39, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %38, %35
  br label %74

46:                                               ; preds = %38
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %46
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = load double, ptr %11, align 8, !tbaa !11
  call void @_ZN6R3Grid12AddGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %13, i32 noundef %50, i32 noundef %51, i32 noundef %52, double noundef %53)
  br label %74

54:                                               ; preds = %46
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 1
  br i1 %56, label %57, label %63

57:                                               ; preds = %54
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = load double, ptr %11, align 8, !tbaa !11
  %62 = fneg double %61
  call void @_ZN6R3Grid12AddGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %13, i32 noundef %58, i32 noundef %59, i32 noundef %60, double noundef %62)
  br label %73

63:                                               ; preds = %54
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = icmp eq i32 %64, 2
  br i1 %65, label %66, label %71

66:                                               ; preds = %63
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = load double, ptr %11, align 8, !tbaa !11
  call void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %13, i32 noundef %67, i32 noundef %68, i32 noundef %69, double noundef %70)
  br label %72

71:                                               ; preds = %63
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str.31)
  br label %72

72:                                               ; preds = %71, %66
  br label %73

73:                                               ; preds = %72, %57
  br label %74

74:                                               ; preds = %73, %49, %45, %34, %23
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid12AddGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592), i32 noundef, i32 noundef, i32 noundef, double noundef) #1 align 2

attributes #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 = { inlinehint 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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"

@.str.31 = external hidden unnamed_addr constant [43 x i8], align 1

declare void @_Z7RNAbortPKcz(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592), i32 noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Grid18RasterizeGridValueEiiidi(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4, i32 noundef %5) local_unnamed_addr #2 align 2 {
  %7 = icmp slt i32 %1, 0
  br i1 %7, label %26, label %8

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 568
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = icmp sle i32 %10, %1
  %12 = icmp slt i32 %2, 0
  %or.cond = or i1 %12, %11
  br i1 %or.cond, label %26, label %13

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 572
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, %2
  %17 = icmp sgt i32 %3, -1
  %or.cond3.not31 = and i1 %17, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 576
  %19 = load i32, ptr %18, align 8
  %.not = icmp sgt i32 %19, %3
  %or.cond28 = select i1 %or.cond3.not31, i1 %.not, i1 false
  br i1 %or.cond28, label %20, label %26

20:                                               ; preds = %13
  switch i32 %5, label %25 [
    i32 0, label %21
    i32 1, label %22
    i32 2, label %24
  ]

21:                                               ; preds = %20
  tail call void @_ZN6R3Grid12AddGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4)
  br label %26

22:                                               ; preds = %20
  %23 = fneg double %4
  tail call void @_ZN6R3Grid12AddGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %23)
  br label %26

24:                                               ; preds = %20
  tail call void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4)
  br label %26

25:                                               ; preds = %20
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str.31)
  br label %26

26:                                               ; preds = %22, %25, %24, %13, %6, %8, %21
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid12AddGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592), i32 noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #1 align 2

attributes #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 = { inlinehint 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 = { 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,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass