; LLVM IR from gem5/gem5 :: util/term (term)

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

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

15:                                               ; preds = %46, %38, %4
  %16 = load i64, ptr %9, align 8, !tbaa !11
  %17 = load i64, ptr %12, align 8, !tbaa !11
  %18 = icmp ugt i64 %16, %17
  br i1 %18, label %19, label %47

19:                                               ; preds = %15
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = load i64, ptr %12, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %22, i64 %23
  %25 = load i64, ptr %9, align 8, !tbaa !11
  %26 = load i64, ptr %12, align 8, !tbaa !11
  %27 = sub i64 %25, %26
  %28 = call i64 (i32, ptr, i64, ...) %20(i32 noundef %21, ptr noundef %24, i64 noundef %27)
  store i64 %28, ptr %11, align 8, !tbaa !11
  %29 = load i64, ptr %11, align 8, !tbaa !11
  switch i64 %29, label %42 [
    i64 -1, label %30
    i64 0, label %40
  ]

30:                                               ; preds = %19
  %31 = call ptr @__errno_location() #4
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 4
  br i1 %33, label %38, label %34

34:                                               ; preds = %30
  %35 = call ptr @__errno_location() #4
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 11
  br i1 %37, label %38, label %39

38:                                               ; preds = %34, %30
  br label %15, !llvm.loop !13

39:                                               ; preds = %34
  br label %40

40:                                               ; preds = %39, %19
  %41 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %41, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %49

42:                                               ; preds = %19
  %43 = load i64, ptr %11, align 8, !tbaa !11
  %44 = load i64, ptr %12, align 8, !tbaa !11
  %45 = add nsw i64 %44, %43
  store i64 %45, ptr %12, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %42
  br label %15, !llvm.loop !13

47:                                               ; preds = %15
  %48 = load i64, ptr %12, align 8, !tbaa !11
  store i64 %48, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %49

49:                                               ; preds = %47, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %50 = load i64, ptr %5, align 8
  ret i64 %50
}

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

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 willreturn memory(none) "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 }
attributes #4 = { nounwind willreturn memory(none) }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 i64 @atomicio(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.outer._crit_edge, label %.lr.ph.split.us.preheader

.lr.ph.split.us.preheader:                        ; preds = %4, %.outer
  %.0.ph28 = phi i64 [ %11, %.outer ], [ 0, %4 ]
  %5 = getelementptr inbounds i8, ptr %2, i64 %.0.ph28
  %6 = sub i64 %3, %.0.ph28
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.backedge, %.lr.ph.split.us.preheader
  %7 = tail call i64 (i32, ptr, i64, ...) %0(i32 noundef %1, ptr noundef %5, i64 noundef %6) #2
  switch i64 %7, label %.outer [
    i64 -1, label %8
    i64 0, label %.outer._crit_edge
  ]

8:                                                ; preds = %.lr.ph.split.us
  %9 = tail call ptr @__errno_location() #3
  %10 = load i32, ptr %9, align 4, !tbaa !5
  switch i32 %10, label %.outer._crit_edge [
    i32 4, label %.lr.ph.split.us.backedge
    i32 11, label %.lr.ph.split.us.backedge
  ]

.lr.ph.split.us.backedge:                         ; preds = %8, %8
  br label %.lr.ph.split.us

.outer:                                           ; preds = %.lr.ph.split.us
  %11 = add nsw i64 %7, %.0.ph28
  %12 = icmp ult i64 %11, %3
  br i1 %12, label %.lr.ph.split.us.preheader, label %.outer._crit_edge, !llvm.loop !9

.outer._crit_edge:                                ; preds = %.outer, %8, %.lr.ph.split.us, %4
  %.014 = phi i64 [ 0, %4 ], [ %7, %.lr.ph.split.us ], [ %7, %8 ], [ %11, %.outer ]
  ret i64 %.014
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 }
attributes #3 = { nounwind willreturn memory(none) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass