; LLVM IR from smwikipedia/EmbeddedAndRTOSSamples :: C2.6 (vid)

; 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.DisplayContext = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@gDisplayContext = external dso_local global %struct.DisplayContext, 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 @clrpix(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @erasechar(i32 noundef %0, i32 noundef %1) #1 {
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sub i32 %12, 1
  %14 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 5), align 4, !tbaa !9
  %15 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 8), align 4, !tbaa !11
  %16 = add i32 %14, %15
  %17 = mul i32 %13, %16
  store i32 %17, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sub i32 %18, 1
  %20 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 6), align 4, !tbaa !12
  %21 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 7), align 4, !tbaa !13
  %22 = add i32 %20, %21
  %23 = mul i32 %19, %22
  store i32 %23, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %48, %2
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 6), align 4, !tbaa !12
  %27 = icmp ult i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %51

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

30:                                               ; preds = %44, %29
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 5), align 4, !tbaa !9
  %33 = icmp ult i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %47

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = add i32 %36, %37
  store i32 %38, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = add i32 %39, %40
  store i32 %41, ptr %11, align 4, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !5
  call void @clrpix(i32 noundef %42, i32 noundef %43)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %44

44:                                               ; preds = %35
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = add i32 %45, 1
  store i32 %46, ptr %9, align 4, !tbaa !5
  br label %30, !llvm.loop !14

47:                                               ; preds = %34
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %24, !llvm.loop !16

51:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = { 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, !6, i64 20}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56}
!11 = !{!10, !6, i64 32}
!12 = !{!10, !6, i64 24}
!13 = !{!10, !6, i64 28}
!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"

%struct.DisplayContext = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@gDisplayContext = external dso_local local_unnamed_addr global %struct.DisplayContext, align 4

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

; Function Attrs: nounwind uwtable
define dso_local void @erasechar(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = add i32 %1, -1
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 20), align 4, !tbaa !5
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 32), align 4, !tbaa !10
  %6 = add i32 %5, %4
  %7 = mul i32 %6, %3
  %8 = add i32 %0, -1
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 24), align 4, !tbaa !11
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 28), align 4, !tbaa !12
  %11 = add i32 %10, %9
  %12 = mul i32 %11, %8
  %.not = icmp eq i32 %9, 0
  %.not16 = icmp eq i32 %4, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not16
  br i1 %or.cond, label %._crit_edge15, label %.preheader

.preheader:                                       ; preds = %2, %._crit_edge
  %13 = phi i32 [ %16, %._crit_edge ], [ %9, %2 ]
  %14 = phi i32 [ %17, %._crit_edge ], [ 1, %2 ]
  %.014 = phi i32 [ %18, %._crit_edge ], [ 0, %2 ]
  %.not17 = icmp eq i32 %14, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %15 = add i32 %.014, %12
  br label %20

._crit_edge15:                                    ; preds = %._crit_edge, %2
  ret void

._crit_edge.loopexit:                             ; preds = %20
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 24), align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %16 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %13, %.preheader ]
  %17 = phi i32 [ %23, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %18 = add nuw i32 %.014, 1
  %19 = icmp ult i32 %18, %16
  br i1 %19, label %.preheader, label %._crit_edge15, !llvm.loop !13

20:                                               ; preds = %.lr.ph, %20
  %.01213 = phi i32 [ 0, %.lr.ph ], [ %22, %20 ]
  %21 = add i32 %.01213, %7
  tail call void @clrpix(i32 noundef %21, i32 noundef %15)
  %22 = add nuw i32 %.01213, 1
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 20), align 4, !tbaa !5
  %24 = icmp ult i32 %22, %23
  br i1 %24, label %20, label %._crit_edge.loopexit, !llvm.loop !16
}

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

!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, !7, i64 20}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 32}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !7, i64 28}
!13 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.unswitch.partial.disable"}
!16 = distinct !{!16, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass