; LLVM IR from ESPboy-edu/ESPboy_tinyphysicsengine :: programs (hello)

; 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: nounwind uwtable
define dso_local i32 @TPE_sqrt(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  store i8 1, ptr %3, align 1, !tbaa !9
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  store i8 -1, ptr %3, align 1, !tbaa !9
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = mul nsw i32 %10, -1
  store i32 %11, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %9, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %13 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %13, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1073741824, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %18, %12
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp ugt i32 %15, %16
  br i1 %17, label %18, label %21

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

21:                                               ; preds = %14
  br label %22

22:                                               ; preds = %41, %21
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %46

25:                                               ; preds = %22
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = add i32 %27, %28
  %30 = icmp uge i32 %26, %29
  br i1 %30, label %31, label %41

31:                                               ; preds = %25
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = add i32 %32, %33
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sub i32 %35, %34
  store i32 %36, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = mul i32 2, %38
  %40 = add i32 %37, %39
  store i32 %40, ptr %4, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %31, %25
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = lshr i32 %42, 2
  store i32 %43, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = lshr i32 %44, 1
  store i32 %45, ptr %4, align 4, !tbaa !5
  br label %22, !llvm.loop !12

46:                                               ; preds = %22
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = load i8, ptr %3, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = mul i32 %47, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i32 %50
}

; 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; 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: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @TPE_sqrt(i32 noundef %0) local_unnamed_addr #0 {
  %spec.select = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
  br label %2

2:                                                ; preds = %2, %1
  %.0 = phi i32 [ 1073741824, %1 ], [ %4, %2 ]
  %3 = icmp ugt i32 %.0, %spec.select
  %4 = lshr i32 %.0, 2
  br i1 %3, label %2, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %2
  %.not31 = icmp eq i32 %.0, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.134 = phi i32 [ %9, %.lr.ph ], [ %.0, %.preheader ]
  %.01933 = phi i32 [ %.120, %.lr.ph ], [ %spec.select, %.preheader ]
  %.02132 = phi i32 [ %10, %.lr.ph ], [ 0, %.preheader ]
  %5 = add nuw i32 %.134, %.02132
  %.not28 = icmp ult i32 %.01933, %5
  %6 = shl nuw i32 %.134, 1
  %7 = select i1 %.not28, i32 0, i32 %6
  %.122 = add i32 %7, %.02132
  %8 = select i1 %.not28, i32 0, i32 %5
  %.120 = sub i32 %.01933, %8
  %9 = lshr i32 %.134, 2
  %10 = lshr i32 %.122, 1
  %.not = icmp ult i32 %.134, 4
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.021.lcssa = phi i32 [ 0, %.preheader ], [ %10, %.lr.ph ]
  %11 = sub nsw i32 0, %.021.lcssa
  %.inv30 = icmp slt i32 %0, 0
  %12 = select i1 %.inv30, i32 %11, i32 %.021.lcssa
  ret i32 %12
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(none) 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 speculatable 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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