; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/zynq_fsbl (image_mover)

; 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.StructPartHeader = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, [1 x i32], i32, [4 x i32], i32 }

@PartitionCount = external dso_local global i32, align 4
@PartitionHeader = external dso_local global [14 x %struct.StructPartHeader], align 16
@FsblLength = external dso_local global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local i32 @GetPartitionHeaderInfo(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = call i32 @GetFsblLength(i32 noundef %7, ptr noundef @FsblLength)
  store i32 %8, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

13:                                               ; preds = %1
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = call i32 @GetPartitionHeaderStartAddr(i32 noundef %14, ptr noundef %4)
  store i32 %15, ptr %5, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %13
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

20:                                               ; preds = %13
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = add i32 %22, %21
  store i32 %23, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = call i32 @LoadPartitionsHeaderInfo(i32 noundef %24, ptr noundef @PartitionHeader)
  store i32 %25, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %20
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

30:                                               ; preds = %20
  %31 = call i32 @GetPartitionCount(ptr noundef @PartitionHeader)
  store i32 %31, ptr @PartitionCount, align 4, !tbaa !5
  %32 = load i32, ptr @PartitionCount, align 4, !tbaa !5
  %33 = icmp uge i32 %32, 14
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

35:                                               ; preds = %30
  %36 = load i32, ptr @PartitionCount, align 4, !tbaa !5
  %37 = icmp ule i32 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

39:                                               ; preds = %35
  br label %40

40:                                               ; preds = %39
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

41:                                               ; preds = %40, %38, %34, %29, %19, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %42 = load i32, ptr %2, align 4
  ret i32 %42
}

; 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
declare dso_local i32 @GetFsblLength(i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @GetPartitionHeaderStartAddr(i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @LoadPartitionsHeaderInfo(i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @GetPartitionCount(ptr noundef) #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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.StructPartHeader = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, [1 x i32], i32, [4 x i32], i32 }

@PartitionCount = external dso_local local_unnamed_addr global i32, align 4
@PartitionHeader = external dso_local global [14 x %struct.StructPartHeader], align 16
@FsblLength = external dso_local global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @GetPartitionHeaderInfo(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  %3 = tail call i32 @GetFsblLength(i32 noundef %0, ptr noundef nonnull @FsblLength)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %15

4:                                                ; preds = %1
  %5 = call i32 @GetPartitionHeaderStartAddr(i32 noundef %0, ptr noundef nonnull %2)
  %.not8 = icmp eq i32 %5, 0
  br i1 %.not8, label %6, label %15

6:                                                ; preds = %4
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = add i32 %7, %0
  store i32 %8, ptr %2, align 4, !tbaa !5
  %9 = call i32 @LoadPartitionsHeaderInfo(i32 noundef %8, ptr noundef nonnull @PartitionHeader)
  %.not9 = icmp eq i32 %9, 0
  br i1 %.not9, label %10, label %15

10:                                               ; preds = %6
  %11 = call i32 @GetPartitionCount(ptr noundef nonnull @PartitionHeader)
  store i32 %11, ptr @PartitionCount, align 4, !tbaa !5
  %12 = icmp ugt i32 %11, 13
  br i1 %12, label %15, label %13

13:                                               ; preds = %10
  %14 = icmp ult i32 %11, 2
  %. = zext i1 %14 to i32
  br label %15

15:                                               ; preds = %13, %10, %6, %4, %1
  %.0 = phi i32 [ 1, %1 ], [ 1, %4 ], [ 1, %6 ], [ 1, %10 ], [ %., %13 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  ret i32 %.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
declare dso_local i32 @GetFsblLength(i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass