; 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 @dchar12x16(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 = %84, %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 %87

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 = %80, %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 %83

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 @setpix(i32 noundef %74, i32 noundef %75)
  br label %79

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

79:                                               ; preds = %76, %73
  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 %80

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

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

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

87:                                               ; 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 @setpix(i32 noundef, i32 noundef) #2

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 @dchar12x16(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
  %.not28 = icmp eq i32 %10, 0
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 8), align 4
  %.not29 = icmp eq i32 %11, 0
  %or.cond = select i1 %.not28, i1 true, i1 %.not29
  br i1 %or.cond, label %._crit_edge27, label %.lr.ph26.split

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

.lr.ph26.split:                                   ; preds = %3, %._crit_edge
  %12 = phi i32 [ %22, %._crit_edge ], [ %10, %3 ]
  %13 = phi i32 [ %23, %._crit_edge ], [ 1, %3 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %3 ]
  %.not30 = icmp eq i32 %13, 0
  br i1 %.not30, label %._crit_edge, label %.lr.ph

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

._crit_edge.loopexit:                             ; preds = %35
  %.pre = 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.ph26.split
  %22 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %12, %.lr.ph26.split ]
  %23 = phi i32 [ %37, %._crit_edge.loopexit ], [ 0, %.lr.ph26.split ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = zext i32 %22 to i64
  %25 = icmp ult i64 %indvars.iv.next, %24
  br i1 %25, label %.lr.ph26.split, label %._crit_edge27, !llvm.loop !11

26:                                               ; preds = %.lr.ph, %35
  %.02223 = phi i32 [ 0, %.lr.ph ], [ %36, %35 ]
  %27 = sub i32 %20, %.02223
  %28 = sub i32 7, %.02223
  %29 = shl nuw i32 1, %28
  %30 = load i8, ptr %21, align 1, !tbaa !14
  %31 = zext i8 %30 to i32
  %32 = and i32 %29, %31
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %34, label %33

33:                                               ; preds = %26
  tail call void @setpix(i32 noundef %18, i32 noundef %27) #2
  br label %35

34:                                               ; preds = %26
  tail call void @clrpix(i32 noundef %18, i32 noundef %27) #2
  br label %35

35:                                               ; preds = %34, %33
  %36 = add nuw i32 %.02223, 1
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 8), align 4, !tbaa !15
  %38 = icmp ult i32 %36, %37
  br i1 %38, label %26, label %._crit_edge.loopexit, !llvm.loop !16
}

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

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