; LLVM IR from reazon-research/OpenArm :: control/canfd_control/Core/Src (octospi)

; 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.OSPI_HandleTypeDef = type { ptr, %struct.OSPI_InitTypeDef, ptr, i32, i32, ptr, i32, i32, i32 }
%struct.OSPI_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.OSPIM_CfgTypeDef = type { i32, i32, i32, i32, i32, i32 }

@hospi1 = external dso_local global %struct.OSPI_HandleTypeDef, align 8

; Function Attrs: nounwind uwtable
define dso_local void @MX_OCTOSPI1_Init() #0 {
  %1 = alloca %struct.OSPIM_CfgTypeDef, align 4
  call void @llvm.lifetime.start.p0(i64 24, ptr %1) #4
  call void @llvm.memset.p0.i64(ptr align 4 %1, i8 0, i64 24, i1 false)
  store ptr inttoptr (i64 1375752192 to ptr), ptr @hospi1, align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), align 8, !tbaa !12
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 1), align 4, !tbaa !13
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 2), align 8, !tbaa !14
  store i32 32, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 3), align 4, !tbaa !15
  store i32 1, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 4), align 8, !tbaa !16
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 5), align 4, !tbaa !17
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 6), align 8, !tbaa !18
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 7), align 4, !tbaa !19
  store i32 1, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 8), align 8, !tbaa !20
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 9), align 4, !tbaa !21
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 10), align 8, !tbaa !22
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 11), align 4, !tbaa !23
  store i32 8, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 12), align 8, !tbaa !24
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 13), align 4, !tbaa !25
  store i32 0, ptr getelementptr inbounds (%struct.OSPI_InitTypeDef, ptr getelementptr inbounds (%struct.OSPI_HandleTypeDef, ptr @hospi1, i32 0, i32 1), i32 0, i32 14), align 8, !tbaa !26
  %2 = call i32 @HAL_OSPI_Init(ptr noundef @hospi1)
  %3 = icmp ne i32 %2, 0
  br i1 %3, label %4, label %5

4:                                                ; preds = %0
  call void @Error_Handler()
  br label %5

5:                                                ; preds = %4, %0
  %6 = getelementptr inbounds %struct.OSPIM_CfgTypeDef, ptr %1, i32 0, i32 0
  store i32 1, ptr %6, align 4, !tbaa !27
  %7 = getelementptr inbounds %struct.OSPIM_CfgTypeDef, ptr %1, i32 0, i32 2
  store i32 1, ptr %7, align 4, !tbaa !29
  %8 = getelementptr inbounds %struct.OSPIM_CfgTypeDef, ptr %1, i32 0, i32 3
  store i32 65537, ptr %8, align 4, !tbaa !30
  %9 = call i32 @HAL_OSPIM_Config(ptr noundef @hospi1, ptr noundef %1, i32 noundef 5000)
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %5
  call void @Error_Handler()
  br label %12

12:                                               ; preds = %11, %5
  call void @llvm.lifetime.end.p0(i64 24, ptr %1) #4
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @HAL_OSPI_Init(ptr noundef) #3

declare void @Error_Handler() #3

declare i32 @HAL_OSPIM_Config(ptr noundef, ptr noundef, i32 noundef) #3

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 #4 = { 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 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 72, !11, i64 80, !11, i64 84, !7, i64 88, !11, i64 96, !11, i64 100, !11, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 8}
!13 = !{!6, !11, i64 12}
!14 = !{!6, !11, i64 16}
!15 = !{!6, !11, i64 20}
!16 = !{!6, !11, i64 24}
!17 = !{!6, !11, i64 28}
!18 = !{!6, !11, i64 32}
!19 = !{!6, !11, i64 36}
!20 = !{!6, !11, i64 40}
!21 = !{!6, !11, i64 44}
!22 = !{!6, !11, i64 48}
!23 = !{!6, !11, i64 52}
!24 = !{!6, !11, i64 56}
!25 = !{!6, !11, i64 60}
!26 = !{!6, !11, i64 64}
!27 = !{!28, !11, i64 0}
!28 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!29 = !{!28, !11, i64 8}
!30 = !{!28, !11, i64 12}


; 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.OSPI_HandleTypeDef = type { ptr, %struct.OSPI_InitTypeDef, ptr, i32, i32, ptr, i32, i32, i32 }
%struct.OSPI_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.OSPIM_CfgTypeDef = type { i32, i32, i32, i32, i32, i32 }

@hospi1 = external dso_local global %struct.OSPI_HandleTypeDef, align 8

; Function Attrs: nounwind uwtable
define dso_local void @MX_OCTOSPI1_Init() local_unnamed_addr #0 {
  %1 = alloca %struct.OSPIM_CfgTypeDef, align 4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %1, i8 0, i64 24, i1 false)
  store ptr inttoptr (i64 1375752192 to ptr), ptr @hospi1, align 8, !tbaa !5
  store <4 x i32> <i32 1, i32 0, i32 0, i32 32>, ptr getelementptr inbounds (i8, ptr @hospi1, i64 8), align 8, !tbaa !12
  store <4 x i32> <i32 1, i32 0, i32 0, i32 0>, ptr getelementptr inbounds (i8, ptr @hospi1, i64 24), align 8, !tbaa !12
  store <4 x i32> <i32 1, i32 0, i32 0, i32 0>, ptr getelementptr inbounds (i8, ptr @hospi1, i64 40), align 8, !tbaa !12
  store i32 8, ptr getelementptr inbounds (i8, ptr @hospi1, i64 56), align 8, !tbaa !13
  store i32 0, ptr getelementptr inbounds (i8, ptr @hospi1, i64 60), align 4, !tbaa !14
  store i32 0, ptr getelementptr inbounds (i8, ptr @hospi1, i64 64), align 8, !tbaa !15
  %2 = tail call i32 @HAL_OSPI_Init(ptr noundef nonnull @hospi1) #4
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %4, label %3

3:                                                ; preds = %0
  tail call void @Error_Handler() #4
  br label %4

4:                                                ; preds = %3, %0
  store i32 1, ptr %1, align 4, !tbaa !16
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 1, ptr %5, align 4, !tbaa !18
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 65537, ptr %6, align 4, !tbaa !19
  %7 = call i32 @HAL_OSPIM_Config(ptr noundef nonnull @hospi1, ptr noundef nonnull %1, i32 noundef 5000) #4
  %.not1 = icmp eq i32 %7, 0
  br i1 %.not1, label %9, label %8

8:                                                ; preds = %4
  call void @Error_Handler() #4
  br label %9

9:                                                ; preds = %8, %4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %1) #4
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @HAL_OSPI_Init(ptr noundef) local_unnamed_addr #3

declare void @Error_Handler() local_unnamed_addr #3

declare i32 @HAL_OSPIM_Config(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 #4 = { 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 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 72, !11, i64 80, !11, i64 84, !7, i64 88, !11, i64 96, !11, i64 100, !11, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56}
!11 = !{!"int", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!6, !11, i64 56}
!14 = !{!6, !11, i64 60}
!15 = !{!6, !11, i64 64}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!18 = !{!17, !11, i64 8}
!19 = !{!17, !11, i64 12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,TailCallElimPass