; LLVM IR from lfarcaro/ARINC653_ARMV7A_Z7000 :: ARINC653_ARMV7A_Z7000.sw/ARINC653_ARMV7A_Z7000_bsp/ps7_cortexa9_0/libsrc (GenDmaProg)

; 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.XDmaPs = type { %struct.XDmaPs_Config, i32, i32, ptr, ptr, [8 x %struct.XDmaPs_ChannelData] }
%struct.XDmaPs_Config = type { i16, i32 }
%struct.XDmaPs_ChannelData = type { i32, i32, [2 x %struct.XDmaPs_ProgBuf], ptr, ptr, ptr, ptr, i32 }
%struct.XDmaPs_ProgBuf = type { [128 x i8], i32, i32 }
%struct.XDmaPs_Cmd = type { %struct.XDmaPs_ChanCtrl, %struct.XDmaPs_BD, ptr, i32, ptr, i32, i32, i32, i32 }
%struct.XDmaPs_ChanCtrl = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.XDmaPs_BD = type { i32, i32, i32 }

@Xil_AssertStatus = external global i32, align 4
@.str = external hidden unnamed_addr constant [161 x i8], align 1

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

declare void @Xil_Assert(ptr noundef, i32 noundef) #1

; 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 hidden void @XDmaPs_BufPool_Free(ptr noundef, ptr noundef) #2

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

15:                                               ; preds = %3
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !9
  br label %17

16:                                               ; preds = %3
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 1338)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

17:                                               ; preds = %15
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !9
  br label %22

21:                                               ; preds = %17
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 1339)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

22:                                               ; preds = %20
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp ugt i32 %23, 8
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XDmaPs, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds [8 x %struct.XDmaPs_ChannelData], ptr %28, i64 0, i64 0
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds %struct.XDmaPs_ChannelData, ptr %29, i64 %31
  store ptr %32, ptr %10, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XDmaPs_Cmd, ptr %33, i32 0, i32 0
  store ptr %34, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %35, i32 0, i32 9
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %38, i32 0, i32 8
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = mul i32 %37, %40
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %42, i32 0, i32 4
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = mul i32 %44, %47
  %49 = icmp ne i32 %41, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %26
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

51:                                               ; preds = %26
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %52, i32 0, i32 10
  %54 = load i32, ptr %53, align 4, !tbaa !16
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %67, label %56

56:                                               ; preds = %51
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.XDmaPs_Cmd, ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds %struct.XDmaPs_BD, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !17
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %61, i32 0, i32 9
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = urem i32 %60, %63
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %56
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

67:                                               ; preds = %56, %51
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %68, i32 0, i32 5
  %70 = load i32, ptr %69, align 4, !tbaa !20
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %83, label %72

72:                                               ; preds = %67
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.XDmaPs_Cmd, ptr %73, i32 0, i32 1
  %75 = getelementptr inbounds %struct.XDmaPs_BD, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !21
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.XDmaPs_ChanCtrl, ptr %77, i32 0, i32 4
  %79 = load i32, ptr %78, align 4, !tbaa !14
  %80 = urem i32 %76, %79
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %72
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

83:                                               ; preds = %72, %67
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.XDmaPs_ChannelData, ptr %84, i32 0, i32 2
  %86 = getelementptr inbounds [2 x %struct.XDmaPs_ProgBuf], ptr %85, i64 0, i64 0
  %87 = call ptr @XDmaPs_BufPool_Allocate(ptr noundef %86)
  store ptr %87, ptr %8, align 8, !tbaa !5
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = icmp eq ptr %88, null
  br i1 %89, label %90, label %91

90:                                               ; preds = %83
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

91:                                               ; preds = %83
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.XDmaPs_Cmd, ptr %93, i32 0, i32 4
  store ptr %92, ptr %94, align 8, !tbaa !22
  %95 = load i32, ptr %6, align 4, !tbaa !9
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.XDmaPs, ptr %97, i32 0, i32 2
  %99 = load i32, ptr %98, align 4, !tbaa !23
  %100 = call i32 @XDmaPs_BuildDmaProg(i32 noundef %95, ptr noundef %96, i32 noundef %99)
  store i32 %100, ptr %9, align 4, !tbaa !9
  %101 = load i32, ptr %9, align 4, !tbaa !9
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.XDmaPs_Cmd, ptr %102, i32 0, i32 5
  store i32 %101, ptr %103, align 8, !tbaa !27
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = icmp sle i32 %104, 0
  br i1 %105, label %106, label %115

106:                                              ; preds = %91
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.XDmaPs_ChannelData, ptr %107, i32 0, i32 2
  %109 = getelementptr inbounds [2 x %struct.XDmaPs_ProgBuf], ptr %108, i64 0, i64 0
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  call void @XDmaPs_BufPool_Free(ptr noundef %109, ptr noundef %110)
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.XDmaPs_Cmd, ptr %111, i32 0, i32 5
  store i32 0, ptr %112, align 8, !tbaa !27
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.XDmaPs_Cmd, ptr %113, i32 0, i32 4
  store ptr null, ptr %114, align 8, !tbaa !22
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

115:                                              ; preds = %91
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %116

116:                                              ; preds = %115, %106, %90, %82, %66, %50, %25, %21, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %117 = load i32, ptr %4, align 4
  ret i32 %117
}

; Function Attrs: nounwind uwtable
declare hidden ptr @XDmaPs_BufPool_Allocate(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @XDmaPs_BuildDmaProg(i32 noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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, !10, i64 36}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40}
!13 = !{!12, !10, i64 32}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 40}
!17 = !{!18, !10, i64 44}
!18 = !{!"", !12, i64 0, !19, i64 44, !6, i64 56, !10, i64 64, !6, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92}
!19 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!20 = !{!12, !10, i64 20}
!21 = !{!18, !10, i64 48}
!22 = !{!18, !6, i64 72}
!23 = !{!24, !10, i64 12}
!24 = !{!"", !25, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !7, i64 32}
!25 = !{!"", !26, i64 0, !10, i64 4}
!26 = !{!"short", !7, i64 0}
!27 = !{!18, !10, i64 80}


; 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.XDmaPs_ChannelData = type { i32, i32, [2 x %struct.XDmaPs_ProgBuf], ptr, ptr, ptr, ptr, i32 }
%struct.XDmaPs_ProgBuf = type { [128 x i8], i32, i32 }

@Xil_AssertStatus = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [161 x i8], align 1

declare void @Xil_Assert(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @XDmaPs_BufPool_Free(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @XDmaPs_GenDmaProg(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %3
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !5
  %.not34 = icmp eq ptr %2, null
  br i1 %.not34, label %8, label %6

5:                                                ; preds = %3
  tail call void @Xil_Assert(ptr noundef nonnull @.str, i32 noundef 1338) #2
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !5
  br label %48

6:                                                ; preds = %4
  %7 = icmp ugt i32 %1, 8
  br i1 %7, label %48, label %9

8:                                                ; preds = %4
  tail call void @Xil_Assert(ptr noundef nonnull @.str, i32 noundef 1339) #2
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !5
  br label %48

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = zext nneg i32 %1 to i64
  %12 = getelementptr inbounds i8, ptr %2, i64 36
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %2, i64 32
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = mul i32 %15, %13
  %17 = getelementptr inbounds i8, ptr %2, i64 16
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %2, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = mul i32 %20, %18
  %.not35 = icmp eq i32 %16, %21
  br i1 %.not35, label %22, label %48

22:                                               ; preds = %9
  %23 = getelementptr inbounds i8, ptr %2, i64 40
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %.not36 = icmp eq i32 %24, 0
  br i1 %.not36, label %25, label %29

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %2, i64 44
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %28 = urem i32 %27, %13
  %.not37 = icmp eq i32 %28, 0
  br i1 %.not37, label %29, label %48

29:                                               ; preds = %25, %22
  %30 = getelementptr inbounds i8, ptr %2, i64 20
  %31 = load i32, ptr %30, align 4, !tbaa !19
  %.not38 = icmp eq i32 %31, 0
  br i1 %.not38, label %32, label %36

32:                                               ; preds = %29
  %33 = getelementptr inbounds i8, ptr %2, i64 48
  %34 = load i32, ptr %33, align 4, !tbaa !20
  %35 = urem i32 %34, %18
  %.not39 = icmp eq i32 %35, 0
  br i1 %.not39, label %36, label %48

36:                                               ; preds = %32, %29
  %37 = getelementptr inbounds %struct.XDmaPs_ChannelData, ptr %10, i64 %11, i32 2
  %38 = tail call ptr @XDmaPs_BufPool_Allocate(ptr noundef nonnull %37)
  %39 = icmp eq ptr %38, null
  br i1 %39, label %48, label %40

40:                                               ; preds = %36
  %41 = getelementptr inbounds i8, ptr %2, i64 72
  store ptr %38, ptr %41, align 8, !tbaa !21
  %42 = getelementptr inbounds i8, ptr %0, i64 12
  %43 = load i32, ptr %42, align 4, !tbaa !22
  %44 = tail call i32 @XDmaPs_BuildDmaProg(i32 noundef %1, ptr noundef nonnull %2, i32 noundef %43)
  %45 = getelementptr inbounds i8, ptr %2, i64 80
  store i32 %44, ptr %45, align 8, !tbaa !26
  %46 = icmp slt i32 %44, 1
  br i1 %46, label %47, label %48

47:                                               ; preds = %40
  tail call void @XDmaPs_BufPool_Free(ptr noundef nonnull %37, ptr noundef nonnull %38)
  store i32 0, ptr %45, align 8, !tbaa !26
  store ptr null, ptr %41, align 8, !tbaa !21
  br label %48

48:                                               ; preds = %40, %36, %32, %25, %9, %6, %47, %8, %5
  %.0 = phi i32 [ 1, %47 ], [ 0, %8 ], [ 0, %5 ], [ 1, %6 ], [ 1, %9 ], [ 1, %25 ], [ 1, %32 ], [ 1, %36 ], [ 0, %40 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @XDmaPs_BufPool_Allocate(ptr noundef) local_unnamed_addr #1

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

attributes #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 = { 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"}
!9 = !{!10, !6, i64 36}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40}
!11 = !{!10, !6, i64 32}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 12}
!14 = !{!10, !6, i64 40}
!15 = !{!16, !6, i64 44}
!16 = !{!"", !10, i64 0, !17, i64 44, !18, i64 56, !6, i64 64, !18, i64 72, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92}
!17 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8}
!18 = !{!"any pointer", !7, i64 0}
!19 = !{!10, !6, i64 20}
!20 = !{!16, !6, i64 48}
!21 = !{!16, !18, i64 72}
!22 = !{!23, !6, i64 12}
!23 = !{!"", !24, i64 0, !6, i64 8, !6, i64 12, !18, i64 16, !18, i64 24, !7, i64 32}
!24 = !{!"", !25, i64 0, !6, i64 4}
!25 = !{!"short", !7, i64 0}
!26 = !{!16, !6, i64 80}


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