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

; Function Attrs: nounwind uwtable
define dso_local i32 @ST7789H2_RegisterBusIO(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %78

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %14, i32 0, i32 0
  store ptr %12, ptr %15, align 8, !tbaa !14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %20, i32 0, i32 1
  store ptr %18, ptr %21, align 8, !tbaa !18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 8, !tbaa !19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %26, i32 0, i32 2
  store i16 %24, ptr %27, align 8, !tbaa !20
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %32, i32 0, i32 3
  store ptr %30, ptr %33, align 8, !tbaa !22
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !23
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %38, i32 0, i32 4
  store ptr %36, ptr %39, align 8, !tbaa !24
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %40, i32 0, i32 5
  %42 = load ptr, ptr %41, align 8, !tbaa !25
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %44, i32 0, i32 5
  store ptr %42, ptr %45, align 8, !tbaa !26
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %46, i32 0, i32 6
  %48 = load ptr, ptr %47, align 8, !tbaa !27
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %50, i32 0, i32 6
  store ptr %48, ptr %51, align 8, !tbaa !28
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct.ST7789H2_ctx_t, ptr %53, i32 0, i32 1
  store ptr @ST7789H2_ReadRegWrap, ptr %54, align 8, !tbaa !29
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.ST7789H2_ctx_t, ptr %56, i32 0, i32 0
  store ptr @ST7789H2_WriteRegWrap, ptr %57, align 8, !tbaa !30
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds %struct.ST7789H2_ctx_t, ptr %59, i32 0, i32 2
  store ptr @ST7789H2_SendDataWrap, ptr %60, align 8, !tbaa !31
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds %struct.ST7789H2_ctx_t, ptr %63, i32 0, i32 3
  store ptr %61, ptr %64, align 8, !tbaa !32
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %76

70:                                               ; preds = %9
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.ST7789H2_IO_t, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !14
  %75 = call i32 %74()
  store i32 %75, ptr %5, align 4, !tbaa !9
  br label %77

76:                                               ; preds = %9
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %76, %70
  br label %78

78:                                               ; preds = %77, %8
  %79 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %79
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ST7789H2_ReadRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @ST7789H2_WriteRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @ST7789H2_SendDataWrap(ptr noundef, ptr noundef, i32 noundef) #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 = { 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 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !12, i64 0, !16, i64 56, !7, i64 88, !10, i64 92}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!12, !6, i64 8}
!18 = !{!15, !6, i64 8}
!19 = !{!12, !13, i64 16}
!20 = !{!15, !13, i64 16}
!21 = !{!12, !6, i64 24}
!22 = !{!15, !6, i64 24}
!23 = !{!12, !6, i64 32}
!24 = !{!15, !6, i64 32}
!25 = !{!12, !6, i64 40}
!26 = !{!15, !6, i64 40}
!27 = !{!12, !6, i64 48}
!28 = !{!15, !6, i64 48}
!29 = !{!15, !6, i64 64}
!30 = !{!15, !6, i64 56}
!31 = !{!15, !6, i64 72}
!32 = !{!15, !6, i64 80}


; 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 i32 @ST7789H2_RegisterBusIO(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %24, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %5, ptr %0, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load i16, ptr %9, align 8, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store i16 %10, ptr %11, align 8, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load <2 x ptr>, ptr %12, align 8, !tbaa !19
  store <2 x ptr> %14, ptr %13, align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %1, i64 40
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load <2 x ptr>, ptr %15, align 8, !tbaa !19
  store <2 x ptr> %17, ptr %16, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %0, i64 56
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr @ST7789H2_ReadRegWrap, ptr %19, align 8, !tbaa !20
  store ptr @ST7789H2_WriteRegWrap, ptr %18, align 8, !tbaa !21
  %20 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr @ST7789H2_SendDataWrap, ptr %20, align 8, !tbaa !22
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %0, ptr %21, align 8, !tbaa !23
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %24, label %22

22:                                               ; preds = %4
  %23 = tail call i32 %5() #1
  br label %24

24:                                               ; preds = %4, %2, %22
  %.0 = phi i32 [ %23, %22 ], [ -1, %2 ], [ -1, %4 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ST7789H2_ReadRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @ST7789H2_WriteRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @ST7789H2_SendDataWrap(ptr noundef, ptr noundef, i32 noundef) #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" }
attributes #1 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 56, !8, i64 88, !14, i64 92}
!13 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!14 = !{!"int", !8, i64 0}
!15 = !{!6, !7, i64 8}
!16 = !{!12, !7, i64 8}
!17 = !{!6, !10, i64 16}
!18 = !{!12, !10, i64 16}
!19 = !{!7, !7, i64 0}
!20 = !{!12, !7, i64 64}
!21 = !{!12, !7, i64 56}
!22 = !{!12, !7, i64 72}
!23 = !{!12, !7, i64 80}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass