; 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
@fb = external dso_local global ptr, align 8

; 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
define dso_local void @scrollup() #1 {
  %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 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 11), align 4, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  br label %61

9:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %10 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 6), align 4, !tbaa !10
  %11 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 7), align 4, !tbaa !11
  %12 = add i32 %10, %11
  store i32 %12, ptr %1, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %13 = load i32, ptr @gDisplayContext, align 4, !tbaa !13
  %14 = load i32, ptr %1, align 4, !tbaa !12
  %15 = mul i32 %13, %14
  store i32 %15, ptr %2, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %16 = load i32, ptr getelementptr inbounds (%struct.DisplayContext, ptr @gDisplayContext, i32 0, i32 13), align 4, !tbaa !14
  %17 = sub i32 %16, 1
  %18 = load i32, ptr %2, align 4, !tbaa !12
  %19 = mul i32 %17, %18
  store i32 %19, ptr %3, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %39, %9
  %21 = load i32, ptr %4, align 4, !tbaa !12
  %22 = load i32, ptr %3, align 4, !tbaa !12
  %23 = icmp ule i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %42

25:                                               ; preds = %20
  %26 = load ptr, ptr @fb, align 8, !tbaa !15
  %27 = load i32, ptr %4, align 4, !tbaa !12
  %28 = load i32, ptr @gDisplayContext, align 4, !tbaa !13
  %29 = load i32, ptr %1, align 4, !tbaa !12
  %30 = mul i32 %28, %29
  %31 = add i32 %27, %30
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %26, i64 %32
  %34 = load volatile i32, ptr %33, align 4, !tbaa !12
  %35 = load ptr, ptr @fb, align 8, !tbaa !15
  %36 = load i32, ptr %4, align 4, !tbaa !12
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  store volatile i32 %34, ptr %38, align 4, !tbaa !12
  br label %39

39:                                               ; preds = %25
  %40 = load i32, ptr %4, align 4, !tbaa !12
  %41 = add i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !12
  br label %20, !llvm.loop !17

42:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %43 = load i32, ptr %3, align 4, !tbaa !12
  %44 = add i32 %43, 1
  store i32 %44, ptr %5, align 4, !tbaa !12
  br label %45

45:                                               ; preds = %57, %42
  %46 = load i32, ptr %5, align 4, !tbaa !12
  %47 = load i32, ptr %3, align 4, !tbaa !12
  %48 = load i32, ptr %2, align 4, !tbaa !12
  %49 = add i32 %47, %48
  %50 = icmp ule i32 %46, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %60

52:                                               ; preds = %45
  %53 = load ptr, ptr @fb, align 8, !tbaa !15
  %54 = load i32, ptr %5, align 4, !tbaa !12
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  store volatile i32 0, ptr %56, align 4, !tbaa !12
  br label %57

57:                                               ; preds = %52
  %58 = load i32, ptr %5, align 4, !tbaa !12
  %59 = add i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !12
  br label %45, !llvm.loop !19

60:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %61

61:                                               ; preds = %60, %8
  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, !7, i64 44}
!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 24}
!11 = !{!6, !7, i64 28}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 52}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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
@fb = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local void @scrollup() local_unnamed_addr #0 {
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 44), align 4, !tbaa !5
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %0
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 24), align 4, !tbaa !10
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 28), align 4, !tbaa !11
  %6 = add i32 %5, %4
  %7 = load i32, ptr @gDisplayContext, align 4, !tbaa !12
  %8 = mul i32 %7, %6
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @gDisplayContext, i64 52), align 4, !tbaa !13
  %10 = add i32 %9, -1
  %11 = mul i32 %10, %8
  %12 = load ptr, ptr @fb, align 8, !tbaa !14
  br label %14

.preheader:                                       ; preds = %14
  %13 = mul i32 %9, %8
  %.not1619.not = icmp ult i32 %11, %13
  br i1 %.not1619.not, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %.018 = add nuw i32 %11, 1
  br label %.lr.ph

14:                                               ; preds = %3, %14
  %.01417 = phi i32 [ 0, %3 ], [ %23, %14 ]
  %15 = load i32, ptr @gDisplayContext, align 4, !tbaa !12
  %16 = mul i32 %15, %6
  %17 = add i32 %16, %.01417
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %12, i64 %18
  %20 = load volatile i32, ptr %19, align 4, !tbaa !16
  %21 = zext i32 %.01417 to i64
  %22 = getelementptr inbounds i32, ptr %12, i64 %21
  store volatile i32 %20, ptr %22, align 4, !tbaa !16
  %23 = add i32 %.01417, 1
  %.not = icmp ugt i32 %23, %11
  br i1 %.not, label %.preheader, label %14, !llvm.loop !17

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.020 = phi i32 [ %.0, %.lr.ph ], [ %.018, %.lr.ph.preheader ]
  %24 = zext i32 %.020 to i64
  %25 = getelementptr inbounds i32, ptr %12, i64 %24
  store volatile i32 0, ptr %25, align 4, !tbaa !16
  %.0 = add i32 %.020, 1
  %.not16 = icmp ugt i32 %.0, %13
  br i1 %.not16, label %.loopexit, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %0
  ret void
}

attributes #0 = { nofree norecurse 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 44}
!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 24}
!11 = !{!6, !7, i64 28}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 52}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass