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

; 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 global %struct.DisplayContext, align 4
@_font12x16_start = external global i8, align 1

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

24:                                               ; preds = %81, %3
  %25 = load i32, ptr %9, align 4, !tbaa !8
  %26 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 3), align 4, !tbaa !14
  %27 = icmp ult i32 %25, %26
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %24
  %30 = load i32, ptr %9, align 4, !tbaa !8
  %31 = icmp ult i32 %30, 12
  %32 = zext i1 %31 to i64
  %33 = select i1 %31, i32 1, i32 2
  store i32 %33, ptr %8, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %34 = load i32, ptr %9, align 4, !tbaa !8
  %35 = icmp ult i32 %34, 12
  br i1 %35, label %36, label %38

36:                                               ; preds = %29
  %37 = load i32, ptr %9, align 4, !tbaa !8
  br label %41

38:                                               ; preds = %29
  %39 = load i32, ptr %9, align 4, !tbaa !8
  %40 = sub i32 %39, 12
  br label %41

41:                                               ; preds = %38, %36
  %42 = phi i32 [ %37, %36 ], [ %40, %38 ]
  store i32 %42, ptr %11, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !8
  br label %43

43:                                               ; preds = %77, %41
  %44 = load i32, ptr %12, align 4, !tbaa !8
  %45 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 2), align 4, !tbaa !15
  %46 = icmp ult i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %80

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %49 = load i32, ptr %5, align 4, !tbaa !8
  %50 = load i32, ptr %11, align 4, !tbaa !8
  %51 = add i32 %49, %50
  store i32 %51, ptr %13, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %52 = load i32, ptr %6, align 4, !tbaa !8
  %53 = load i32, ptr %8, align 4, !tbaa !8
  %54 = mul i32 %53, 8
  %55 = add i32 %52, %54
  %56 = load i32, ptr %12, align 4, !tbaa !8
  %57 = sub i32 %55, %56
  store i32 %57, ptr %14, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %58 = load ptr, ptr %7, align 8, !tbaa !12
  %59 = load i32, ptr %9, align 4, !tbaa !8
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  store ptr %61, ptr %15, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 1, ptr %16) #3
  %62 = load i32, ptr %12, align 4, !tbaa !8
  %63 = sub i32 7, %62
  %64 = shl i32 1, %63
  %65 = trunc i32 %64 to i8
  store i8 %65, ptr %16, align 1, !tbaa !5
  %66 = load ptr, ptr %15, align 8, !tbaa !12
  %67 = load i8, ptr %66, align 1, !tbaa !5
  %68 = zext i8 %67 to i32
  %69 = load i8, ptr %16, align 1, !tbaa !5
  %70 = zext i8 %69 to i32
  %71 = and i32 %68, %70
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %76

73:                                               ; preds = %48
  %74 = load i32, ptr %13, align 4, !tbaa !8
  %75 = load i32, ptr %14, align 4, !tbaa !8
  call void @clrpix(i32 noundef %74, i32 noundef %75)
  br label %76

76:                                               ; preds = %73, %48
  call void @llvm.lifetime.end.p0(i64 1, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %12, align 4, !tbaa !8
  %79 = add i32 %78, 1
  store i32 %79, ptr %12, align 4, !tbaa !8
  br label %43, !llvm.loop !16

80:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %9, align 4, !tbaa !8
  %83 = add i32 %82, 1
  store i32 %83, ptr %9, align 4, !tbaa !8
  br label %24, !llvm.loop !18

84:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

declare void @clrpix(i32 noundef, i32 noundef) #2

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

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


; 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 local_unnamed_addr global %struct.DisplayContext, align 4
@_font12x16_start = external local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local void @undchar12x16(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i8 %0 to i32
  %5 = add nsw i32 %4, -32
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 16), align 4, !tbaa !5
  %7 = mul i32 %6, %5
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr @_font12x16_start, i64 %8
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 12), align 4, !tbaa !10
  %.not26 = icmp eq i32 %10, 0
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 8), align 4
  %.not27 = icmp eq i32 %11, 0
  %or.cond = select i1 %.not26, i1 true, i1 %.not27
  br i1 %or.cond, label %._crit_edge25, label %.lr.ph24.split

._crit_edge25:                                    ; preds = %._crit_edge, %3
  ret void

.lr.ph24.split:                                   ; preds = %3, %._crit_edge
  %12 = phi i32 [ %23, %._crit_edge ], [ %10, %3 ]
  %13 = phi i32 [ %24, %._crit_edge ], [ %11, %3 ]
  %14 = phi i32 [ %25, %._crit_edge ], [ 1, %3 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %3 ]
  %.not28 = icmp eq i32 %14, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph24.split
  %15 = icmp ult i64 %indvars.iv, 12
  %16 = trunc nuw i64 %indvars.iv to i32
  %17 = add i32 %16, -12
  %18 = select i1 %15, i32 %16, i32 %17
  %19 = getelementptr inbounds i8, ptr %9, i64 %indvars.iv
  %20 = select i1 %15, i32 8, i32 16
  %21 = add i32 %20, %2
  %22 = add i32 %18, %1
  br label %28

._crit_edge.loopexit:                             ; preds = %37
  %.pre31 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 12), align 4, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph24.split
  %23 = phi i32 [ %.pre31, %._crit_edge.loopexit ], [ %12, %.lr.ph24.split ]
  %24 = phi i32 [ %38, %._crit_edge.loopexit ], [ %13, %.lr.ph24.split ]
  %25 = phi i32 [ %38, %._crit_edge.loopexit ], [ 0, %.lr.ph24.split ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = zext i32 %23 to i64
  %27 = icmp ult i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph24.split, label %._crit_edge25, !llvm.loop !11

28:                                               ; preds = %.lr.ph, %37
  %29 = phi i32 [ %13, %.lr.ph ], [ %38, %37 ]
  %.02021 = phi i32 [ 0, %.lr.ph ], [ %39, %37 ]
  %30 = sub i32 7, %.02021
  %31 = shl nuw i32 1, %30
  %32 = load i8, ptr %19, align 1, !tbaa !14
  %33 = zext i8 %32 to i32
  %34 = and i32 %31, %33
  %.not = icmp eq i32 %34, 0
  br i1 %.not, label %37, label %35

35:                                               ; preds = %28
  %36 = sub i32 %21, %.02021
  tail call void @clrpix(i32 noundef %22, i32 noundef %36) #2
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 8), align 4, !tbaa !15
  br label %37

37:                                               ; preds = %35, %28
  %38 = phi i32 [ %.pre, %35 ], [ %29, %28 ]
  %39 = add nuw i32 %.02021, 1
  %40 = icmp ult i32 %39, %38
  br i1 %40, label %28, label %._crit_edge.loopexit, !llvm.loop !16
}

declare void @clrpix(i32 noundef, i32 noundef) local_unnamed_addr #1

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 = { 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, !7, i64 16}
!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 12}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = !{!8, !8, i64 0}
!15 = !{!6, !7, i64 8}
!16 = distinct !{!16, !12}


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