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

; 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"

%struct.Vector3 = type { %union.anon.0, float }
%union.anon.0 = type { [3 x float] }
%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 uwtable
define dso_local { <2 x float>, <2 x float> } @_ZN7Texture11getPixelValEff(ptr noundef nonnull align 8 dereferenceable(32) %0, float noundef %1, float noundef %2) #1 align 2 {
  %4 = alloca %struct.Vector3, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, 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
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %16 = load float, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = sub nsw i32 %18, 1
  %20 = sitofp i32 %19 to float
  %21 = fmul float %16, %20
  %22 = fptosi float %21 to i32
  store i32 %22, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %23 = load float, ptr %7, align 4, !tbaa !9
  %24 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = sub nsw i32 %25, 1
  %27 = sitofp i32 %26 to float
  %28 = fmul float %23, %27
  %29 = fptosi float %28 to i32
  store i32 %29, ptr %9, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %30 = load i32, ptr %8, align 4, !tbaa !14
  %31 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 4
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = sdiv i32 %30, %32
  store i32 %33, ptr %10, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %34 = load i32, ptr %9, align 4, !tbaa !14
  %35 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 5
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = sdiv i32 %34, %36
  store i32 %37, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %38 = load i32, ptr %8, align 4, !tbaa !14
  %39 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 4
  %40 = load i32, ptr %39, align 4, !tbaa !16
  %41 = srem i32 %38, %40
  store i32 %41, ptr %12, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %42 = load i32, ptr %9, align 4, !tbaa !14
  %43 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 5
  %44 = load i32, ptr %43, align 8, !tbaa !17
  %45 = srem i32 %42, %44
  store i32 %45, ptr %13, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %46 = load i32, ptr %11, align 4, !tbaa !14
  %47 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 6
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = mul nsw i32 %46, %48
  %50 = load i32, ptr %10, align 4, !tbaa !14
  %51 = add nsw i32 %49, %50
  %52 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 4
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 5
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = mul nsw i32 %53, %55
  %57 = mul nsw i32 %51, %56
  %58 = load i32, ptr %13, align 4, !tbaa !14
  %59 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 4
  %60 = load i32, ptr %59, align 4, !tbaa !16
  %61 = mul nsw i32 %58, %60
  %62 = add nsw i32 %57, %61
  %63 = load i32, ptr %12, align 4, !tbaa !14
  %64 = add nsw i32 %62, %63
  %65 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 3
  %66 = load i32, ptr %65, align 8, !tbaa !19
  %67 = mul nsw i32 %64, %66
  store i32 %67, ptr %14, align 4, !tbaa !14
  %68 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !20
  %70 = load i32, ptr %14, align 4, !tbaa !14
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds float, ptr %69, i64 %71
  %73 = load float, ptr %72, align 4, !tbaa !9
  %74 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !20
  %76 = load i32, ptr %14, align 4, !tbaa !14
  %77 = add nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds float, ptr %75, i64 %78
  %80 = load float, ptr %79, align 4, !tbaa !9
  %81 = getelementptr inbounds %class.Texture, ptr %15, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !20
  %83 = load i32, ptr %14, align 4, !tbaa !14
  %84 = add nsw i32 %83, 2
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds float, ptr %82, i64 %85
  %87 = load float, ptr %86, align 4, !tbaa !9
  call void @_ZN7Vector3IfEC2Efff(ptr noundef nonnull align 4 dereferenceable(16) %4, float noundef %73, float noundef %80, float noundef %87)
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %88 = load { <2 x float>, <2 x float> }, ptr %4, align 4
  ret { <2 x float>, <2 x float> } %88
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7Vector3IfEC2Efff(ptr noundef nonnull align 4 dereferenceable(16), float noundef, float noundef, float noundef) unnamed_addr #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 = { 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 = !{!"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, !13, i64 16}
!20 = !{!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"

%struct.Vector3 = type { %union.anon.0, float }
%union.anon.0 = type { [3 x float] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, <2 x float> } @_ZN7Texture11getPixelValEff(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0, float noundef %1, float noundef %2) local_unnamed_addr #0 align 2 {
  %4 = alloca %struct.Vector3, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = add nsw i32 %6, -1
  %8 = sitofp i32 %7 to float
  %9 = fmul float %8, %1
  %10 = fptosi float %9 to i32
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = add nsw i32 %12, -1
  %14 = sitofp i32 %13 to float
  %15 = fmul float %14, %2
  %16 = fptosi float %15 to i32
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %19 = sdiv i32 %10, %18
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = sdiv i32 %16, %21
  %23 = srem i32 %10, %18
  %24 = srem i32 %16, %21
  %25 = getelementptr inbounds i8, ptr %0, i64 28
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = mul nsw i32 %26, %22
  %28 = add nsw i32 %27, %19
  %29 = mul i32 %28, %21
  %reass.add = add i32 %29, %24
  %reass.mul = mul i32 %reass.add, %18
  %30 = add i32 %reass.mul, %23
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load i32, ptr %31, align 8, !tbaa !15
  %33 = mul nsw i32 %30, %32
  %34 = load ptr, ptr %0, align 8, !tbaa !16
  %35 = sext i32 %33 to i64
  %36 = getelementptr inbounds float, ptr %34, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !17
  %38 = getelementptr i8, ptr %36, i64 4
  %39 = load float, ptr %38, align 4, !tbaa !17
  %40 = getelementptr i8, ptr %36, i64 8
  %41 = load float, ptr %40, align 4, !tbaa !17
  call void @_ZN7Vector3IfEC2Efff(ptr noundef nonnull align 4 dereferenceable(16) %4, float noundef %37, float noundef %39, float noundef %41)
  %.fca.0.load = load <2 x float>, ptr %4, align 8
  %.fca.0.insert = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> %.fca.0.load, 0
  %.fca.1.gep = getelementptr inbounds i8, ptr %4, i64 8
  %.fca.1.load = load <2 x float>, ptr %.fca.1.gep, align 8
  %.fca.1.insert = insertvalue { <2 x float>, <2 x float> } %.fca.0.insert, <2 x float> %.fca.1.load, 1
  ret { <2 x float>, <2 x float> } %.fca.1.insert
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7Vector3IfEC2Efff(ptr noundef nonnull align 4 dereferenceable(16), float noundef, float noundef, float noundef) unnamed_addr #0 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" }

!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, !10, i64 16}
!16 = !{!6, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !8, i64 0}


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