; LLVM IR from IOsonata/IOsonata :: src/miscdev (ledmx)

; 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.LEDMXFONT_BITMAP = type { i32, [8 x i8] }
%struct.LEDMXCFG = type { ptr, i32, [16 x i32], i32, ptr }
%struct.LEDMXDEV = type { i32, [16 x i32], i32, ptr, ptr }

@g_FontBitmapSize = external constant i32, align 4
@g_FontBitmap = external constant [0 x %struct.LEDMXFONT_BITMAP], align 4

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @LedMxCmd(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @LedMxInit(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = 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) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %13, label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %2
  store i32 1, ptr %7, align 4
  br label %94

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @LedMxIOInit(ptr noundef %15, ptr noundef %16)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.LEDMXCFG, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.LEDMXDEV, ptr %20, i32 0, i32 0
  store i32 %19, ptr %21, align 4, !tbaa !12
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LEDMXDEV, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [16 x i32], ptr %23, i64 0, i64 0
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LEDMXCFG, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds [16 x i32], ptr %26, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %27, i64 64, i1 false)
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %28

28:                                               ; preds = %63, %14
  %29 = load i32, ptr %5, align 4, !tbaa !14
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.LEDMXDEV, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %34, label %66

34:                                               ; preds = %28
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.LEDMXCFG, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %5, align 4, !tbaa !14
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [16 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !14
  store i32 %40, ptr %6, align 4, !tbaa !14
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %41, i32 noundef 2048, i32 noundef %42)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %43, i32 noundef 2112, i32 noundef %44)
  %45 = load i32, ptr %6, align 4, !tbaa !14
  %46 = and i32 %45, 3
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %51

48:                                               ; preds = %34
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %49, i32 noundef 2096, i32 noundef %50)
  br label %54

51:                                               ; preds = %34
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %52, i32 noundef 2080, i32 noundef %53)
  br label %54

54:                                               ; preds = %51, %48
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %55, i32 noundef 2050, i32 noundef %56)
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %57, i32 noundef 2064, i32 noundef %58)
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %59, i32 noundef 2054, i32 noundef %60)
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !14
  call void @LedMxCmd(ptr noundef %61, i32 noundef 2398, i32 noundef %62)
  br label %63

63:                                               ; preds = %54
  %64 = load i32, ptr %5, align 4, !tbaa !14
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %5, align 4, !tbaa !14
  br label %28, !llvm.loop !15

66:                                               ; preds = %28
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.LEDMXCFG, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 4, !tbaa !17
  %70 = icmp eq ptr %69, null
  br i1 %70, label %76, label %71

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.LEDMXCFG, ptr %72, i32 0, i32 3
  %74 = load i32, ptr %73, align 4, !tbaa !18
  %75 = icmp sle i32 %74, 0
  br i1 %75, label %76, label %82

76:                                               ; preds = %71, %66
  %77 = load i32, ptr @g_FontBitmapSize, align 4, !tbaa !14
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.LEDMXDEV, ptr %78, i32 0, i32 2
  store i32 %77, ptr %79, align 4, !tbaa !19
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.LEDMXDEV, ptr %80, i32 0, i32 3
  store ptr @g_FontBitmap, ptr %81, align 4, !tbaa !20
  br label %93

82:                                               ; preds = %71
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.LEDMXCFG, ptr %83, i32 0, i32 3
  %85 = load i32, ptr %84, align 4, !tbaa !18
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.LEDMXDEV, ptr %86, i32 0, i32 2
  store i32 %85, ptr %87, align 4, !tbaa !19
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.LEDMXCFG, ptr %88, i32 0, i32 4
  %90 = load ptr, ptr %89, align 4, !tbaa !17
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.LEDMXDEV, ptr %91, i32 0, i32 3
  store ptr %90, ptr %92, align 4, !tbaa !20
  br label %93

93:                                               ; preds = %82, %76
  store i32 0, ptr %7, align 4
  br label %94

