; LLVM IR from Angelo1211/SoftwareRenderer :: src/texture.ll (ZN7Texture15getIntensityValEff)

; 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.Texture = type { ptr, i32, i32, i32, i32, i32, i32 }

; 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 nounwind uwtable
define dso_local noundef float @_ZN7Texture15getIntensityValEff(ptr noundef nonnull align 8 dereferenceable(32) %0, float noundef %1, float noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load float, ptr %5, align 4, !tbaa !9
  %16 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = sub nsw i32 %17, 1
  %19 = sitofp i32 %18 to float
  %20 = fmul float %15, %19
  %21 = fptosi float %20 to i32
  store i32 %21, ptr %7, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %22 = load float, ptr %6, align 4, !tbaa !9
  %23 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = sub nsw i32 %24, 1
  %26 = sitofp i32 %25 to float
  %27 = fmul float %22, %26
  %28 = fptosi float %27 to i32
  store i32 %28, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %29 = load i32, ptr %7, align 4, !tbaa !14
  %30 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 4
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = sdiv i32 %29, %31
  store i32 %32, ptr %9, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %33 = load i32, ptr %8, align 4, !tbaa !14
  %34 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 5
  %35 = load i32, ptr %34, align 8, !tbaa !17
  %36 = sdiv i32 %33, %35
  store i32 %36, ptr %10, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %37 = load i32, ptr %7, align 4, !tbaa !14
  %38 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 4
  %39 = load i32, ptr %38, align 4, !tbaa !16
  %40 = srem i32 %37, %39
  store i32 %40, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %41 = load i32, ptr %8, align 4, !tbaa !14
  %42 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 5
  %43 = load i32, ptr %42, align 8, !tbaa !17
  %44 = srem i32 %41, %43
  store i32 %44, ptr %12, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %45 = load i32, ptr %10, align 4, !tbaa !14
  %46 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 6
  %47 = load i32, ptr %46, align 4, !tbaa !18
  %48 = mul nsw i32 %45, %47
  %49 = load i32, ptr %9, align 4, !tbaa !14
  %50 = add nsw i32 %48, %49
  %51 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 4
  %52 = load i32, ptr %51, align 4, !tbaa !16
  %53 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 5
  %54 = load i32, ptr %53, align 8, !tbaa !17
  %55 = mul nsw i32 %52, %54
  %56 = mul nsw i32 %50, %55
  %57 = load i32, ptr %12, align 4, !tbaa !14
  %58 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 4
  %59 = load i32, ptr %58, align 4, !tbaa !16
  %60 = mul nsw i32 %57, %59
  %61 = add nsw i32 %56, %60
  %62 = load i32, ptr %11, align 4, !tbaa !14
  %63 = add nsw i32 %61, %62
  store i32 %63, ptr %13, align 4, !tbaa !14
  %64 = getelementptr inbounds %class.Texture, ptr %14, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  %66 = load i32, ptr %13, align 4, !tbaa !14
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds float, ptr %65, i64 %67
  %69 = load float, ptr %68, align 4, !tbaa !9
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret float %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS7Texture", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 12}
!16 = !{!12, !13, i64 20}
!17 = !{!12, !13, i64 24}
!18 = !{!12, !13, i64 28}
!19 = !{!12, !6, 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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef float @_ZN7Texture15getIntensityValEff(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0, float noundef %1, float noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = add nsw i32 %5, -1
  %7 = sitofp i32 %6 to float
  %8 = fmul float %7, %1
  %9 = fptosi float %8 to i32
  %10 = getelementptr inbounds i8, ptr %0, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = add nsw i32 %11, -1
  %13 = sitofp i32 %12 to float
  %14 = fmul float %13, %2
  %15 = fptosi float %14 to i32
  %16 = getelementptr inbounds i8, ptr %0, i64 20
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = sdiv i32 %9, %17
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = sdiv i32 %15, %20
  %22 = srem i32 %9, %17
  %23 = srem i32 %15, %20
  %24 = getelementptr inbounds i8, ptr %0, i64 28
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = mul nsw i32 %25, %21
  %27 = add nsw i32 %26, %18
  %28 = mul i32 %27, %20
  %reass.add = add i32 %28, %23
  %reass.mul = mul i32 %reass.add, %17
  %29 = add i32 %reass.mul, %22
  %30 = load ptr, ptr %0, align 8, !tbaa !15
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds float, ptr %30, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !16
  ret float %33
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 8}
!6 = !{!"_ZTS7Texture", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !10, i64 20}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !10, i64 28}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !8, i64 0}


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