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

; 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.Pixel = type { i8, %struct.TGLPixFmt }
%struct.TGLPixFmt = type { %struct.TGLFmt, %struct.TGLFmt }
%struct.TGLFmt = type { i8, %union.TGLFmtColor }
%union.TGLFmtColor = type { %struct.TGLRGB }
%struct.TGLRGB = type { i8, i8, i8 }
%struct.TGL = type { i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, 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_clear(ptr noundef %0, i8 noundef zeroext %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca %struct.Pixel, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %7 = load i8, ptr %4, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = and i32 %8, 1
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %35

11:                                               ; preds = %2
  store i32 0, ptr %5, align 4, !tbaa !10
  br label %12

12:                                               ; preds = %31, %11
  %13 = load i32, ptr %5, align 4, !tbaa !10
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TGL, ptr %14, i32 0, i32 4
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = icmp ult i32 %13, %16
  br i1 %17, label %18, label %34

18:                                               ; preds = %12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TGL, ptr %19, i32 0, i32 5
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load i32, ptr %5, align 4, !tbaa !10
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds %struct.Pixel, ptr %21, i64 %23
  %25 = getelementptr inbounds %struct.Pixel, ptr %6, i32 0, i32 0
  store i8 32, ptr %25, align 1, !tbaa !16
  %26 = getelementptr inbounds %struct.Pixel, ptr %6, i32 0, i32 1
  %27 = getelementptr inbounds %struct.TGLPixFmt, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.TGLFmt, ptr %27, i32 0, i32 0
  store i8 0, ptr %28, align 1, !tbaa !20
  %29 = getelementptr inbounds %struct.TGLFmt, ptr %27, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 1 %29, i8 0, i64 3, i1 false)
  %30 = getelementptr inbounds %struct.TGLPixFmt, ptr %26, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 1 %30, i8 0, i64 4, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %24, ptr align 1 %6, i64 9, i1 false), !tbaa.struct !21
  br label %31

31:                                               ; preds = %18
  %32 = load i32, ptr %5, align 4, !tbaa !10
  %33 = add i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !10
  br label %12, !llvm.loop !22

34:                                               ; preds = %12
  br label %35

35:                                               ; preds = %34, %2
  %36 = load i8, ptr %4, align 1, !tbaa !9
  %37 = zext i8 %36 to i32
  %38 = and i32 %37, 4
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %58

40:                                               ; preds = %35
  store i32 0, ptr %5, align 4, !tbaa !10
  br label %41

41:                                               ; preds = %54, %40
  %42 = load i32, ptr %5, align 4, !tbaa !10
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TGL, ptr %43, i32 0, i32 4
  %45 = load i32, ptr %44, align 8, !tbaa !12
  %46 = icmp ult i32 %42, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %41
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TGL, ptr %48, i32 0, i32 6
  %50 = load ptr, ptr %49, align 8, !tbaa !24
  %51 = load i32, ptr %5, align 4, !tbaa !10
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %50, i64 %52
  store float -1.000000e+00, ptr %53, align 4, !tbaa !25
  br label %54

54:                                               ; preds = %47
  %55 = load i32, ptr %5, align 4, !tbaa !10
  %56 = add i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !10
  br label %41, !llvm.loop !27

57:                                               ; preds = %41
  br label %58

58:                                               ; preds = %57, %35
  %59 = load i8, ptr %4, align 1, !tbaa !9
  %60 = zext i8 %59 to i32
  %61 = and i32 %60, 2
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %71

63:                                               ; preds = %58
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TGL, ptr %64, i32 0, i32 7
  %66 = load ptr, ptr %65, align 8, !tbaa !28
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TGL, ptr %67, i32 0, i32 8
  %69 = load i32, ptr %68, align 8, !tbaa !29
  %70 = zext i32 %69 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %66, i8 0, i64 %70, i1 false)
  br label %71

