; LLVM IR from BrunoLevy/learn-fpga :: FemtoRV/FIRMWARE/EXAMPLES (test_font_OLED)

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

@GL_width = external global i16, align 2
@GL_height = external global i16, align 2
@font_8x8 = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @GL_init(i32 noundef -1)
  call void (...) @GL_clear()
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %104, %0
  %16 = load i16, ptr @GL_width, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = sub nsw i32 %17, 1
  %19 = load i16, ptr @GL_height, align 2, !tbaa !9
  %20 = zext i16 %19 to i32
  %21 = sub nsw i32 %20, 1
  call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %18, i32 noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %101, %15
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i16, ptr @GL_height, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = icmp ult i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i32 4, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %104

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %97, %28
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i16, ptr @GL_width, align 2, !tbaa !9
  %32 = zext i16 %31 to i32
  %33 = icmp ult i32 %30, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %29
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %100

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add i32 %36, %37
  %39 = udiv i32 %38, 8
  store i32 %39, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add i32 %40, %41
  %43 = udiv i32 %42, 8
  store i32 %43, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = mul i32 %44, 16
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = add i32 %45, %46
  %48 = and i32 %47, 127
  store i32 %48, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = add i32 %49, %50
  %52 = urem i32 %51, 8
  store i32 %52, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = add i32 %53, %54
  %56 = urem i32 %55, 8
  store i32 %56, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %57 = load ptr, ptr @font_8x8, align 8, !tbaa !11
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = mul i32 %58, 8
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = add i32 %59, %60
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %57, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !13
  %65 = zext i8 %64 to i32
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = shl i32 1, %66
  %68 = and i32 %65, %67
  %69 = icmp ne i32 %68, 0
  %70 = zext i1 %69 to i64
  %71 = select i1 %69, i32 255, i32 0
  store i32 %71, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = add i32 %72, %73
  %75 = and i32 %74, 63
  store i32 %75, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = lshr i32 %76, 3
  %78 = and i32 %77, 63
  store i32 %78, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sub i32 0, %79
  %81 = load i32, ptr %2, align 4, !tbaa !5
  %82 = add i32 %80, %81
  %83 = and i32 %82, 63
  store i32 %83, ptr %14, align 4, !tbaa !5
  %84 = load i32, ptr %11, align 4, !tbaa !5
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %94

86:                                               ; preds = %35
  %87 = load i32, ptr %14, align 4, !tbaa !5
  %88 = load i32, ptr %13, align 4, !tbaa !5
  %89 = shl i32 %88, 6
  %90 = or i32 %87, %89
  %91 = load i32, ptr %12, align 4, !tbaa !5
  %92 = shl i32 %91, 11
  %93 = or i32 %90, %92
  br label %95

94:                                               ; preds = %35
  br label %95

95:                                               ; preds = %94, %86
  %96 = phi i32 [ %93, %86 ], [ 0, %94 ]
  store volatile i32 %96, ptr inttoptr (i64 4202752 to ptr), align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %97

97:                                               ; preds = %95
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = add i32 %98, 1
  store i32 %99, ptr %5, align 4, !tbaa !5
  br label %29, !llvm.loop !14

100:                                              ; preds = %34
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %3, align 4, !tbaa !5
  %103 = add i32 %102, 1
  store i32 %103, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !16

104:                                              ; preds = %27
  %105 = load i32, ptr %2, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %2, align 4, !tbaa !5
  br label %15
}

declare void @GL_init(i32 noundef) #1

declare void @GL_clear(...) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @GL_write_window(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@GL_width = external local_unnamed_addr global i16, align 2
@GL_height = external local_unnamed_addr global i16, align 2
@font_8x8 = external local_unnamed_addr global ptr, align 8

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @GL_init(i32 noundef -1) #3
  tail call void (...) @GL_clear() #3
  %.pre = load i16, ptr @GL_height, align 2, !tbaa !5
  br label %1

1:                                                ; preds = %._crit_edge31, %0
  %2 = phi i16 [ %.pre, %0 ], [ %8, %._crit_edge31 ]
  %.0 = phi i32 [ 0, %0 ], [ %60, %._crit_edge31 ]
  %3 = load i16, ptr @GL_width, align 2, !tbaa !5
  %4 = zext i16 %3 to i32
  %5 = add nsw i32 %4, -1
  %6 = zext i16 %2 to i32
  %7 = add nsw i32 %6, -1
  tail call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %5, i32 noundef %7)
  %8 = load i16, ptr @GL_height, align 2, !tbaa !5
  %9 = zext i16 %8 to i32
  %.not = icmp eq i16 %8, 0
  br i1 %.not, label %._crit_edge31, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %10 = load i16, ptr @GL_width, align 2, !tbaa !5
  %.fr = freeze i16 %10
  %11 = zext i16 %.fr to i32
  %.not32 = icmp eq i16 %.fr, 0
  %12 = load ptr, ptr @font_8x8, align 8
  br i1 %.not32, label %._crit_edge31, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i32 %11, 1
  %13 = icmp eq i16 %.fr, 1
  %unroll_iter = and i32 %11, 65534
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.02730.us = phi i32 [ %59, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %14 = add nuw i32 %.02730.us, %.0
  %15 = shl i32 %14, 4
  %16 = and i32 %15, 896
  %17 = and i32 %14, 7
  %18 = shl nuw nsw i32 1, %17
  %19 = sub nsw i32 %.0, %.02730.us
  %20 = and i32 %19, 63
  %21 = shl i32 %.02730.us, 3
  %22 = and i32 %21, 4032
  %23 = or disjoint i32 %20, %22
  %24 = shl i32 %14, 11
  %25 = and i32 %24, 129024
  %26 = or i32 %23, %25
  br i1 %13, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.02829.us = phi i32 [ %48, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i32 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %27 = add nuw i32 %.02829.us, %.0
  %28 = and i32 %27, 7
  %29 = add i32 %27, %16
  %30 = and i32 %29, 1016
  %31 = or disjoint i32 %30, %28
  %32 = zext nneg i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %12, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = zext i8 %34 to i32
  %36 = and i32 %18, %35
  %.not.us = icmp eq i32 %36, 0
  %spec.select = select i1 %.not.us, i32 0, i32 %26
  store volatile i32 %spec.select, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !10
  %37 = or disjoint i32 %.02829.us, 1
  %38 = add nuw i32 %37, %.0
  %39 = and i32 %38, 7
  %40 = add i32 %38, %16
  %41 = and i32 %40, 1016
  %42 = or disjoint i32 %41, %39
  %43 = zext nneg i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %12, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = and i32 %18, %46
  %.not.us.1 = icmp eq i32 %47, 0
  %spec.select.1 = select i1 %.not.us.1, i32 0, i32 %26
  store volatile i32 %spec.select.1, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !10
  %48 = add nuw nsw i32 %.02829.us, 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !12

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.02829.us.unr = phi i32 [ 0, %.preheader.us ], [ %48, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %49 = add nuw i32 %.02829.us.unr, %.0
  %50 = and i32 %49, 7
  %51 = add i32 %49, %16
  %52 = and i32 %51, 1016
  %53 = or disjoint i32 %52, %50
  %54 = zext nneg i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %12, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %57 = zext i8 %56 to i32
  %58 = and i32 %18, %57
  %.not.us.epil = icmp eq i32 %58, 0
  %spec.select.epil = select i1 %.not.us.epil, i32 0, i32 %26
  store volatile i32 %spec.select.epil, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !10
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %59 = add nuw nsw i32 %.02730.us, 1
  %exitcond34.not = icmp eq i32 %59, %9
  br i1 %exitcond34.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !14

._crit_edge31:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %1
  %60 = add nuw nsw i32 %.0, 1
  br label %1
}

declare void @GL_init(i32 noundef) local_unnamed_addr #1

declare void @GL_clear(...) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @GL_write_window(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { noreturn 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 = { inlinehint 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 #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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass