; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/src/dev/lcd_hd44780.ll (ZN5daisy10LcdHD447805WriteEhh)

; 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.daisy::LcdHD44780" = type { i8, i8, %struct.dsy_gpio, %struct.dsy_gpio, [4 x %struct.dsy_gpio] }
%struct.dsy_gpio = type { %struct.dsy_gpio_pin, i32, i32 }
%struct.dsy_gpio_pin = type { i32, i8 }

declare void @_ZN5daisy6System5DelayEj(i32 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 void @dsy_gpio_write(ptr noundef, i8 noundef zeroext) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5daisy10LcdHD447805WriteEhh(ptr noundef nonnull align 4 dereferenceable(100) %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 0, ptr %7, align 1, !tbaa !9
  br label %9

9:                                                ; preds = %28, %3
  %10 = load i8, ptr %7, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = load i8, ptr %6, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  br label %31

16:                                               ; preds = %9
  %17 = getelementptr inbounds %"class.daisy::LcdHD44780", ptr %8, i32 0, i32 4
  %18 = load i8, ptr %7, align 1, !tbaa !9
  %19 = zext i8 %18 to i64
  %20 = getelementptr inbounds [4 x %struct.dsy_gpio], ptr %17, i64 0, i64 %19
  %21 = load i8, ptr %5, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = load i8, ptr %7, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = ashr i32 %22, %24
  %26 = and i32 %25, 1
  %27 = trunc i32 %26 to i8
  call void @dsy_gpio_write(ptr noundef %20, i8 noundef zeroext %27)
  br label %28

28:                                               ; preds = %16
  %29 = load i8, ptr %7, align 1, !tbaa !9
  %30 = add i8 %29, 1
  store i8 %30, ptr %7, align 1, !tbaa !9
  br label %9, !llvm.loop !10

31:                                               ; preds = %15
  %32 = getelementptr inbounds %"class.daisy::LcdHD44780", ptr %8, i32 0, i32 3
  call void @dsy_gpio_write(ptr noundef %32, i8 noundef zeroext 1)
  call void @_ZN5daisy6System5DelayEj(i32 noundef 1)
  %33 = getelementptr inbounds %"class.daisy::LcdHD44780", ptr %8, i32 0, i32 3
  call void @dsy_gpio_write(ptr noundef %33, i8 noundef zeroext 0)
  ret void
}

attributes #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 = { mustprogress 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 #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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; 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"

%struct.dsy_gpio = type { %struct.dsy_gpio_pin, i32, i32 }
%struct.dsy_gpio_pin = type { i32, i8 }

declare void @_ZN5daisy6System5DelayEj(i32 noundef) local_unnamed_addr #0

declare void @dsy_gpio_write(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5daisy10LcdHD447805WriteEhh(ptr noundef nonnull align 4 dereferenceable(100) %0, i8 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #1 align 2 {
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = getelementptr inbounds i8, ptr %0, i64 36
  %5 = zext i8 %1 to i32
  %wide.trip.count = zext i8 %2 to i64
  br label %7

._crit_edge:                                      ; preds = %7, %3
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  tail call void @dsy_gpio_write(ptr noundef nonnull %6, i8 noundef zeroext 1)
  tail call void @_ZN5daisy6System5DelayEj(i32 noundef 1)
  tail call void @dsy_gpio_write(ptr noundef nonnull %6, i8 noundef zeroext 0)
  ret void

7:                                                ; preds = %.lr.ph, %7
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %7 ]
  %8 = trunc nuw i64 %indvars.iv to i32
  %9 = getelementptr inbounds [4 x %struct.dsy_gpio], ptr %4, i64 0, i64 %indvars.iv
  %10 = lshr i32 %5, %8
  %11 = trunc nuw i32 %10 to i8
  %12 = and i8 %11, 1
  tail call void @dsy_gpio_write(ptr noundef nonnull %9, i8 noundef zeroext %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %7, !llvm.loop !5
}

attributes #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 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass