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

; 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 @GetPartitionCount(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %19, %1
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = icmp ult i32 %6, 14
  br i1 %7, label %8, label %22

8:                                                ; preds = %5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds %struct.StructPartHeader, ptr %9, i64 %11
  store ptr %12, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @IsLastPartition(ptr noundef %13)
  %15 = zext i32 %14 to i64
  %16 = icmp ne i64 %15, 1
  br i1 %16, label %17, label %18

17:                                               ; preds = %8
  br label %22

18:                                               ; preds = %8
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !11

22:                                               ; preds = %17, %5
  %23 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %23
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @IsLastPartition(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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
define dso_local i32 @GetPartitionCount(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @IsLastPartition(ptr noundef %0)
  %.not = icmp eq i32 %2, 1
  br i1 %.not, label %3, label %42

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = tail call i32 @IsLastPartition(ptr noundef nonnull %4)
  %.not.1 = icmp eq i32 %5, 1
  br i1 %.not.1, label %6, label %42

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 128
  %8 = tail call i32 @IsLastPartition(ptr noundef nonnull %7)
  %.not.2 = icmp eq i32 %8, 1
  br i1 %.not.2, label %9, label %42

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 192
  %11 = tail call i32 @IsLastPartition(ptr noundef nonnull %10)
  %.not.3 = icmp eq i32 %11, 1
  br i1 %.not.3, label %12, label %42

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 256
  %14 = tail call i32 @IsLastPartition(ptr noundef nonnull %13)
  %.not.4 = icmp eq i32 %14, 1
  br i1 %.not.4, label %15, label %42

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 320
  %17 = tail call i32 @IsLastPartition(ptr noundef nonnull %16)
  %.not.5 = icmp eq i32 %17, 1
  br i1 %.not.5, label %18, label %42

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 384
  %20 = tail call i32 @IsLastPartition(ptr noundef nonnull %19)
  %.not.6 = icmp eq i32 %20, 1
  br i1 %.not.6, label %21, label %42

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 448
  %23 = tail call i32 @IsLastPartition(ptr noundef nonnull %22)
  %.not.7 = icmp eq i32 %23, 1
  br i1 %.not.7, label %24, label %42

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %0, i64 512
  %26 = tail call i32 @IsLastPartition(ptr noundef nonnull %25)
  %.not.8 = icmp eq i32 %26, 1
  br i1 %.not.8, label %27, label %42

27:                                               ; preds = %24
  %28 = getelementptr inbounds i8, ptr %0, i64 576
  %29 = tail call i32 @IsLastPartition(ptr noundef nonnull %28)
  %.not.9 = icmp eq i32 %29, 1
  br i1 %.not.9, label %30, label %42

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 640
  %32 = tail call i32 @IsLastPartition(ptr noundef nonnull %31)
  %.not.10 = icmp eq i32 %32, 1
  br i1 %.not.10, label %33, label %42

33:                                               ; preds = %30
  %34 = getelementptr inbounds i8, ptr %0, i64 704
  %35 = tail call i32 @IsLastPartition(ptr noundef nonnull %34)
  %.not.11 = icmp eq i32 %35, 1
  br i1 %.not.11, label %36, label %42

36:                                               ; preds = %33
  %37 = getelementptr inbounds i8, ptr %0, i64 768
  %38 = tail call i32 @IsLastPartition(ptr noundef nonnull %37)
  %.not.12 = icmp eq i32 %38, 1
  br i1 %.not.12, label %39, label %42

39:                                               ; preds = %36
  %40 = getelementptr inbounds i8, ptr %0, i64 832
  %41 = tail call i32 @IsLastPartition(ptr noundef nonnull %40)
  %.not.13 = icmp eq i32 %41, 1
  %spec.select = select i1 %.not.13, i32 14, i32 13
  br label %42

42:                                               ; preds = %39, %36, %33, %30, %27, %24, %21, %18, %15, %12, %9, %6, %3, %1
  %.0.lcssa = phi i32 [ 0, %1 ], [ 1, %3 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ], [ 5, %15 ], [ 6, %18 ], [ 7, %21 ], [ 8, %24 ], [ 9, %27 ], [ 10, %30 ], [ 11, %33 ], [ 12, %36 ], [ %spec.select, %39 ]
  ret i32 %.0.lcssa
}

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

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

!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)"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass