; LLVM IR from wojciech-graj/TermGL :: termgl (tgl_pixel_shader_texture)

; 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.TGLPixelShaderTexture = type { i8, i8, ptr, ptr }
%struct.TGLPixFmt = type { %struct.TGLFmt, %struct.TGLFmt }
%struct.TGLFmt = type { i8, %union.TGLFmtColor }
%union.TGLFmtColor = type { %struct.TGLRGB }
%struct.TGLRGB = type { i8, i8, i8 }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @tgl_pixel_shader_texture(i8 noundef zeroext %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i8 %0, ptr %6, align 1, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !8
  store ptr %3, ptr %9, align 8, !tbaa !8
  store ptr %4, ptr %10, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load ptr, ptr %10, align 8, !tbaa !8
  store ptr %13, ptr %11, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %14 = load i8, ptr %6, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = load ptr, ptr %11, align 8, !tbaa !8
  %17 = getelementptr inbounds %struct.TGLPixelShaderTexture, ptr %16, i32 0, i32 0
  %18 = load i8, ptr %17, align 8, !tbaa !10
  %19 = zext i8 %18 to i32
  %20 = mul nsw i32 %15, %19
  %21 = sdiv i32 %20, 256
  %22 = load ptr, ptr %11, align 8, !tbaa !8
  %23 = getelementptr inbounds %struct.TGLPixelShaderTexture, ptr %22, i32 0, i32 0
  %24 = load i8, ptr %23, align 8, !tbaa !10
  %25 = zext i8 %24 to i32
  %26 = load i8, ptr %7, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  %28 = load ptr, ptr %11, align 8, !tbaa !8
  %29 = getelementptr inbounds %struct.TGLPixelShaderTexture, ptr %28, i32 0, i32 1
  %30 = load i8, ptr %29, align 1, !tbaa !12
  %31 = zext i8 %30 to i32
  %32 = mul nsw i32 %27, %31
  %33 = sdiv i32 %32, 256
  %34 = mul nsw i32 %25, %33
  %35 = add nsw i32 %21, %34
  store i32 %35, ptr %12, align 4, !tbaa !13
  %36 = load ptr, ptr %8, align 8, !tbaa !8
  %37 = load ptr, ptr %11, align 8, !tbaa !8
  %38 = getelementptr inbounds %struct.TGLPixelShaderTexture, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = load i32, ptr %12, align 4, !tbaa !13
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds %struct.TGLPixFmt, ptr %39, i64 %41
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr align 1 %42, i64 8, i1 false), !tbaa.struct !16
  %43 = load ptr, ptr %11, align 8, !tbaa !8
  %44 = getelementptr inbounds %struct.TGLPixelShaderTexture, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load i32, ptr %12, align 4, !tbaa !13
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !8
  store i8 %49, ptr %50, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"TGLPixelShaderTexture", !6, i64 0, !6, i64 1, !9, i64 8, !9, i64 16}
!12 = !{!11, !6, i64 1}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !6, i64 0}
!15 = !{!11, !9, i64 16}
!16 = !{i64 0, i64 1, !5, i64 1, i64 3, !5, i64 4, i64 1, !5, i64 5, i64 3, !5}
!17 = !{!11, !9, i64 8}


; 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.TGLPixFmt = type { %struct.TGLFmt, %struct.TGLFmt }
%struct.TGLFmt = type { i8, %union.TGLFmtColor }
%union.TGLFmtColor = type { %struct.TGLRGB }
%struct.TGLRGB = type { i8, i8, i8 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @tgl_pixel_shader_texture(i8 noundef zeroext %0, i8 noundef zeroext %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = zext i8 %0 to i32
  %7 = load i8, ptr %4, align 8, !tbaa !5
  %8 = zext i8 %7 to i32
  %9 = mul nuw nsw i32 %8, %6
  %10 = lshr i32 %9, 8
  %11 = zext i8 %1 to i32
  %12 = getelementptr inbounds i8, ptr %4, i64 1
  %13 = load i8, ptr %12, align 1, !tbaa !10
  %14 = zext i8 %13 to i32
  %15 = mul nuw nsw i32 %14, %11
  %16 = lshr i32 %15, 8
  %17 = mul nuw nsw i32 %16, %8
  %18 = add nuw nsw i32 %17, %10
  %19 = getelementptr inbounds i8, ptr %4, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = zext nneg i32 %18 to i64
  %22 = getelementptr inbounds %struct.TGLPixFmt, ptr %20, i64 %21
  %23 = load i64, ptr %22, align 1
  store i64 %23, ptr %2, align 1
  %24 = getelementptr inbounds i8, ptr %4, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %25, i64 %21
  %27 = load i8, ptr %26, align 1, !tbaa !13
  store i8 %27, ptr %3, align 1, !tbaa !13
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, 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, !7, i64 0}
!6 = !{!"TGLPixelShaderTexture", !7, i64 0, !7, i64 1, !9, i64 8, !9, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!6, !7, i64 1}
!11 = !{!6, !9, i64 16}
!12 = !{!6, !9, i64 8}
!13 = !{!7, !7, i64 0}


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