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

; 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 @_Z13drawLine4ConnR8TgaImageiiiij(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 i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = 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
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sub nsw i32 %21, %22
  store i32 %23, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sub nsw i32 %24, %25
  store i32 %26, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = shl i32 %27, 1
  %29 = load i32, ptr %13, align 4, !tbaa !9
  %30 = sub nsw i32 %28, %29
  store i32 %30, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = shl i32 %31, 1
  store i32 %32, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %33 = load i32, ptr %14, align 4, !tbaa !9
  %34 = load i32, ptr %13, align 4, !tbaa !9
  %35 = sub nsw i32 %33, %34
  %36 = shl i32 %35, 1
  store i32 %36, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %37 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %37, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %38 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %38, ptr %19, align 4, !tbaa !9
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %39, i32 noundef %40, i32 noundef %41, i32 noundef %42)
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  store i32 1, ptr %20, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %70, %6
  %44 = load i32, ptr %20, align 4, !tbaa !9
  %45 = load i32, ptr %14, align 4, !tbaa !9
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = add nsw i32 %45, %46
  %48 = icmp sle i32 %44, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  br label %73

50:                                               ; preds = %43
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %53, label %59

53:                                               ; preds = %50
  %54 = load i32, ptr %17, align 4, !tbaa !9
  %55 = load i32, ptr %15, align 4, !tbaa !9
  %56 = add nsw i32 %55, %54
  store i32 %56, ptr %15, align 4, !tbaa !9
  %57 = load i32, ptr %19, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %19, align 4, !tbaa !9
  br label %65

59:                                               ; preds = %50
  %60 = load i32, ptr %16, align 4, !tbaa !9
  %61 = load i32, ptr %15, align 4, !tbaa !9
  %62 = add nsw i32 %61, %60
  store i32 %62, ptr %15, align 4, !tbaa !9
  %63 = load i32, ptr %18, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %18, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %59, %53
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i32, ptr %18, align 4, !tbaa !9
  %68 = load i32, ptr %19, align 4, !tbaa !9
  %69 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %66, i32 noundef %67, i32 noundef %68, i32 noundef %69)
  br label %70

70:                                               ; preds = %65
  %71 = load i32, ptr %20, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %20, align 4, !tbaa !9
  br label %43, !llvm.loop !11

73:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  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 = distinct !{!11, !12}
!12 = !{!"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 @_Z13drawLine4ConnR8TgaImageiiiij(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 %3, %1
  %8 = sub nsw i32 %4, %2
  %9 = shl i32 %8, 1
  %10 = sub nsw i32 %8, %7
  %11 = shl i32 %10, 1
  tail call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2, i32 noundef %5)
  %12 = add nsw i32 %8, %7
  %.not34 = icmp slt i32 %12, 1
  br i1 %.not34, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %13 = sub nsw i32 %9, %7
  br label %.lr.ph

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.038 = phi i32 [ %17, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.02937 = phi i32 [ %.1, %.lr.ph ], [ %2, %.lr.ph.preheader ]
  %.03036 = phi i32 [ %.131, %.lr.ph ], [ %1, %.lr.ph.preheader ]
  %.03235 = phi i32 [ %.133, %.lr.ph ], [ %13, %.lr.ph.preheader ]
  %14 = icmp slt i32 %.03235, 1
  %.pn = select i1 %14, i32 %9, i32 %11
  %15 = zext i1 %14 to i32
  %.131 = add nsw i32 %.03036, %15
  %not. = xor i1 %14, true
  %16 = zext i1 %not. to i32
  %.1 = add nsw i32 %.02937, %16
  %.133 = add nsw i32 %.pn, %.03235
  tail call void @_ZN8TgaImage8putPixelEiij(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.131, i32 noundef %.1, i32 noundef %5)
  %17 = add nuw nsw i32 %.038, 1
  %.not.not = icmp slt i32 %.038, %12
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass