; 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
define dso_local i32 @ST7789H2_DeInit(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca [2 x i8], align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %5, i32 0, i32 2
  %7 = load i8, ptr %6, align 8, !tbaa !11
  %8 = zext i8 %7 to i32
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %26

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call i32 @ST7789H2_DisplayOff(ptr noundef %11)
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = add nsw i32 %13, %12
  store i32 %14, ptr %3, align 4, !tbaa !9
  %15 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 1
  store i8 0, ptr %15, align 1, !tbaa !16
  %16 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 0
  store i8 16, ptr %16, align 1, !tbaa !16
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 0
  %20 = call i32 @st7789h2_send_data(ptr noundef %18, ptr noundef %19, i32 noundef 1)
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr %3, align 4, !tbaa !9
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  call void @ST7789H2_Delay(ptr noundef %23, i32 noundef 10)
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %24, i32 0, i32 2
  store i8 0, ptr %25, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %10, %1
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 -1, ptr %3, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %29, %26
  %31 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %31
}

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

; 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_send_data(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @ST7789H2_Delay(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 = { 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 = !{!12, !7, i64 88}
!12 = !{!"", !13, i64 0, !15, i64 56, !7, i64 88, !10, i64 92}
!13 = !{!"", !6, i64 0, !6, i64 8, !14, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!14 = !{!"short", !7, i64 0}
!15 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!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"

; Function Attrs: nounwind uwtable
define dso_local i32 @ST7789H2_DeInit(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [2 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load i8, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %13, label %5

5:                                                ; preds = %1
  %6 = tail call i32 @ST7789H2_DisplayOff(ptr noundef nonnull %0)
  %7 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 0, ptr %7, align 1, !tbaa !14
  store i8 16, ptr %2, align 1, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  %9 = call i32 @st7789h2_send_data(ptr noundef nonnull %8, ptr noundef nonnull %2, i32 noundef 1) #3
  call void @ST7789H2_Delay(ptr noundef nonnull %0, i32 noundef 10)
  store i8 0, ptr %3, align 8, !tbaa !5
  %10 = sub i32 0, %9
  %11 = icmp ne i32 %6, %10
  %12 = sext i1 %11 to i32
  br label %13

13:                                               ; preds = %5, %1
  %.0 = phi i32 [ %12, %5 ], [ 0, %1 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %2) #3
  ret i32 %.0
}

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

; 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_send_data(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @ST7789H2_Delay(ptr noundef, i32 noundef) 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" }
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, !9, i64 88}
!6 = !{!"", !7, i64 0, !12, i64 56, !9, i64 88, !13, i64 92}
!7 = !{!"", !8, i64 0, !8, i64 8, !11, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!"", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24}
!13 = !{!"int", !9, i64 0}
!14 = !{!9, !9, i64 0}


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