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

; 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.TGLPixelShaderSimple = type { %struct.TGLPixFmt, 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: nounwind uwtable
define dso_local void @tgl_pixel_shader_simple(i8 noundef zeroext %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %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
  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
  %12 = load ptr, ptr %10, align 8, !tbaa !8
  store ptr %12, ptr %11, align 8, !tbaa !8
  %13 = load ptr, ptr %8, align 8, !tbaa !8
  %14 = load ptr, ptr %11, align 8, !tbaa !8
  %15 = getelementptr inbounds %struct.TGLPixelShaderSimple, ptr %14, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %13, ptr align 8 %15, i64 8, i1 false), !tbaa.struct !10
  %16 = load ptr, ptr %11, align 8, !tbaa !8
  %17 = getelementptr inbounds %struct.TGLPixelShaderSimple, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load i8, ptr %6, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = load i8, ptr %7, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = add nsw i32 %20, %22
  %24 = trunc i32 %23 to i8
  %25 = call signext i8 @tgl_grad_char(ptr noundef %18, i8 noundef zeroext %24)
  %26 = load ptr, ptr %9, align 8, !tbaa !8
  store i8 %25, ptr %26, align 1, !tbaa !5
  %27 = load i8, ptr %7, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

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

; 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) #2

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @tgl_grad_char(ptr noundef, i8 noundef zeroext) #0

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 1, !5, i64 1, i64 3, !5, i64 4, i64 1, !5, i64 5, i64 3, !5}
!11 = !{!12, !9, i64 8}
!12 = !{!"TGLPixelShaderSimple", !13, i64 0, !9, i64 8}
!13 = !{!"TGLPixFmt", !14, i64 0, !14, i64 4}
!14 = !{!"TGLFmt", !6, i64 0, !6, i64 1}


; 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: nounwind uwtable
define dso_local void @tgl_pixel_shader_simple(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 = load i64, ptr %4, align 8
  store i64 %6, ptr %2, align 1
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = add i8 %1, %0
  %10 = tail call signext i8 @tgl_grad_char(ptr noundef %8, i8 noundef zeroext %9)
  store i8 %10, ptr %3, align 1, !tbaa !12
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @tgl_grad_char(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

attributes #0 = { 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, !11, i64 8}
!6 = !{!"TGLPixelShaderSimple", !7, i64 0, !11, i64 8}
!7 = !{!"TGLPixFmt", !8, i64 0, !8, i64 4}
!8 = !{!"TGLFmt", !9, i64 0, !9, i64 1}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!9, !9, i64 0}


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