71:                                               ; preds = %63, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 16}
!13 = !{!"TGL", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !14, i64 52, !7, i64 53}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!13, !6, i64 24}
!16 = !{!17, !7, i64 0}
!17 = !{!"Pixel", !7, i64 0, !18, i64 1}
!18 = !{!"TGLPixFmt", !19, i64 0, !19, i64 4}
!19 = !{!"TGLFmt", !7, i64 0, !7, i64 1}
!20 = !{!19, !7, i64 0}
!21 = !{i64 0, i64 1, !9, i64 1, i64 1, !9, i64 2, i64 3, !9, i64 5, i64 1, !9, i64 6, i64 3, !9}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!13, !6, i64 32}
!25 = !{!26, !26, i64 0}
!26 = !{!"float", !7, i64 0}
!27 = distinct !{!27, !23}
!28 = !{!13, !6, i64 40}
!29 = !{!13, !11, i64 48}


; 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.Pixel = type { i8, %struct.TGLPixFmt }
%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: nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @tgl_clear(ptr nocapture noundef readonly %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext i8 %1 to i32
  %4 = and i32 %3, 1
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.loopexit17, label %.preheader16

.preheader16:                                     ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not21 = icmp eq i32 %6, 0
  br i1 %.not21, label %.loopexit17, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader16
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %8 ]
  %9 = load ptr, ptr %7, align 8, !tbaa !12
  %10 = getelementptr inbounds %struct.Pixel, ptr %9, i64 %indvars.iv
  store i8 32, ptr %10, align 1, !tbaa !13
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  store i64 0, ptr %.sroa.2.0..sroa_idx, align 1
  %11 = load i32, ptr %5, align 8, !tbaa !5
  %12 = zext i32 %11 to i64
  %13 = icmp ult i64 %indvars.iv.next, %12
  br i1 %13, label %8, label %.loopexit17, !llvm.loop !14

.loopexit17:                                      ; preds = %8, %.preheader16, %2
  %14 = and i32 %3, 4
  %.not14 = icmp eq i32 %14, 0
  br i1 %.not14, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.loopexit17
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %.not22 = icmp eq i32 %16, 0
  br i1 %.not22, label %.loopexit, label %.lr.ph20

.lr.ph20:                                         ; preds = %.preheader
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %wide.trip.count = zext i32 %16 to i64
  %min.iters.check = icmp ult i32 %16, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph20
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %19 = getelementptr inbounds float, ptr %18, i64 %index
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, ptr %19, align 4, !tbaa !17
  store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, ptr %20, align 4, !tbaa !17
  %index.next = add nuw i64 %index, 8
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph20
  %indvars.iv24.ph = phi i64 [ 0, %.lr.ph20 ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv24 = phi i64 [ %indvars.iv.next25, %scalar.ph ], [ %indvars.iv24.ph, %scalar.ph.preheader ]
  %22 = getelementptr inbounds float, ptr %18, i64 %indvars.iv24
  store float -1.000000e+00, ptr %22, align 4, !tbaa !17
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next25, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !22

.loopexit:                                        ; preds = %scalar.ph, %middle.block, %.preheader, %.loopexit17
  %23 = and i32 %3, 2
  %.not15 = icmp eq i32 %23, 0
  br i1 %.not15, label %30, label %24

24:                                               ; preds = %.loopexit
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !23
  %27 = getelementptr inbounds i8, ptr %0, i64 48
  %28 = load i32, ptr %27, align 8, !tbaa !24
  %29 = zext i32 %28 to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %26, i8 0, i64 %29, i1 false)
  br label %30

30:                                               ; preds = %24, %.loopexit
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(write, 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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 16}
!6 = !{!"TGL", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !11, i64 52, !8, i64 53}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !10, i64 32}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !8, i64 0}
!19 = distinct !{!19, !15, !20, !21}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !15, !21, !20}
!23 = !{!6, !10, i64 40}
!24 = !{!6, !7, i64 48}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass