; LLVM IR from cpq/bare-metal-programming-guide :: steps/step-6-clock (sysinit)

; 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.SCB_Type = type { i32, i32, i32, i32, i32, i32, [12 x i8], i32, i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, [4 x i32], [5 x i32], [5 x i32], i32 }
%struct.RCC_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, [2 x i32], i32, i32, i32, i32 }

@SystemCoreClock = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @SystemInit() #0 {
  %1 = load volatile i32, ptr getelementptr inbounds (%struct.SCB_Type, ptr inttoptr (i64 3758157056 to ptr), i32 0, i32 20), align 4, !tbaa !5
  %2 = zext i32 %1 to i64
  %3 = or i64 %2, 15728640
  %4 = trunc i64 %3 to i32
  store volatile i32 %4, ptr getelementptr inbounds (%struct.SCB_Type, ptr inttoptr (i64 3758157056 to ptr), i32 0, i32 20), align 4, !tbaa !5
  %5 = load volatile i32, ptr inttoptr (i64 1073888256 to ptr), align 4, !tbaa !10
  %6 = zext i32 %5 to i64
  %7 = or i64 %6, 773
  %8 = trunc i64 %7 to i32
  store volatile i32 %8, ptr inttoptr (i64 1073888256 to ptr), align 4, !tbaa !10
  %9 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 1), align 4, !tbaa !12
  %10 = zext i32 %9 to i64
  %11 = and i64 %10, -131072
  %12 = trunc i64 %11 to i32
  store volatile i32 %12, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 1), align 4, !tbaa !12
  %13 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 1), align 4, !tbaa !12
  %14 = or i32 %13, 0
  store volatile i32 %14, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 1), align 4, !tbaa !12
  %15 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 1), align 4, !tbaa !12
  %16 = or i32 %15, 11528
  store volatile i32 %16, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 1), align 4, !tbaa !12
  %17 = load volatile i32, ptr inttoptr (i64 1073887232 to ptr), align 4, !tbaa !14
  %18 = zext i32 %17 to i64
  %19 = or i64 %18, 16777216
  %20 = trunc i64 %19 to i32
  store volatile i32 %20, ptr inttoptr (i64 1073887232 to ptr), align 4, !tbaa !14
  br label %21

21:                                               ; preds = %26, %0
  %22 = load volatile i32, ptr inttoptr (i64 1073887232 to ptr), align 4, !tbaa !14
  %23 = zext i32 %22 to i64
  %24 = and i64 %23, 33554432
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  call void @spin(i32 noundef 1)
  br label %21, !llvm.loop !15

27:                                               ; preds = %21
  store volatile i32 37888, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 2), align 4, !tbaa !17
  %28 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 2), align 4, !tbaa !17
  %29 = or i32 %28, 2
  store volatile i32 %29, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 2), align 4, !tbaa !17
  br label %30

30:                                               ; preds = %34, %27
  %31 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 2), align 4, !tbaa !17
  %32 = and i32 %31, 12
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  call void @spin(i32 noundef 1)
  br label %30, !llvm.loop !18

35:                                               ; preds = %30
  %36 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 16), align 4, !tbaa !19
  %37 = zext i32 %36 to i64
  %38 = or i64 %37, 16384
  %39 = trunc i64 %38 to i32
  store volatile i32 %39, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1073887232 to ptr), i32 0, i32 16), align 4, !tbaa !19
  %40 = load i32, ptr @SystemCoreClock, align 4, !tbaa !20
  %41 = udiv i32 %40, 1000
  %42 = call i32 @SysTick_Config(i32 noundef %41)
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @spin(i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @SysTick_Config(i32 noundef) #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 = { 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" }

!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 136}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !8, i64 24, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !8, i64 64, !7, i64 72, !7, i64 76, !8, i64 80, !8, i64 96, !8, i64 116, !7, i64 136}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!12 = !{!13, !7, i64 4}
!13 = !{!"", !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, !8, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !8, i64 72, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !8, i64 104, !7, i64 112, !7, i64 116, !8, i64 120, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140}
!14 = !{!13, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!13, !7, i64 8}
!18 = distinct !{!18, !16}
!19 = !{!13, !7, i64 68}
!20 = !{!7, !7, i64 0}


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

@SystemCoreClock = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @SystemInit() local_unnamed_addr #0 {
  %1 = load volatile i32, ptr inttoptr (i64 3758157192 to ptr), align 8, !tbaa !5
  %2 = or i32 %1, 15728640
  store volatile i32 %2, ptr inttoptr (i64 3758157192 to ptr), align 8, !tbaa !5
  %3 = load volatile i32, ptr inttoptr (i64 1073888256 to ptr), align 1024, !tbaa !10
  %4 = or i32 %3, 773
  store volatile i32 %4, ptr inttoptr (i64 1073888256 to ptr), align 1024, !tbaa !10
  %5 = load volatile i32, ptr inttoptr (i64 1073887236 to ptr), align 4, !tbaa !12
  %6 = and i32 %5, -131072
  store volatile i32 %6, ptr inttoptr (i64 1073887236 to ptr), align 4, !tbaa !12
  %7 = load volatile i32, ptr inttoptr (i64 1073887236 to ptr), align 4, !tbaa !12
  store volatile i32 %7, ptr inttoptr (i64 1073887236 to ptr), align 4, !tbaa !12
  %8 = load volatile i32, ptr inttoptr (i64 1073887236 to ptr), align 4, !tbaa !12
  %9 = or i32 %8, 11528
  store volatile i32 %9, ptr inttoptr (i64 1073887236 to ptr), align 4, !tbaa !12
  %10 = load volatile i32, ptr inttoptr (i64 1073887232 to ptr), align 2048, !tbaa !14
  %11 = or i32 %10, 16777216
  store volatile i32 %11, ptr inttoptr (i64 1073887232 to ptr), align 2048, !tbaa !14
  %12 = load volatile i32, ptr inttoptr (i64 1073887232 to ptr), align 2048, !tbaa !14
  %13 = and i32 %12, 33554432
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  tail call void @spin(i32 noundef 1)
  %15 = load volatile i32, ptr inttoptr (i64 1073887232 to ptr), align 2048, !tbaa !14
  %16 = and i32 %15, 33554432
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %0
  store volatile i32 37888, ptr inttoptr (i64 1073887240 to ptr), align 8, !tbaa !17
  %18 = load volatile i32, ptr inttoptr (i64 1073887240 to ptr), align 8, !tbaa !17
  %19 = or i32 %18, 2
  store volatile i32 %19, ptr inttoptr (i64 1073887240 to ptr), align 8, !tbaa !17
  %20 = load volatile i32, ptr inttoptr (i64 1073887240 to ptr), align 8, !tbaa !17
  %21 = and i32 %20, 12
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.lr.ph2, label %._crit_edge3

.lr.ph2:                                          ; preds = %._crit_edge, %.lr.ph2
  tail call void @spin(i32 noundef 1)
  %23 = load volatile i32, ptr inttoptr (i64 1073887240 to ptr), align 8, !tbaa !17
  %24 = and i32 %23, 12
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %.lr.ph2, label %._crit_edge3, !llvm.loop !18

._crit_edge3:                                     ; preds = %.lr.ph2, %._crit_edge
  %26 = load volatile i32, ptr inttoptr (i64 1073887300 to ptr), align 4, !tbaa !19
  %27 = or i32 %26, 16384
  store volatile i32 %27, ptr inttoptr (i64 1073887300 to ptr), align 4, !tbaa !19
  %28 = load i32, ptr @SystemCoreClock, align 4, !tbaa !20
  %29 = udiv i32 %28, 1000
  %30 = tail call i32 @SysTick_Config(i32 noundef %29)
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @spin(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @SysTick_Config(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 = { 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" }

!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 136}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !8, i64 24, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !8, i64 64, !7, i64 72, !7, i64 76, !8, i64 80, !8, i64 96, !8, i64 116, !7, i64 136}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!12 = !{!13, !7, i64 4}
!13 = !{!"", !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, !8, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !8, i64 72, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !8, i64 104, !7, i64 112, !7, i64 116, !8, i64 120, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140}
!14 = !{!13, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!13, !7, i64 8}
!18 = distinct !{!18, !16}
!19 = !{!13, !7, i64 68}
!20 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SimplifyCFGPass,TailCallElimPass