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

; 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.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 @_ZN7R2Image11SetPixelRGBEiiRK5RNRgb(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 8 dereferenceable(24) %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = getelementptr inbounds %class.R2Image, ptr %10, i32 0, i32 4
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = getelementptr inbounds %class.R2Image, ptr %10, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = mul nsw i32 %13, %15
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.R2Image, ptr %10, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = mul nsw i32 %17, %19
  %21 = add nsw i32 %16, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %12, i64 %22
  store ptr %23, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.R2Image, ptr %10, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !14
  switch i32 %25, label %82 [
    i32 1, label %26
    i32 2, label %33
    i32 3, label %42
    i32 4, label %61
  ]

26:                                               ; preds = %4
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = call noundef double @_ZNK5RNRgb9LuminanceEv(ptr noundef nonnull align 8 dereferenceable(24) %27)
  %29 = fmul double 2.550000e+02, %28
  %30 = fptoui double %29 to i8
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %9, align 8, !tbaa !5
  store i8 %30, ptr %31, align 1, !tbaa !15
  br label %82

33:                                               ; preds = %4
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call noundef double @_ZNK5RNRgb9LuminanceEv(ptr noundef nonnull align 8 dereferenceable(24) %34)
  %36 = fmul double 2.550000e+02, %35
  %37 = fptoui double %36 to i8
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %9, align 8, !tbaa !5
  store i8 %37, ptr %38, align 1, !tbaa !15
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i32 1
  store ptr %41, ptr %9, align 8, !tbaa !5
  store i8 -1, ptr %40, align 1, !tbaa !15
  br label %82

42:                                               ; preds = %4
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = call noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24) %43)
  %45 = fmul double 2.550000e+02, %44
  %46 = fptoui double %45 to i8
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %9, align 8, !tbaa !5
  store i8 %46, ptr %47, align 1, !tbaa !15
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = call noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24) %49)
  %51 = fmul double 2.550000e+02, %50
  %52 = fptoui double %51 to i8
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 1
  store ptr %54, ptr %9, align 8, !tbaa !5
  store i8 %52, ptr %53, align 1, !tbaa !15
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = call noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24) %55)
  %57 = fmul double 2.550000e+02, %56
  %58 = fptoui double %57 to i8
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i32 1
  store ptr %60, ptr %9, align 8, !tbaa !5
  store i8 %58, ptr %59, align 1, !tbaa !15
  br label %82

61:                                               ; preds = %4
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = call noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24) %62)
  %64 = fmul double 2.550000e+02, %63
  %65 = fptoui double %64 to i8
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i32 1
  store ptr %67, ptr %9, align 8, !tbaa !5
  store i8 %65, ptr %66, align 1, !tbaa !15
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = call noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24) %68)
  %70 = fmul double 2.550000e+02, %69
  %71 = fptoui double %70 to i8
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i32 1
  store ptr %73, ptr %9, align 8, !tbaa !5
  store i8 %71, ptr %72, align 1, !tbaa !15
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = call noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24) %74)
  %76 = fmul double 2.550000e+02, %75
  %77 = fptoui double %76 to i8
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i32 1
  store ptr %79, ptr %9, align 8, !tbaa !5
  store i8 %77, ptr %78, align 1, !tbaa !15
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i32 1
  store ptr %81, ptr %9, align 8, !tbaa !5
  store i8 -1, ptr %80, align 1, !tbaa !15
  br label %82

82:                                               ; preds = %61, %42, %33, %26, %4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

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

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

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

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

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 = { 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, !6, i64 16}
!12 = !{!"_ZTS7R2Image", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 8}
!15 = !{!7, !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 nounwind uwtable
define dso_local void @_ZN7R2Image11SetPixelRGBEiiRK5RNRgb(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 8 dereferenceable(24) %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = mul nsw i32 %8, %2
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = mul nsw i32 %11, %1
  %13 = add nsw i32 %12, %9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %6, i64 %14
  switch i32 %11, label %50 [
    i32 1, label %16
    i32 2, label %20
    i32 3, label %25
    i32 4, label %37
  ]

16:                                               ; preds = %4
  %17 = tail call noundef double @_ZNK5RNRgb9LuminanceEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %18 = fmul double %17, 2.550000e+02
  %19 = fptoui double %18 to i8
  store i8 %19, ptr %15, align 1, !tbaa !13
  br label %50

20:                                               ; preds = %4
  %21 = tail call noundef double @_ZNK5RNRgb9LuminanceEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %22 = fmul double %21, 2.550000e+02
  %23 = fptoui double %22 to i8
  %24 = getelementptr inbounds i8, ptr %15, i64 1
  store i8 %23, ptr %15, align 1, !tbaa !13
  store i8 -1, ptr %24, align 1, !tbaa !13
  br label %50

25:                                               ; preds = %4
  %26 = tail call noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %27 = fmul double %26, 2.550000e+02
  %28 = fptoui double %27 to i8
  %29 = getelementptr inbounds i8, ptr %15, i64 1
  store i8 %28, ptr %15, align 1, !tbaa !13
  %30 = tail call noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %31 = fmul double %30, 2.550000e+02
  %32 = fptoui double %31 to i8
  %33 = getelementptr inbounds i8, ptr %15, i64 2
  store i8 %32, ptr %29, align 1, !tbaa !13
  %34 = tail call noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %35 = fmul double %34, 2.550000e+02
  %36 = fptoui double %35 to i8
  store i8 %36, ptr %33, align 1, !tbaa !13
  br label %50

37:                                               ; preds = %4
  %38 = tail call noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %39 = fmul double %38, 2.550000e+02
  %40 = fptoui double %39 to i8
  %41 = getelementptr inbounds i8, ptr %15, i64 1
  store i8 %40, ptr %15, align 1, !tbaa !13
  %42 = tail call noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %43 = fmul double %42, 2.550000e+02
  %44 = fptoui double %43 to i8
  %45 = getelementptr inbounds i8, ptr %15, i64 2
  store i8 %44, ptr %41, align 1, !tbaa !13
  %46 = tail call noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %47 = fmul double %46, 2.550000e+02
  %48 = fptoui double %47 to i8
  %49 = getelementptr inbounds i8, ptr %15, i64 3
  store i8 %48, ptr %45, align 1, !tbaa !13
  store i8 -1, ptr %49, align 1, !tbaa !13
  br label %50

50:                                               ; preds = %37, %25, %20, %16, %4
  ret void
}

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

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

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

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

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

!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, !10, i64 16}
!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 = !{!6, !7, i64 12}
!12 = !{!6, !7, i64 8}
!13 = !{!8, !8, i64 0}


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