; LLVM IR from koshkin-sergey/mbOS :: Device/ADI/ADuC7023/Driver (IRQ_ADUC7023)

; 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.IRQ_MODE_INFO_s = type { i32 }
%struct.IRQ_s = type { i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, i32, %struct.EXT_IRQ, i32 }
%struct.EXT_IRQ = type { i32, i32 }
%struct.FIQ_s = type { i32, i32, i32, i32, [4 x i32], i32, i32 }

@irq_table = external hidden global [22 x ptr], section ".bss.irq_table", align 128
@irq_mode = external hidden global %struct.IRQ_MODE_INFO_s, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @IRQ_Initialize() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 ptrtoint (ptr @irq_table to i32), ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = and i32 %5, -8388481
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %24

9:                                                ; preds = %0
  store i32 0, ptr @irq_mode, align 4, !tbaa !9
  store volatile i32 -1, ptr getelementptr inbounds (%struct.IRQ_s, ptr inttoptr (i64 4294901760 to ptr), i32 0, i32 3), align 4, !tbaa !11
  store volatile i32 -1, ptr getelementptr inbounds (%struct.FIQ_s, ptr inttoptr (i64 4294902016 to ptr), i32 0, i32 3), align 4, !tbaa !14
  store volatile i32 0, ptr getelementptr inbounds (%struct.IRQ_s, ptr inttoptr (i64 4294901760 to ptr), i32 0, i32 8), align 4, !tbaa !5
  store volatile i32 0, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds (%struct.IRQ_s, ptr inttoptr (i64 4294901760 to ptr), i32 0, i32 8), i64 0, i64 1), align 4, !tbaa !5
  store volatile i32 0, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds (%struct.IRQ_s, ptr inttoptr (i64 4294901760 to ptr), i32 0, i32 8), i64 0, i64 2), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %18, %9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp ult i32 %11, 22
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %21

14:                                               ; preds = %10
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [22 x ptr], ptr @irq_table, i64 0, i64 %16
  store ptr null, ptr %17, align 8, !tbaa !16
  br label %18

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

21:                                               ; preds = %13
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = lshr i32 %22, 7
  store volatile i32 %23, ptr getelementptr inbounds (%struct.IRQ_s, ptr inttoptr (i64 4294901760 to ptr), i32 0, i32 5), align 4, !tbaa !20
  store volatile i32 3, ptr getelementptr inbounds (%struct.IRQ_s, ptr inttoptr (i64 4294901760 to ptr), i32 0, i32 10), align 4, !tbaa !21
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %24

24:                                               ; preds = %21, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  %25 = load i32, ptr %1, align 4
  ret i32 %25
}

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

; 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 = { 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 0}
!10 = !{!"IRQ_MODE_INFO_s", !6, i64 0}
!11 = !{!12, !6, i64 12}
!12 = !{!"IRQ_s", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !7, i64 32, !6, i64 44, !6, i64 48, !13, i64 52, !6, i64 60}
!13 = !{!"EXT_IRQ", !6, i64 0, !6, i64 4}
!14 = !{!15, !6, i64 12}
!15 = !{!"FIQ_s", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !6, i64 32, !6, i64 36}
!16 = !{!17, !17, i64 0}
!17 = !{!"any pointer", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !6, i64 20}
!21 = !{!12, !6, i64 48}


; 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.IRQ_MODE_INFO_s = type { i32 }

@irq_table = external hidden global [22 x ptr], section ".bss.irq_table", align 128
@irq_mode = external hidden local_unnamed_addr global %struct.IRQ_MODE_INFO_s, align 4

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 -1, 1) i32 @IRQ_Initialize() local_unnamed_addr #0 {
  %.not = icmp ult i32 ptrtoint (ptr @irq_table to i32), 8388608
  br i1 %.not, label %1, label %3

1:                                                ; preds = %0
  store i32 0, ptr @irq_mode, align 4, !tbaa !5
  store volatile i32 -1, ptr inttoptr (i64 4294901772 to ptr), align 4, !tbaa !10
  store volatile i32 -1, ptr inttoptr (i64 4294902028 to ptr), align 4, !tbaa !13
  store volatile i32 0, ptr inttoptr (i64 4294901792 to ptr), align 32, !tbaa !15
  store volatile i32 0, ptr inttoptr (i64 4294901796 to ptr), align 4, !tbaa !15
  store volatile i32 0, ptr inttoptr (i64 4294901800 to ptr), align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 128 dereferenceable(176) @irq_table, i8 0, i64 176, i1 false), !tbaa !16
  %2 = lshr exact i32 ptrtoint (ptr @irq_table to i32), 7
  store volatile i32 %2, ptr inttoptr (i64 4294901780 to ptr), align 4, !tbaa !18
  store volatile i32 3, ptr inttoptr (i64 4294901808 to ptr), align 16, !tbaa !19
  br label %3

3:                                                ; preds = %0, %1
  %.06 = phi i32 [ 0, %1 ], [ -1, %0 ]
  ret i32 %.06
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

!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, !7, i64 0}
!6 = !{!"IRQ_MODE_INFO_s", !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 12}
!11 = !{!"IRQ_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !8, i64 32, !7, i64 44, !7, i64 48, !12, i64 52, !7, i64 60}
!12 = !{!"EXT_IRQ", !7, i64 0, !7, i64 4}
!13 = !{!14, !7, i64 12}
!14 = !{!"FIQ_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !7, i64 32, !7, i64 36}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!11, !7, i64 20}
!19 = !{!11, !7, i64 48}


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