; LLVM IR from steps3d/graphics-book :: Code/Chapter-7/circle.ll (Z11drawCircle1R8TgaImageiiij)

; 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: mustprogress uwtable
declare dso_local void @_Z16drawCirclePointsR8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11drawCircle1R8TgaImageiiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca float, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %14 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %14, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = sitofp i32 %15 to float
  %17 = fsub float 1.250000e+00, %16
  store float %17, ptr %13, align 4, !tbaa !11
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z16drawCirclePointsR8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16) %18, i32 noundef %19, i32 noundef %20, i32 noundef %21, i32 noundef %22, i32 noundef %23)
  br label %24

24:                                               ; preds = %53, %5
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = icmp sgt i32 %25, %26
  br i1 %27, label %28, label %60

28:                                               ; preds = %24
  %29 = load float, ptr %13, align 4, !tbaa !11
  %30 = fcmp olt float %29, 0.000000e+00
  br i1 %30, label %31, label %40

31:                                               ; preds = %28
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = mul nsw i32 2, %32
  %34 = add nsw i32 %33, 3
  %35 = sitofp i32 %34 to float
  %36 = load float, ptr %13, align 4, !tbaa !11
  %37 = fadd float %36, %35
  store float %37, ptr %13, align 4, !tbaa !11
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %11, align 4, !tbaa !9
  br label %53

40:                                               ; preds = %28
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = sub nsw i32 %41, %42
  %44 = mul nsw i32 2, %43
  %45 = add nsw i32 %44, 5
  %46 = sitofp i32 %45 to float
  %47 = load float, ptr %13, align 4, !tbaa !11
  %48 = fadd float %47, %46
  store float %48, ptr %13, align 4, !tbaa !11
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %11, align 4, !tbaa !9
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %12, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %40, %31
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z16drawCirclePointsR8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16) %54, i32 noundef %55, i32 noundef %56, i32 noundef %57, i32 noundef %58, i32 noundef %59)
  br label %24, !llvm.loop !13

60:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

; 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 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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: mustprogress uwtable
declare dso_local void @_Z16drawCirclePointsR8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11drawCircle1R8TgaImageiiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  tail call void @_Z16drawCirclePointsR8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef 0, i32 noundef %3, i32 noundef %4)
  %6 = icmp sgt i32 %3, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %7 = uitofp nneg i32 %3 to float
  %8 = fsub float 1.250000e+00, %7
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %.030 = phi float [ %.1, %18 ], [ %8, %.lr.ph.preheader ]
  %.02429 = phi i32 [ %.125, %18 ], [ %3, %.lr.ph.preheader ]
  %.02628 = phi i32 [ %.127, %18 ], [ 0, %.lr.ph.preheader ]
  %9 = fcmp olt float %.030, 0.000000e+00
  br i1 %9, label %10, label %13

10:                                               ; preds = %.lr.ph
  %11 = shl nuw nsw i32 %.02628, 1
  %12 = add nuw nsw i32 %11, 3
  br label %18

13:                                               ; preds = %.lr.ph
  %14 = sub nsw i32 %.02628, %.02429
  %15 = shl nsw i32 %14, 1
  %16 = add nsw i32 %15, 5
  %17 = add nsw i32 %.02429, -1
  br label %18

18:                                               ; preds = %13, %10
  %.125 = phi i32 [ %.02429, %10 ], [ %17, %13 ]
  %.pn.in = phi i32 [ %12, %10 ], [ %16, %13 ]
  %.pn = sitofp i32 %.pn.in to float
  %.1 = fadd float %.030, %.pn
  %.127 = add nuw nsw i32 %.02628, 1
  tail call void @_Z16drawCirclePointsR8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef %.127, i32 noundef %.125, i32 noundef %4)
  %19 = icmp sgt i32 %.125, %.127
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %18, %5
  ret void
}

attributes #0 = { mustprogress 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" }

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass