; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/hw (ps7_init)

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

; 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 i32 @ps7_config(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca [16 x i64], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %14, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 128, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 -1, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %123, %1
  %16 = load i32, ptr %11, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %124

18:                                               ; preds = %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds i64, ptr %19, i64 0
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = and i64 %21, 15
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds i64, ptr %24, i64 0
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = lshr i64 %26, 4
  store i64 %27, ptr %4, align 8, !tbaa !11
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %42, %18
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %45

32:                                               ; preds = %28
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i64, ptr %33, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 %40
  store i64 %38, ptr %41, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %32
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %7, align 4, !tbaa !9
  br label %28, !llvm.loop !13

45:                                               ; preds = %28
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = sext i32 %47 to i64
  %50 = getelementptr inbounds i64, ptr %48, i64 %49
  store ptr %50, ptr %3, align 8, !tbaa !5
  %51 = load i64, ptr %4, align 8, !tbaa !11
  switch i64 %51, label %122 [
    i64 0, label %52
    i64 1, label %53
    i64 2, label %58
    i64 3, label %66
    i64 4, label %84
    i64 5, label %105
  ]

52:                                               ; preds = %45
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %123

53:                                               ; preds = %45
  %54 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 0
  %55 = load i64, ptr %54, align 16, !tbaa !11
  %56 = inttoptr i64 %55 to ptr
  store ptr %56, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  store volatile i64 0, ptr %57, align 8, !tbaa !11
  br label %123

58:                                               ; preds = %45
  %59 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 0
  %60 = load i64, ptr %59, align 16, !tbaa !11
  %61 = inttoptr i64 %60 to ptr
  store ptr %61, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 1
  %63 = load i64, ptr %62, align 8, !tbaa !11
  store i64 %63, ptr %9, align 8, !tbaa !11
  %64 = load i64, ptr %9, align 8, !tbaa !11
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  store volatile i64 %64, ptr %65, align 8, !tbaa !11
  br label %123

66:                                               ; preds = %45
  %67 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 0
  %68 = load i64, ptr %67, align 16, !tbaa !11
  %69 = inttoptr i64 %68 to ptr
  store ptr %69, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 1
  %71 = load i64, ptr %70, align 8, !tbaa !11
  store i64 %71, ptr %10, align 8, !tbaa !11
  %72 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 2
  %73 = load i64, ptr %72, align 16, !tbaa !11
  store i64 %73, ptr %9, align 8, !tbaa !11
  %74 = load i64, ptr %9, align 8, !tbaa !11
  %75 = load i64, ptr %10, align 8, !tbaa !11
  %76 = and i64 %74, %75
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = load volatile i64, ptr %77, align 8, !tbaa !11
  %79 = load i64, ptr %10, align 8, !tbaa !11
  %80 = xor i64 %79, -1
  %81 = and i64 %78, %80
  %82 = or i64 %76, %81
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  store volatile i64 %82, ptr %83, align 8, !tbaa !11
  br label %123

84:                                               ; preds = %45
  %85 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 0
  %86 = load i64, ptr %85, align 16, !tbaa !11
  %87 = inttoptr i64 %86 to ptr
  store ptr %87, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 1
  %89 = load i64, ptr %88, align 8, !tbaa !11
  store i64 %89, ptr %10, align 8, !tbaa !11
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %90

90:                                               ; preds = %101, %84
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load volatile i64, ptr %91, align 8, !tbaa !11
  %93 = load i64, ptr %10, align 8, !tbaa !11
  %94 = and i64 %92, %93
  %95 = icmp ne i64 %94, 0
  %96 = xor i1 %95, true
  br i1 %96, label %97, label %104

97:                                               ; preds = %90
  %98 = load i32, ptr %12, align 4, !tbaa !9
  %99 = icmp eq i32 %98, 100000000
  br i1 %99, label %100, label %101

100:                                              ; preds = %97
  store i32 2, ptr %11, align 4, !tbaa !9
  br label %104

101:                                              ; preds = %97
  %102 = load i32, ptr %12, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %12, align 4, !tbaa !9
  br label %90, !llvm.loop !15

104:                                              ; preds = %100, %90
  br label %123

105:                                              ; preds = %45
  %106 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 0
  %107 = load i64, ptr %106, align 16, !tbaa !11
  %108 = inttoptr i64 %107 to ptr
  store ptr %108, ptr %8, align 8, !tbaa !5
  %109 = getelementptr inbounds [16 x i64], ptr %5, i64 0, i64 1
  %110 = load i64, ptr %109, align 8, !tbaa !11
  store i64 %110, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %111 = load i64, ptr %10, align 8, !tbaa !11
  %112 = trunc i64 %111 to i32
  %113 = call i32 @get_number_of_cycles_for_delay(i32 noundef %112)
  store i32 %113, ptr %13, align 4, !tbaa !9
  call void @perf_reset_and_start_timer()
  br label %114

114:                                              ; preds = %120, %105
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  %116 = load volatile i64, ptr %115, align 8, !tbaa !11
  %117 = load i32, ptr %13, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  %119 = icmp ult i64 %116, %118
  br i1 %119, label %120, label %121

120:                                              ; preds = %114
  br label %114, !llvm.loop !16

121:                                              ; preds = %114
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %123

122:                                              ; preds = %45
  store i32 1, ptr %11, align 4, !tbaa !9
  br label %123

123:                                              ; preds = %122, %121, %104, %66, %58, %53, %52
  br label %15, !llvm.loop !17

124:                                              ; preds = %15
  %125 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 128, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i32 %125
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_number_of_cycles_for_delay(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @perf_reset_and_start_timer() #1

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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

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

; Function Attrs: mustprogress 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 range(i32 0, -2147483648) i32 @ps7_config(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca [16 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %2)
  %.8.sroa_idx64 = getelementptr inbounds i8, ptr %2, i64 8
  %.8.sroa_idx65 = getelementptr inbounds i8, ptr %2, i64 8
  %.8.sroa_idx66 = getelementptr inbounds i8, ptr %2, i64 8
  %.16.sroa_idx68 = getelementptr inbounds i8, ptr %2, i64 16
  %.8.sroa_idx67 = getelementptr inbounds i8, ptr %2, i64 8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.backedge, %1
  %.041 = phi ptr [ %0, %1 ], [ %11, %.loopexit.backedge ]
  %3 = load i64, ptr %.041, align 8, !tbaa !5
  %4 = trunc i64 %3 to i32
  %5 = and i32 %4, 15
  %6 = lshr i64 %3, 4
  %.not42 = icmp eq i32 %5, 0
  br i1 %.not42, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.loopexit
  %scevgep = getelementptr i8, ptr %.041, i64 8
  %7 = shl i64 %3, 3
  %8 = and i64 %7, 120
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %2, ptr align 8 %scevgep, i64 %8, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %.loopexit
  %9 = add nuw nsw i32 %5, 1
  %10 = zext nneg i32 %9 to i64
  %11 = getelementptr inbounds i64, ptr %.041, i64 %10
  switch i64 %6, label %.loopexit57 [
    i64 0, label %.loopexit57.loopexit63
    i64 1, label %12
    i64 2, label %14
    i64 3, label %16
    i64 4, label %23
    i64 5, label %38
  ]

12:                                               ; preds = %._crit_edge
  %.0..0. = load i64, ptr %2, align 16, !tbaa !5
  %13 = inttoptr i64 %.0..0. to ptr
  store volatile i64 0, ptr %13, align 8, !tbaa !5
  br label %.loopexit.backedge

14:                                               ; preds = %._crit_edge
  %.0..0.45 = load i64, ptr %2, align 16, !tbaa !5
  %15 = inttoptr i64 %.0..0.45 to ptr
  %.8..8.54 = load i64, ptr %.8.sroa_idx67, align 8, !tbaa !5
  store volatile i64 %.8..8.54, ptr %15, align 8, !tbaa !5
  br label %.loopexit.backedge

16:                                               ; preds = %._crit_edge
  %.0..0.46 = load i64, ptr %2, align 16, !tbaa !5
  %17 = inttoptr i64 %.0..0.46 to ptr
  %.8..8.52 = load i64, ptr %.8.sroa_idx66, align 8, !tbaa !5
  %.16..16. = load i64, ptr %.16.sroa_idx68, align 16, !tbaa !5
  %18 = and i64 %.16..16., %.8..8.52
  %19 = load volatile i64, ptr %17, align 8, !tbaa !5
  %20 = xor i64 %.8..8.52, -1
  %21 = and i64 %19, %20
  %22 = or i64 %21, %18
  store volatile i64 %22, ptr %17, align 8, !tbaa !5
  br label %.loopexit.backedge

23:                                               ; preds = %._crit_edge
  %.0..0.47 = load i64, ptr %2, align 16, !tbaa !5
  %24 = inttoptr i64 %.0..0.47 to ptr
  %.8..8.50 = load i64, ptr %.8.sroa_idx65, align 8, !tbaa !5
  %25 = load volatile i64, ptr %24, align 8, !tbaa !5
  %26 = and i64 %25, %.8..8.50
  %.not34 = icmp eq i64 %26, 0
  br i1 %.not34, label %.lr.ph37, label %.loopexit.backedge

.loopexit.backedge:                               ; preds = %43, %27, %.lr.ph37.1, %.lr.ph37.2, %.lr.ph37.3, %23, %16, %14, %12
  br label %.loopexit

27:                                               ; preds = %.lr.ph37
  %28 = load volatile i64, ptr %24, align 8, !tbaa !5
  %29 = and i64 %28, %.8..8.50
  %.not = icmp eq i64 %29, 0
  br i1 %.not, label %.lr.ph37.1, label %.loopexit.backedge, !llvm.loop !9

.lr.ph37.1:                                       ; preds = %27
  %30 = load volatile i64, ptr %24, align 8, !tbaa !5
  %31 = and i64 %30, %.8..8.50
  %.not.1 = icmp eq i64 %31, 0
  br i1 %.not.1, label %.lr.ph37.2, label %.loopexit.backedge, !llvm.loop !9

.lr.ph37.2:                                       ; preds = %.lr.ph37.1
  %32 = load volatile i64, ptr %24, align 8, !tbaa !5
  %33 = and i64 %32, %.8..8.50
  %.not.2 = icmp eq i64 %33, 0
  br i1 %.not.2, label %.lr.ph37.3, label %.loopexit.backedge, !llvm.loop !9

.lr.ph37.3:                                       ; preds = %.lr.ph37.2
  %34 = add nuw nsw i32 %.02835, 4
  %35 = load volatile i64, ptr %24, align 8, !tbaa !5
  %36 = and i64 %35, %.8..8.50
  %.not.3 = icmp eq i64 %36, 0
  br i1 %.not.3, label %.lr.ph37, label %.loopexit.backedge, !llvm.loop !9

.lr.ph37:                                         ; preds = %23, %.lr.ph37.3
  %.02835 = phi i32 [ %34, %.lr.ph37.3 ], [ 0, %23 ]
  %37 = icmp eq i32 %.02835, 100000000
  br i1 %37, label %.loopexit57, label %27

38:                                               ; preds = %._crit_edge
  %.0..0.48 = load i64, ptr %2, align 16, !tbaa !5
  %39 = inttoptr i64 %.0..0.48 to ptr
  %.8..8. = load i64, ptr %.8.sroa_idx64, align 8, !tbaa !5
  %40 = trunc i64 %.8..8. to i32
  %41 = tail call i32 @get_number_of_cycles_for_delay(i32 noundef %40)
  tail call void @perf_reset_and_start_timer()
  %42 = sext i32 %41 to i64
  br label %43

43:                                               ; preds = %43, %38
  %44 = load volatile i64, ptr %39, align 8, !tbaa !5
  %45 = icmp ult i64 %44, %42
  br i1 %45, label %43, label %.loopexit.backedge, !llvm.loop !11

.loopexit57.loopexit63:                           ; preds = %._crit_edge
  br label %.loopexit57

.loopexit57:                                      ; preds = %.lr.ph37, %._crit_edge, %.loopexit57.loopexit63
  %.1.ph = phi i32 [ 0, %.loopexit57.loopexit63 ], [ 1, %._crit_edge ], [ 2, %.lr.ph37 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %2)
  ret i32 %.1.ph
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_number_of_cycles_for_delay(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @perf_reset_and_start_timer() local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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