; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (SetHandler)

; 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.XEmacPs_Instance = type { %struct.XEmacPs_Config, i32, i32, i32, %struct.XEmacPs_BdRing, %struct.XEmacPs_BdRing, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32 }
%struct.XEmacPs_Config = type { i16, i64, i8, i8, i8, i8, i8, i8, i8 }
%struct.XEmacPs_BdRing = type { i64, i64, i64, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32 }

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

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

14:                                               ; preds = %4
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !9
  br label %16

15:                                               ; preds = %4
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 83)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !9
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %54

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

19:                                               ; preds = %16
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !9
  br label %21

20:                                               ; preds = %16
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 84)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !9
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %54

21:                                               ; preds = %19
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XEmacPs_Instance, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = icmp eq i32 %24, 286331153
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !9
  br label %28

27:                                               ; preds = %21
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 85)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !9
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %54

28:                                               ; preds = %26
  %29 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %29, label %51 [
    i32 1, label %30
    i32 2, label %37
    i32 3, label %44
  ]

30:                                               ; preds = %28
  store i64 0, ptr %10, align 8, !tbaa !17
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XEmacPs_Instance, ptr %32, i32 0, i32 6
  store ptr %31, ptr %33, align 8, !tbaa !18
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XEmacPs_Instance, ptr %35, i32 0, i32 8
  store ptr %34, ptr %36, align 8, !tbaa !19
  br label %52

37:                                               ; preds = %28
  store i64 0, ptr %10, align 8, !tbaa !17
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XEmacPs_Instance, ptr %39, i32 0, i32 7
  store ptr %38, ptr %40, align 8, !tbaa !20
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XEmacPs_Instance, ptr %42, i32 0, i32 9
  store ptr %41, ptr %43, align 8, !tbaa !21
  br label %52

44:                                               ; preds = %28
  store i64 0, ptr %10, align 8, !tbaa !17
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XEmacPs_Instance, ptr %46, i32 0, i32 10
  store ptr %45, ptr %47, align 8, !tbaa !22
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XEmacPs_Instance, ptr %49, i32 0, i32 11
  store ptr %48, ptr %50, align 8, !tbaa !23
  br label %52

51:                                               ; preds = %28
  store i64 15, ptr %10, align 8, !tbaa !17
  br label %52

52:                                               ; preds = %51, %44, %37, %30
  %53 = load i64, ptr %10, align 8, !tbaa !17
  store i64 %53, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %54

54:                                               ; preds = %52, %27, %20, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %55 = load i64, ptr %5, align 8
  ret i64 %55
}

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

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

; 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 = { "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 28}
!12 = !{!"XEmacPs_Instance", !13, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !16, i64 40, !16, i64 152, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !10, i64 312, !10, i64 316, !10, i64 320, !10, i64 324, !10, i64 328}
!13 = !{!"", !14, i64 0, !15, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !7, i64 20, !7, i64 21, !7, i64 22}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104}
!17 = !{!15, !15, i64 0}
!18 = !{!12, !6, i64 264}
!19 = !{!12, !6, i64 280}
!20 = !{!12, !6, i64 272}
!21 = !{!12, !6, i64 288}
!22 = !{!12, !6, i64 296}
!23 = !{!12, !6, i64 304}


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

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

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

5:                                                ; preds = %4
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !5
  %.not20 = icmp eq ptr %2, null
  br i1 %.not20, label %11, label %7

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

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 28
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 286331153
  br i1 %10, label %12, label %13

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

12:                                               ; preds = %7
  switch i32 %1, label %23 [
    i32 1, label %14
    i32 2, label %17
    i32 3, label %20
  ]

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

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 264
  store ptr %2, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %0, i64 280
  store ptr %3, ptr %16, align 8, !tbaa !17
  br label %23

17:                                               ; preds = %12
  %18 = getelementptr inbounds i8, ptr %0, i64 272
  store ptr %2, ptr %18, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %0, i64 288
  store ptr %3, ptr %19, align 8, !tbaa !19
  br label %23

20:                                               ; preds = %12
  %21 = getelementptr inbounds i8, ptr %0, i64 296
  store ptr %2, ptr %21, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %0, i64 304
  store ptr %3, ptr %22, align 8, !tbaa !21
  br label %23

23:                                               ; preds = %14, %17, %20, %12, %13, %11, %6
  %.017 = phi i64 [ 0, %13 ], [ 0, %11 ], [ 0, %6 ], [ 0, %20 ], [ 0, %17 ], [ 0, %14 ], [ 15, %12 ]
  ret i64 %.017
}

declare void @Xil_Assert(ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 28}
!10 = !{!"XEmacPs_Instance", !11, i64 0, !6, i64 24, !6, i64 28, !6, i64 32, !14, i64 40, !14, i64 152, !15, i64 264, !15, i64 272, !15, i64 280, !15, i64 288, !15, i64 296, !15, i64 304, !6, i64 312, !6, i64 316, !6, i64 320, !6, i64 324, !6, i64 328}
!11 = !{!"", !12, i64 0, !13, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !7, i64 20, !7, i64 21, !7, i64 22}
!12 = !{!"short", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !15, i64 80, !6, i64 88, !6, i64 92, !6, i64 96, !6, i64 100, !6, i64 104}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!10, !15, i64 264}
!17 = !{!10, !15, i64 280}
!18 = !{!10, !15, i64 272}
!19 = !{!10, !15, i64 288}
!20 = !{!10, !15, i64 296}
!21 = !{!10, !15, i64 304}


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