; LLVM IR from koshkin-sergey/mbOS :: Device/ADI/ADuC7023/Driver (RTOS_TIMER_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.RTOS_TIMER_s = type { i16, i16, i16, i16, i16, i16, i8, i8 }

@SystemCoreClock = external global i32, align 4

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

10:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %29

11:                                               ; preds = %2
  %12 = load i32, ptr @SystemCoreClock, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = udiv i32 %12, %13
  store i32 %14, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = icmp ugt i64 %16, 65535
  br i1 %17, label %18, label %19

18:                                               ; preds = %11
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %29

19:                                               ; preds = %11
  store volatile i16 64, ptr getelementptr inbounds (%struct.RTOS_TIMER_s, ptr inttoptr (i64 4294902528 to ptr), i32 0, i32 4), align 2, !tbaa !11
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = trunc i32 %20 to i16
  store volatile i16 %21, ptr inttoptr (i64 4294902528 to ptr), align 2, !tbaa !14
  %22 = call i32 @IRQ_Disable(i32 noundef 2)
  %23 = call i32 @IRQ_ClearPending(i32 noundef 2)
  %24 = call i32 @IRQ_SetPriority(i32 noundef 2, i32 noundef 7)
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = call i32 @IRQ_SetHandler(i32 noundef 2, ptr noundef %25)
  %27 = call i32 @IRQ_SetMode(i32 noundef 2, i32 noundef 0)
  %28 = call i32 @IRQ_Enable(i32 noundef 2)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %29

29:                                               ; preds = %19, %18, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %30 = load i32, ptr %3, align 4
  ret i32 %30
}

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

declare i32 @IRQ_Disable(i32 noundef) #2

declare i32 @IRQ_ClearPending(i32 noundef) #2

declare i32 @IRQ_SetPriority(i32 noundef, i32 noundef) #2

declare i32 @IRQ_SetHandler(i32 noundef, ptr noundef) #2

declare i32 @IRQ_SetMode(i32 noundef, i32 noundef) #2

declare i32 @IRQ_Enable(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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"RTOS_TIMER_s", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10, !7, i64 12, !7, i64 13}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 0}


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

@SystemCoreClock = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @osTickSetup(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %16, label %4

4:                                                ; preds = %2
  %5 = load i32, ptr @SystemCoreClock, align 4, !tbaa !5
  %6 = udiv i32 %5, %0
  %7 = icmp ugt i32 %6, 65535
  br i1 %7, label %16, label %8

8:                                                ; preds = %4
  store volatile i16 64, ptr inttoptr (i64 4294902536 to ptr), align 8, !tbaa !9
  %9 = trunc nuw i32 %6 to i16
  store volatile i16 %9, ptr inttoptr (i64 4294902528 to ptr), align 256, !tbaa !12
  %10 = tail call i32 @IRQ_Disable(i32 noundef 2) #2
  %11 = tail call i32 @IRQ_ClearPending(i32 noundef 2) #2
  %12 = tail call i32 @IRQ_SetPriority(i32 noundef 2, i32 noundef 7) #2
  %13 = tail call i32 @IRQ_SetHandler(i32 noundef 2, ptr noundef %1) #2
  %14 = tail call i32 @IRQ_SetMode(i32 noundef 2, i32 noundef 0) #2
  %15 = tail call i32 @IRQ_Enable(i32 noundef 2) #2
  br label %16

16:                                               ; preds = %4, %2, %8
  %.0 = phi i32 [ 0, %8 ], [ -1, %2 ], [ -1, %4 ]
  ret i32 %.0
}

declare i32 @IRQ_Disable(i32 noundef) local_unnamed_addr #1

declare i32 @IRQ_ClearPending(i32 noundef) local_unnamed_addr #1

declare i32 @IRQ_SetPriority(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @IRQ_SetHandler(i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @IRQ_SetMode(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @IRQ_Enable(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, !11, i64 8}
!10 = !{!"RTOS_TIMER_s", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !11, i64 8, !11, i64 10, !7, i64 12, !7, i64 13}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 0}


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