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

13:                                               ; preds = %3
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = add i32 %14, 80
  %16 = lshr i32 %15, 8
  %17 = trunc i32 %16 to i8
  %18 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 0
  store i8 %17, ptr %18, align 1, !tbaa !16
  %19 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 1
  store i8 0, ptr %19, align 1, !tbaa !16
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = add i32 %20, 80
  %22 = trunc i32 %21 to i8
  %23 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 2
  store i8 %22, ptr %23, align 1, !tbaa !16
  %24 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 3
  store i8 0, ptr %24, align 1, !tbaa !16
  %25 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 4
  store i8 1, ptr %25, align 1, !tbaa !16
  %26 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 5
  store i8 0, ptr %26, align 1, !tbaa !16
  %27 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 6
  store i8 63, ptr %27, align 1, !tbaa !16
  %28 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 7
  store i8 0, ptr %28, align 1, !tbaa !16
  br label %43

29:                                               ; preds = %3
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = lshr i32 %30, 8
  %32 = trunc i32 %31 to i8
  %33 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 0
  store i8 %32, ptr %33, align 1, !tbaa !16
  %34 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 1
  store i8 0, ptr %34, align 1, !tbaa !16
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = trunc i32 %35 to i8
  %37 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 2
  store i8 %36, ptr %37, align 1, !tbaa !16
  %38 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 3
  store i8 0, ptr %38, align 1, !tbaa !16
  %39 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 4
  store i8 0, ptr %39, align 1, !tbaa !16
  %40 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 5
  store i8 0, ptr %40, align 1, !tbaa !16
  %41 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 6
  store i8 -17, ptr %41, align 1, !tbaa !16
  %42 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 7
  store i8 0, ptr %42, align 1, !tbaa !16
  br label %43

43:                                               ; preds = %29, %13
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 0
  %47 = call i32 @st7789h2_write_reg(ptr noundef %45, i16 noundef zeroext 42, ptr noundef %46, i32 noundef 4)
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr %7, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = icmp eq i32 %52, 2
  br i1 %53, label %54, label %70

54:                                               ; preds = %43
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = add i32 %55, 80
  %57 = lshr i32 %56, 8
  %58 = trunc i32 %57 to i8
  %59 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 0
  store i8 %58, ptr %59, align 1, !tbaa !16
  %60 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 1
  store i8 0, ptr %60, align 1, !tbaa !16
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = add i32 %61, 80
  %63 = trunc i32 %62 to i8
  %64 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 2
  store i8 %63, ptr %64, align 1, !tbaa !16
  %65 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 3
  store i8 0, ptr %65, align 1, !tbaa !16
  %66 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 4
  store i8 1, ptr %66, align 1, !tbaa !16
  %67 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 5
  store i8 0, ptr %67, align 1, !tbaa !16
  %68 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 6
  store i8 63, ptr %68, align 1, !tbaa !16
  %69 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 7
  store i8 0, ptr %69, align 1, !tbaa !16
  br label %84

70:                                               ; preds = %43
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = lshr i32 %71, 8
  %73 = trunc i32 %72 to i8
  %74 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 0
  store i8 %73, ptr %74, align 1, !tbaa !16
  %75 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 1
  store i8 0, ptr %75, align 1, !tbaa !16
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = trunc i32 %76 to i8
  %78 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 2
  store i8 %77, ptr %78, align 1, !tbaa !16
  %79 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 3
  store i8 0, ptr %79, align 1, !tbaa !16
  %80 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 4
  store i8 0, ptr %80, align 1, !tbaa !16
  %81 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 5
  store i8 0, ptr %81, align 1, !tbaa !16
  %82 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 6
  store i8 -17, ptr %82, align 1, !tbaa !16
  %83 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 7
  store i8 0, ptr %83, align 1, !tbaa !16
  br label %84

84:                                               ; preds = %70, %54
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ST7789H2_Object_t, ptr %85, i32 0, i32 1
  %87 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 0
  %88 = call i32 @st7789h2_write_reg(ptr noundef %86, i16 noundef zeroext 43, ptr noundef %87, i32 noundef 4)
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = add nsw i32 %89, %88
  store i32 %90, ptr %7, align 4, !tbaa !9
  %91 = load i32, ptr %7, align 4, !tbaa !9
  %92 = icmp ne i32 %91, 0
  br i1 %92, label %93, label %94

93:                                               ; preds = %84
  store i32 -1, ptr %7, align 4, !tbaa !9
  br label %94

94:                                               ; preds = %93, %84
  %95 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %95
}

; 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 = !{!12, !10, i64 92}
!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_SetCursor(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [8 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 92
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 1
  %8 = add i32 %1, 80
  %.sink17.in.in = select i1 %7, i32 %8, i32 %1
  %.sink15 = zext i1 %7 to i8
  %.sink = select i1 %7, i8 63, i8 -17
  %.sink16 = trunc i32 %.sink17.in.in to i8
  %.sink17.in = lshr i32 %.sink17.in.in, 8
  %.sink17 = trunc i32 %.sink17.in to i8
  store i8 %.sink17, ptr %4, align 1
  %9 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 0, ptr %9, align 1
  %10 = getelementptr inbounds i8, ptr %4, i64 2
  store i8 %.sink16, ptr %10, align 1
  %11 = getelementptr inbounds i8, ptr %4, i64 3
  store i8 0, ptr %11, align 1
  %12 = getelementptr inbounds i8, ptr %4, i64 4
  store i8 %.sink15, ptr %12, align 1
  %13 = getelementptr inbounds i8, ptr %4, i64 5
  store i8 0, ptr %13, align 1
  %14 = getelementptr inbounds i8, ptr %4, i64 6
  store i8 %.sink, ptr %14, align 1
  %15 = getelementptr inbounds i8, ptr %4, i64 7
  store i8 0, ptr %15, align 1
  %16 = getelementptr inbounds i8, ptr %0, i64 56
  %17 = call i32 @st7789h2_write_reg(ptr noundef nonnull %16, i16 noundef zeroext 42, ptr noundef nonnull %4, i32 noundef 4) #3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 2
  %20 = add i32 %2, 80
  %.sink21.in.in = select i1 %19, i32 %20, i32 %2
  %.sink19 = zext i1 %19 to i8
  %.sink18 = select i1 %19, i8 63, i8 -17
  %.sink20 = trunc i32 %.sink21.in.in to i8
  %.sink21.in = lshr i32 %.sink21.in.in, 8
  %.sink21 = trunc i32 %.sink21.in to i8
  store i8 %.sink21, ptr %4, align 1
  store i8 0, ptr %9, align 1
  store i8 %.sink20, ptr %10, align 1
  store i8 0, ptr %11, align 1
  store i8 %.sink19, ptr %12, align 1
  store i8 0, ptr %13, align 1
  store i8 %.sink18, ptr %14, align 1
  store i8 0, ptr %15, align 1
  %21 = call i32 @st7789h2_write_reg(ptr noundef nonnull %16, i16 noundef zeroext 43, ptr noundef nonnull %4, i32 noundef 4) #3
  %22 = sub i32 0, %21
  %.not = icmp ne i32 %17, %22
  %spec.store.select = sext i1 %.not to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #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, !13, i64 92}
!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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass