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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9drawLine3R8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #2 {
  %7 = alloca ptr, align 8
  %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
  %14 = alloca float, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = sub nsw i32 %17, %18
  %20 = sitofp i32 %19 to float
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sub nsw i32 %21, %22
  %24 = sitofp i32 %23 to float
  %25 = fdiv float %20, %24
  store float %25, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store float 0.000000e+00, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %26 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %26, ptr %15, align 4, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %27, i32 noundef %28, i32 noundef %29, i32 noundef %30)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %16, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %53, %6
  %34 = load i32, ptr %16, align 4, !tbaa !9
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %56

38:                                               ; preds = %33
  %39 = load float, ptr %13, align 4, !tbaa !11
  %40 = load float, ptr %14, align 4, !tbaa !11
  %41 = fadd float %40, %39
  store float %41, ptr %14, align 4, !tbaa !11
  %42 = fcmp ogt float %41, 5.000000e-01
  br i1 %42, label %43, label %48

43:                                               ; preds = %38
  %44 = load float, ptr %14, align 4, !tbaa !11
  %45 = fadd float %44, -1.000000e+00
  store float %45, ptr %14, align 4, !tbaa !11
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %15, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %43, %38
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i32, ptr %16, align 4, !tbaa !9
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %49, i32 noundef %50, i32 noundef %51, i32 noundef %52)
  br label %53

53:                                               ; preds = %48
  %54 = load i32, ptr %16, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %16, align 4, !tbaa !9
  br label %33, !llvm.loop !13

56:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #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 = !{!"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 nounwind uwtable
declare dso_local void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z9drawLine3R8TgaImageiiiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = sub nsw i32 %4, %2
  %8 = sitofp i32 %7 to float
  %9 = sub nsw i32 %3, %1
  %10 = sitofp i32 %9 to float
  %11 = fdiv float %8, %10
  tail call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef %5)
  %.not.not25 = icmp slt i32 %1, %3
  br i1 %.not.not25, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %6
  ret void

.lr.ph:                                           ; preds = %6, %.lr.ph
  %.0.in28 = phi i32 [ %.0, %.lr.ph ], [ %1, %6 ]
  %.02027 = phi i32 [ %.1, %.lr.ph ], [ %2, %6 ]
  %.02126 = phi float [ %.122, %.lr.ph ], [ 0.000000e+00, %6 ]
  %.0 = add nsw i32 %.0.in28, 1
  %12 = fadd float %11, %.02126
  %13 = fcmp ogt float %12, 5.000000e-01
  %14 = fadd float %12, -1.000000e+00
  %.122 = select i1 %13, float %14, float %12
  %15 = zext i1 %13 to i32
  %.1 = add nsw i32 %.02027, %15
  tail call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.0, i32 noundef %.1, i32 noundef %5)
  %exitcond.not = icmp eq i32 %.0, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

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

!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: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass