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

; 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.RNRgb = type { [3 x double] }
%class.R2Image = type { i32, i32, i32, i32, ptr }

; 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
define dso_local void @_ZNK7R2Image8PixelRGBEii(ptr dead_on_unwind noalias writable sret(%class.RNRgb) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %2, i32 noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %13, i32 noundef %14, i32 noundef %15)
  store ptr %16, ptr %12, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.R2Image, ptr %13, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !11
  switch i32 %18, label %46 [
    i32 1, label %19
    i32 2, label %19
    i32 3, label %27
    i32 4, label %27
  ]

19:                                               ; preds = %4, %4
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i32 1
  store ptr %21, ptr %12, align 8, !tbaa !5
  %22 = load i8, ptr %20, align 1, !tbaa !13
  %23 = zext i8 %22 to i32
  %24 = sitofp i32 %23 to double
  %25 = fdiv double %24, 2.550000e+02
  store double %25, ptr %9, align 8, !tbaa !14
  %26 = load double, ptr %9, align 8, !tbaa !14
  store double %26, ptr %11, align 8, !tbaa !14
  store double %26, ptr %10, align 8, !tbaa !14
  br label %47

27:                                               ; preds = %4, %4
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i32 1
  store ptr %29, ptr %12, align 8, !tbaa !5
  %30 = load i8, ptr %28, align 1, !tbaa !13
  %31 = zext i8 %30 to i32
  %32 = sitofp i32 %31 to double
  %33 = fdiv double %32, 2.550000e+02
  store double %33, ptr %9, align 8, !tbaa !14
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i32 1
  store ptr %35, ptr %12, align 8, !tbaa !5
  %36 = load i8, ptr %34, align 1, !tbaa !13
  %37 = zext i8 %36 to i32
  %38 = sitofp i32 %37 to double
  %39 = fdiv double %38, 2.550000e+02
  store double %39, ptr %10, align 8, !tbaa !14
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i32 1
  store ptr %41, ptr %12, align 8, !tbaa !5
  %42 = load i8, ptr %40, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = sitofp i32 %43 to double
  %45 = fdiv double %44, 2.550000e+02
  store double %45, ptr %11, align 8, !tbaa !14
  br label %47

46:                                               ; preds = %4
  store double 0.000000e+00, ptr %10, align 8, !tbaa !14
  store double 0.000000e+00, ptr %11, align 8, !tbaa !14
  store double 0.000000e+00, ptr %9, align 8, !tbaa !14
  br label %47

47:                                               ; preds = %46, %27, %19
  %48 = load double, ptr %9, align 8, !tbaa !14
  %49 = load double, ptr %10, align 8, !tbaa !14
  %50 = load double, ptr %11, align 8, !tbaa !14
  call void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24) %0, double noundef %48, double noundef %49, double noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) #2 align 2

declare void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24), double noundef, double noundef, double noundef) unnamed_addr #3

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 = { inlinehint mustprogress 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 = { "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}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS7R2Image", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"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"

%class.RNRgb = type { [3 x double] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7R2Image8PixelRGBEii(ptr dead_on_unwind noalias writable sret(%class.RNRgb) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = tail call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %2, i32 noundef %3)
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  switch i32 %7, label %22 [
    i32 1, label %8
    i32 2, label %8
    i32 3, label %14
    i32 4, label %14
  ]

8:                                                ; preds = %4, %4
  %9 = load i8, ptr %5, align 1, !tbaa !11
  %10 = uitofp i8 %9 to double
  %11 = fdiv double %10, 2.550000e+02
  %12 = insertelement <2 x double> poison, double %11, i64 0
  %13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> zeroinitializer
  br label %22

14:                                               ; preds = %4, %4
  %15 = getelementptr inbounds i8, ptr %5, i64 1
  %16 = load i8, ptr %5, align 1, !tbaa !11
  %17 = uitofp i8 %16 to double
  %18 = fdiv double %17, 2.550000e+02
  %19 = load <2 x i8>, ptr %15, align 1, !tbaa !11
  %20 = uitofp <2 x i8> %19 to <2 x double>
  %21 = fdiv <2 x double> %20, <double 2.550000e+02, double 2.550000e+02>
  br label %22

22:                                               ; preds = %4, %14, %8
  %.011 = phi double [ %18, %14 ], [ %11, %8 ], [ 0.000000e+00, %4 ]
  %23 = phi <2 x double> [ %21, %14 ], [ %13, %8 ], [ zeroinitializer, %4 ]
  %24 = extractelement <2 x double> %23, i64 0
  %25 = extractelement <2 x double> %23, i64 1
  tail call void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24) %0, double noundef %.011, double noundef %24, double noundef %25)
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

declare void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24), double noundef, double noundef, double noundef) unnamed_addr #2

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


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