; LLVM IR from mlcommons/tiny :: benchmark/interface/Drivers/BSP/Components/st7789h2 (st7789h2)

; 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.ST7789H2_Object_t = type { %struct.ST7789H2_IO_t, %struct.ST7789H2_ctx_t, i8, i32 }
%struct.ST7789H2_IO_t = type { ptr, ptr, i16, ptr, ptr, ptr, ptr }
%struct.ST7789H2_ctx_t = type { ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local i32 @ST7789H2_SetCursor(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ST7789H2_FillRGBRect(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca [480 x i8], align 16
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 480, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %18, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %65, %6
  %20 = load i32, ptr %16, align 4, !tbaa !9
  %21 = load i32, ptr %12, align 4, !tbaa !9
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %23, label %68

23:                                               ; preds = %19
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %16, align 4, !tbaa !9
  %28 = add i32 %26, %27
  %29 = call i32 @ST7789H2_SetCursor(ptr noundef %24, i32 noundef %25, i32 noundef %28)
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = add nsw i32 %30, %29
  store i32 %31, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %54, %23
  %33 = load i32, ptr %17, align 4, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = icmp ult i32 %33, %34
  br i1 %35, label %36, label %57

36:                                               ; preds = %32
  %37 = load ptr, ptr %15, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = load i32, ptr %17, align 4, !tbaa !9
  %40 = mul i32 2, %39
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [480 x i8], ptr %14, i64 0, i64 %41
  store i8 %38, ptr %42, align 1, !tbaa !11
  %43 = load ptr, ptr %15, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %15, align 8, !tbaa !5
  %45 = load ptr, ptr %15, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = load i32, ptr %17, align 4, !tbaa !9
  %48 = mul i32 2, %47
  %49 = add i32 %48, 1
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [480 x i8], ptr %14, i64 0, i64 %50
  store i8 %46, ptr %51, align 1, !tbaa !11
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i32 1
  store ptr %53, ptr %15, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %36
  %55 = load i32, ptr %17, align 4, !tbaa !9
  %56 = add i32 %55, 1
  store i32 %56, ptr %17, align 4, !tbaa !9
  br label %32, !llvm.loop !12

57:                                               ; preds = %32
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds [480 x i8], ptr %14, i64 0, i64 0
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = call i32 @st7789h2_write_reg(ptr noundef %59, i16 noundef zeroext 44, ptr noundef %60, i32 noundef %61)
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = add nsw i32 %63, %62
  store i32 %64, ptr %13, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %57
  %66 = load i32, ptr %16, align 4, !tbaa !9
  %67 = add i32 %66, 1
  store i32 %67, ptr %16, align 4, !tbaa !9
  br label %19, !llvm.loop !14

68:                                               ; preds = %19
  %69 = load i32, ptr %13, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  store i32 -1, ptr %13, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %71, %68
  %73 = load i32, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 480, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret i32 %73
}

; 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

declare i32 @st7789h2_write_reg(ptr noundef, i16 noundef zeroext, ptr noundef, i32 noundef) #2

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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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
declare dso_local i32 @ST7789H2_SetCursor(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ST7789H2_FillRGBRect(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca [480 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 480, ptr nonnull %7) #3
  %.not35 = icmp eq i32 %5, 0
  br i1 %.not35, label %._crit_edge33, label %.lr.ph32

.lr.ph32:                                         ; preds = %6
  %.not36 = icmp eq i32 %4, 0
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  br i1 %.not36, label %.lr.ph32.split, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph32
  %wide.trip.count = zext i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %9 = icmp eq i32 %4, 1
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.02230.us = phi i32 [ %49, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %.02329.us = phi ptr [ %.lcssa50, %._crit_edge.us ], [ %3, %.lr.ph.us.preheader ]
  %.02428.us = phi i32 [ %48, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %10 = add i32 %.02230.us, %2
  %11 = call i32 @ST7789H2_SetCursor(ptr noundef %0, i32 noundef %1, i32 noundef %10)
  br i1 %9, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %.126.us = phi ptr [ %34, %.lr.ph.us.new ], [ %.02329.us, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %12 = load i8, ptr %.126.us, align 1, !tbaa !5
  %13 = trunc nuw i64 %indvars.iv to i32
  %14 = shl i32 %13, 1
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [480 x i8], ptr %7, i64 0, i64 %15
  store i8 %12, ptr %16, align 4, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.126.us, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = or disjoint i32 %14, 1
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [480 x i8], ptr %7, i64 0, i64 %20
  store i8 %18, ptr %21, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.126.us, i64 2
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = trunc i64 %indvars.iv to i32
  %25 = shl i32 %24, 1
  %26 = or disjoint i32 %25, 2
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [480 x i8], ptr %7, i64 0, i64 %27
  store i8 %23, ptr %28, align 2, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.126.us, i64 3
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = or disjoint i32 %25, 3
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds [480 x i8], ptr %7, i64 0, i64 %32
  store i8 %30, ptr %33, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.126.us, i64 4
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !8

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.lcssa50.ph = phi ptr [ poison, %.lr.ph.us ], [ %34, %.lr.ph.us.new ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next.1, %.lr.ph.us.new ]
  %.126.us.unr = phi ptr [ %.02329.us, %.lr.ph.us ], [ %34, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %35 = load i8, ptr %.126.us.unr, align 1, !tbaa !5
  %36 = trunc nuw i64 %indvars.iv.unr to i32
  %37 = shl i32 %36, 1
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [480 x i8], ptr %7, i64 0, i64 %38
  store i8 %35, ptr %39, align 2, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %.126.us.unr, i64 1
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %42 = or disjoint i32 %37, 1
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [480 x i8], ptr %7, i64 0, i64 %43
  store i8 %41, ptr %44, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %.126.us.unr, i64 2
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa50 = phi ptr [ %.lcssa50.ph, %._crit_edge.us.unr-lcssa ], [ %45, %._crit_edge.us.epilog-lcssa ]
  %46 = add nsw i32 %11, %.02428.us
  %47 = call i32 @st7789h2_write_reg(ptr noundef nonnull %8, i16 noundef zeroext 44, ptr noundef nonnull %7, i32 noundef %4) #3
  %48 = add nsw i32 %46, %47
  %49 = add nuw i32 %.02230.us, 1
  %exitcond41.not = icmp eq i32 %49, %5
  br i1 %exitcond41.not, label %._crit_edge33, label %.lr.ph.us, !llvm.loop !10

.lr.ph32.split:                                   ; preds = %.lr.ph32, %.lr.ph32.split
  %.02230 = phi i32 [ %55, %.lr.ph32.split ], [ 0, %.lr.ph32 ]
  %.02428 = phi i32 [ %54, %.lr.ph32.split ], [ 0, %.lr.ph32 ]
  %50 = add i32 %.02230, %2
  %51 = call i32 @ST7789H2_SetCursor(ptr noundef %0, i32 noundef %1, i32 noundef %50)
  %52 = add nsw i32 %51, %.02428
  %53 = call i32 @st7789h2_write_reg(ptr noundef nonnull %8, i16 noundef zeroext 44, ptr noundef nonnull %7, i32 noundef 0) #3
  %54 = add nsw i32 %52, %53
  %55 = add nuw i32 %.02230, 1
  %exitcond42.not = icmp eq i32 %55, %5
  br i1 %exitcond42.not, label %._crit_edge33, label %.lr.ph32.split, !llvm.loop !10

._crit_edge33:                                    ; preds = %._crit_edge.us, %.lr.ph32.split, %6
  %.024.lcssa = phi i32 [ 0, %6 ], [ %54, %.lr.ph32.split ], [ %48, %._crit_edge.us ]
  %.not = icmp ne i32 %.024.lcssa, 0
  %spec.store.select = sext i1 %.not to i32
  call void @llvm.lifetime.end.p0(i64 480, ptr nonnull %7) #3
  ret i32 %spec.store.select
}

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

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

declare i32 @st7789h2_write_reg(ptr noundef, i16 noundef zeroext, ptr noundef, i32 noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass