; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Tagl/Lib (peng_8)

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

@_ZN16GraphicComponent10_graph_memE = external global ptr, align 8
@_ZN16GraphicComponent15_bytes_per_lineE = external global i32, align 4
@_ZN16GraphicProcessor2D4E = external global [16 x i32], align 16
@_ZN16GraphicComponent9_colormapE = external global [256 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN15PolygonEngine_814SetPixel_rgb_DEP17GVertexAttributesii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, 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
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %class.GVertexAttributes, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp slt i32 %17, 192
  br i1 %18, label %19, label %23

19:                                               ; preds = %3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.GVertexAttributes, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !11
  br label %24

23:                                               ; preds = %3
  br label %24

24:                                               ; preds = %23, %19
  %25 = phi i32 [ %22, %19 ], [ 192, %23 ]
  store i32 %25, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.GVertexAttributes, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = icmp slt i32 %28, 192
  br i1 %29, label %30, label %34

30:                                               ; preds = %24
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.GVertexAttributes, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 4, !tbaa !13
  br label %35

34:                                               ; preds = %24
  br label %35

35:                                               ; preds = %34, %30
  %36 = phi i32 [ %33, %30 ], [ 192, %34 ]
  store i32 %36, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %class.GVertexAttributes, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = icmp slt i32 %39, 192
  br i1 %40, label %41, label %45

41:                                               ; preds = %35
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %class.GVertexAttributes, ptr %42, i32 0, i32 4
  %44 = load i32, ptr %43, align 4, !tbaa !14
  br label %46

45:                                               ; preds = %35
  br label %46

46:                                               ; preds = %45, %41
  %47 = phi i32 [ %44, %41 ], [ 192, %45 ]
  store i32 %47, ptr %9, align 4, !tbaa !9
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = ashr i32 %48, 2
  store i32 %49, ptr %7, align 4, !tbaa !9
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = ashr i32 %50, 2
  store i32 %51, ptr %8, align 4, !tbaa !9
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = ashr i32 %52, 2
  store i32 %53, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = ashr i32 %54, 4
  store i32 %55, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = ashr i32 %56, 4
  store i32 %57, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = ashr i32 %58, 4
  store i32 %59, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = and i32 %60, 3
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = and i32 %62, 3
  %64 = shl i32 %63, 2
  %65 = add nsw i32 %61, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [16 x i32], ptr @_ZN16GraphicProcessor2D4E, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !9
  store i32 %68, ptr %13, align 4, !tbaa !9
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = and i32 %69, 15
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = icmp sgt i32 %70, %71
  br i1 %72, label %73, label %76

73:                                               ; preds = %46
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = add i32 %74, 1
  store i32 %75, ptr %10, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %73, %46
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = and i32 %77, 15
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = icmp sgt i32 %78, %79
  br i1 %80, label %81, label %84

81:                                               ; preds = %76
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = add i32 %82, 1
  store i32 %83, ptr %11, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %81, %76
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = and i32 %85, 15
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = icmp sgt i32 %86, %87
  br i1 %88, label %89, label %92

89:                                               ; preds = %84
  %90 = load i32, ptr %12, align 4, !tbaa !9
  %91 = add i32 %90, 1
  store i32 %91, ptr %12, align 4, !tbaa !9
  br label %92

92:                                               ; preds = %89, %84
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %93 = load i32, ptr %12, align 4, !tbaa !9
  %94 = shl i32 %93, 0
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = shl i32 %95, 2
  %97 = or i32 %94, %96
  %98 = load i32, ptr %10, align 4, !tbaa !9
  %99 = shl i32 %98, 4
  %100 = or i32 %97, %99
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds [256 x i8], ptr @_ZN16GraphicComponent9_colormapE, i64 0, i64 %101
  %103 = load i8, ptr %102, align 1, !tbaa !15
  %104 = zext i8 %103 to i32
  store i32 %104, ptr %14, align 4, !tbaa !9
  %105 = load i32, ptr %14, align 4, !tbaa !9
  %106 = trunc i32 %105 to i8
  %107 = load ptr, ptr @_ZN16GraphicComponent10_graph_memE, align 8, !tbaa !5
  %108 = load i32, ptr %6, align 4, !tbaa !9
  %109 = load i32, ptr @_ZN16GraphicComponent15_bytes_per_lineE, align 4, !tbaa !9
  %110 = mul nsw i32 %108, %109
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i8, ptr %107, i64 %111
  %113 = load i32, ptr %5, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = mul i64 %114, 1
  %116 = getelementptr inbounds i8, ptr %112, i64 %115
  store i8 %106, ptr %116, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  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 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS17GVertexAttributes", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 16}
!15 = !{!7, !7, 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"

@_ZN16GraphicComponent10_graph_memE = external local_unnamed_addr global ptr, align 8
@_ZN16GraphicComponent15_bytes_per_lineE = external local_unnamed_addr global i32, align 4
@_ZN16GraphicProcessor2D4E = external local_unnamed_addr global [16 x i32], align 16
@_ZN16GraphicComponent9_colormapE = external local_unnamed_addr global [256 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN15PolygonEngine_814SetPixel_rgb_DEP17GVertexAttributesii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 192
  %7 = ashr i32 %5, 2
  %spec.select = select i1 %6, i32 %7, i32 48
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = icmp slt i32 %9, 192
  %11 = ashr i32 %9, 2
  %12 = select i1 %10, i32 %11, i32 48
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp slt i32 %14, 192
  %16 = ashr i32 %14, 2
  %17 = select i1 %15, i32 %16, i32 48
  %18 = ashr i32 %12, 4
  %19 = ashr i32 %17, 4
  %20 = and i32 %1, 3
  %21 = shl i32 %2, 2
  %22 = and i32 %21, 12
  %23 = or disjoint i32 %22, %20
  %24 = zext nneg i32 %23 to i64
  %25 = getelementptr inbounds [16 x i32], ptr @_ZN16GraphicProcessor2D4E, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = and i32 %spec.select, 15
  %28 = icmp sgt i32 %27, %26
  %29 = and i32 %12, 15
  %30 = icmp sgt i32 %29, %26
  %31 = zext i1 %30 to i32
  %.028 = add nsw i32 %18, %31
  %32 = and i32 %17, 15
  %33 = icmp sgt i32 %32, %26
  %34 = zext i1 %33 to i32
  %.0 = add nsw i32 %19, %34
  %35 = shl nsw i32 %.028, 2
  %.02933 = select i1 %28, i32 16, i32 0
  %36 = add nsw i32 %.02933, %spec.select
  %37 = and i32 %36, -16
  %38 = or i32 %35, %37
  %39 = or i32 %38, %.0
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds [256 x i8], ptr @_ZN16GraphicComponent9_colormapE, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = load ptr, ptr @_ZN16GraphicComponent10_graph_memE, align 8, !tbaa !14
  %44 = load i32, ptr @_ZN16GraphicComponent15_bytes_per_lineE, align 4, !tbaa !12
  %45 = mul nsw i32 %44, %2
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %43, i64 %46
  %48 = sext i32 %1 to i64
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  store i8 %42, ptr %49, align 1, !tbaa !13
  ret void
}

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


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