94:                                               ; preds = %93, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %95 = load i32, ptr %7, align 4
  switch i32 %95, label %97 [
    i32 0, label %96
    i32 1, label %96
  ]

96:                                               ; preds = %94, %94
  ret void

97:                                               ; preds = %94
  unreachable
}

declare void @LedMxIOInit(ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !11, i64 8}
!10 = !{!"", !6, i64 0, !11, i64 8, !7, i64 12, !11, i64 76, !6, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !7, i64 4, !11, i64 68, !6, i64 72, !6, i64 80}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 80}
!18 = !{!10, !11, i64 76}
!19 = !{!13, !11, i64 68}
!20 = !{!13, !6, i64 72}


; 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.LEDMXFONT_BITMAP = type { i32, [8 x i8] }

@g_FontBitmapSize = external local_unnamed_addr constant i32, align 4
@g_FontBitmap = external constant [0 x %struct.LEDMXFONT_BITMAP], align 4

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

; Function Attrs: nounwind uwtable
define dso_local void @LedMxInit(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %29, label %5

5:                                                ; preds = %2
  tail call void @LedMxIOInit(ptr noundef nonnull %0, ptr noundef nonnull %1) #3
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %7, ptr %0, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = getelementptr inbounds i8, ptr %1, i64 12
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(64) %8, ptr noundef nonnull align 4 dereferenceable(64) %9, i64 64, i1 false)
  %10 = icmp sgt i32 %7, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %11 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !13
  tail call void @LedMxCmd(ptr noundef nonnull %0, i32 noundef 2048, i32 noundef %12)
  tail call void @LedMxCmd(ptr noundef nonnull %0, i32 noundef 2112, i32 noundef %12)
  %13 = and i32 %12, 3
  %14 = icmp eq i32 %13, 0
  %. = select i1 %14, i32 2096, i32 2080
  tail call void @LedMxCmd(ptr noundef nonnull %0, i32 noundef %., i32 noundef %12)
  tail call void @LedMxCmd(ptr noundef nonnull %0, i32 noundef 2050, i32 noundef %12)
  tail call void @LedMxCmd(ptr noundef nonnull %0, i32 noundef 2064, i32 noundef %12)
  tail call void @LedMxCmd(ptr noundef nonnull %0, i32 noundef 2054, i32 noundef %12)
  tail call void @LedMxCmd(ptr noundef nonnull %0, i32 noundef 2398, i32 noundef %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load i32, ptr %0, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %indvars.iv.next, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %5
  %18 = getelementptr inbounds i8, ptr %1, i64 80
  %19 = load ptr, ptr %18, align 4, !tbaa !16
  %20 = icmp eq ptr %19, null
  br i1 %20, label %25, label %21

21:                                               ; preds = %._crit_edge
  %22 = getelementptr inbounds i8, ptr %1, i64 76
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = icmp slt i32 %23, 1
  br i1 %24, label %25, label %.sink.split

25:                                               ; preds = %21, %._crit_edge
  %26 = load i32, ptr @g_FontBitmapSize, align 4, !tbaa !13
  br label %.sink.split

.sink.split:                                      ; preds = %21, %25
  %.sink44 = phi i32 [ %26, %25 ], [ %23, %21 ]
  %g_FontBitmap.sink = phi ptr [ @g_FontBitmap, %25 ], [ %19, %21 ]
  %27 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %.sink44, ptr %27, align 4, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr %g_FontBitmap.sink, ptr %28, align 4, !tbaa !19
  br label %29

29:                                               ; preds = %.sink.split, %2
  ret void
}

declare void @LedMxIOInit(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { "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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !8, i64 12, !10, i64 76, !7, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !8, i64 4, !10, i64 68, !7, i64 72, !7, i64 80}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 80}
!17 = !{!6, !10, i64 76}
!18 = !{!12, !10, i64 68}
!19 = !{!12, !7, i64 72}


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