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

; 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.15 = external hidden unnamed_addr constant [18 x i8], align 1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6R2Grid8ConvolveEPA3_Kd(ptr noundef nonnull align 8 dereferenceable(208), ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid8GradientEi(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [3 x [3 x double]], align 16
  %6 = alloca [3 x [3 x double]], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 72, ptr %5) #4
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 72, i1 false)
  %8 = getelementptr inbounds [3 x [3 x double]], ptr %5, i32 0, i32 0
  %9 = getelementptr inbounds [3 x double], ptr %8, i32 0, i32 0
  store double -2.500000e-01, ptr %9, align 16
  %10 = getelementptr inbounds [3 x double], ptr %8, i32 0, i32 2
  store double 2.500000e-01, ptr %10, align 16
  %11 = getelementptr inbounds [3 x [3 x double]], ptr %5, i32 0, i32 1
  %12 = getelementptr inbounds [3 x double], ptr %11, i32 0, i32 0
  store double -5.000000e-01, ptr %12, align 8
  %13 = getelementptr inbounds [3 x double], ptr %11, i32 0, i32 2
  store double 5.000000e-01, ptr %13, align 8
  %14 = getelementptr inbounds [3 x [3 x double]], ptr %5, i32 0, i32 2
  %15 = getelementptr inbounds [3 x double], ptr %14, i32 0, i32 0
  store double -2.500000e-01, ptr %15, align 16
  %16 = getelementptr inbounds [3 x double], ptr %14, i32 0, i32 2
  store double 2.500000e-01, ptr %16, align 16
  call void @llvm.lifetime.start.p0(i64 72, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 72, i1 false)
  %17 = getelementptr inbounds [3 x [3 x double]], ptr %6, i32 0, i32 0
  %18 = getelementptr inbounds [3 x double], ptr %17, i32 0, i32 0
  store double -2.500000e-01, ptr %18, align 16
  %19 = getelementptr inbounds [3 x double], ptr %17, i32 0, i32 1
  store double -5.000000e-01, ptr %19, align 8
  %20 = getelementptr inbounds [3 x double], ptr %17, i32 0, i32 2
  store double -2.500000e-01, ptr %20, align 16
  %21 = getelementptr inbounds [3 x [3 x double]], ptr %6, i32 0, i32 2
  %22 = getelementptr inbounds [3 x double], ptr %21, i32 0, i32 0
  store double 2.500000e-01, ptr %22, align 16
  %23 = getelementptr inbounds [3 x double], ptr %21, i32 0, i32 1
  store double 5.000000e-01, ptr %23, align 8
  %24 = getelementptr inbounds [3 x double], ptr %21, i32 0, i32 2
  store double 2.500000e-01, ptr %24, align 16
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %2
  %28 = getelementptr inbounds [3 x [3 x double]], ptr %5, i64 0, i64 0
  call void @_ZN6R2Grid8ConvolveEPA3_Kd(ptr noundef nonnull align 8 dereferenceable(208) %7, ptr noundef %28)
  br label %36

29:                                               ; preds = %2
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = getelementptr inbounds [3 x [3 x double]], ptr %6, i64 0, i64 0
  call void @_ZN6R2Grid8ConvolveEPA3_Kd(ptr noundef nonnull align 8 dereferenceable(208) %7, ptr noundef %33)
  br label %35

34:                                               ; preds = %29
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str.15)
  br label %35

35:                                               ; preds = %34, %32
  br label %36

36:                                               ; preds = %35, %27
  call void @llvm.lifetime.end.p0(i64 72, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %5) #4
  ret void
}

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

@.str.15 = external hidden unnamed_addr constant [18 x i8], align 1

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6R2Grid8ConvolveEPA3_Kd(ptr noundef nonnull align 8 dereferenceable(208), ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid8GradientEi(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %1) local_unnamed_addr #3 align 2 {
  %3 = alloca [3 x [3 x double]], align 16
  %4 = alloca [3 x [3 x double]], align 16
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(72) %3, i8 0, i64 64, i1 false)
  store double -2.500000e-01, ptr %3, align 16
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  store <2 x double> <double 2.500000e-01, double -5.000000e-01>, ptr %5, align 16
  %6 = getelementptr inbounds i8, ptr %3, i64 40
  store <2 x double> <double 5.000000e-01, double -2.500000e-01>, ptr %6, align 8
  %7 = getelementptr inbounds i8, ptr %3, i64 64
  store double 2.500000e-01, ptr %7, align 16
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %4) #4
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(72) %8, i8 0, i64 32, i1 false)
  store <2 x double> <double -2.500000e-01, double -5.000000e-01>, ptr %4, align 16
  %9 = getelementptr inbounds i8, ptr %4, i64 16
  store double -2.500000e-01, ptr %9, align 16
  %10 = getelementptr inbounds i8, ptr %4, i64 48
  store <2 x double> <double 2.500000e-01, double 5.000000e-01>, ptr %10, align 16
  %11 = getelementptr inbounds i8, ptr %4, i64 64
  store double 2.500000e-01, ptr %11, align 16
  switch i32 %1, label %14 [
    i32 0, label %12
    i32 1, label %13
  ]

12:                                               ; preds = %2
  call void @_ZN6R2Grid8ConvolveEPA3_Kd(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef nonnull %3)
  br label %15

13:                                               ; preds = %2
  call void @_ZN6R2Grid8ConvolveEPA3_Kd(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef nonnull %4)
  br label %15

14:                                               ; preds = %2
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str.15)
  br label %15

15:                                               ; preds = %13, %14, %12
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #4
  ret void
}

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


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