; LLVM IR from jpvt/Computer_Graphics :: Assignment #1/mygl_framework (mygl)

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

%struct.Pixel = type { %struct.Tuple, %struct.RGBA_Colors }
%struct.Tuple = type { i32, i32 }
%struct.RGBA_Colors = type { i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @PutPixel(ptr noundef byval(%struct.Pixel) align 8) #0

; Function Attrs: nounwind uwtable
declare dso_local void @LinearColorInterpolation(ptr noundef byval(%struct.Pixel) align 8, ptr noundef, ptr noundef byval(%struct.Pixel) align 8) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local void @DrawPixelLineX(ptr noundef byval(%struct.Pixel) align 8 %0, ptr noundef byval(%struct.Pixel) align 8 %1) #0 {
  %3 = alloca %struct.Pixel, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 8 %0, i64 24, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = getelementptr inbounds %struct.Pixel, ptr %1, i32 0, i32 0
  %9 = getelementptr inbounds %struct.Tuple, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !10
  %11 = getelementptr inbounds %struct.Pixel, ptr %0, i32 0, i32 0
  %12 = getelementptr inbounds %struct.Tuple, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !10
  %14 = sub i32 %10, %13
  store i32 %14, ptr %5, align 4, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %15 = getelementptr inbounds %struct.Pixel, ptr %1, i32 0, i32 0
  %16 = getelementptr inbounds %struct.Tuple, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = getelementptr inbounds %struct.Pixel, ptr %0, i32 0, i32 0
  %19 = getelementptr inbounds %struct.Tuple, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = sub i32 %17, %20
  store i32 %21, ptr %6, align 4, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %22 = load i32, ptr %6, align 4, !tbaa !6
  %23 = mul nsw i32 2, %22
  %24 = load i32, ptr %5, align 4, !tbaa !6
  %25 = sub nsw i32 %23, %24
  store i32 %25, ptr %7, align 4, !tbaa !6
  %26 = load i32, ptr %6, align 4, !tbaa !6
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %2
  store i32 -1, ptr %4, align 4, !tbaa !6
  %29 = load i32, ptr %6, align 4, !tbaa !6
  %30 = sub nsw i32 0, %29
  store i32 %30, ptr %6, align 4, !tbaa !6
  br label %31

31:                                               ; preds = %28, %2
  br label %32

32:                                               ; preds = %53, %31
  %33 = getelementptr inbounds %struct.Pixel, ptr %3, i32 0, i32 0
  %34 = getelementptr inbounds %struct.Tuple, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 4, !tbaa !10
  %36 = getelementptr inbounds %struct.Pixel, ptr %1, i32 0, i32 0
  %37 = getelementptr inbounds %struct.Tuple, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !10
  %39 = icmp ule i32 %35, %38
  br i1 %39, label %40, label %62

40:                                               ; preds = %32
  call void @LinearColorInterpolation(ptr noundef byval(%struct.Pixel) align 8 %0, ptr noundef %3, ptr noundef byval(%struct.Pixel) align 8 %1)
  call void @PutPixel(ptr noundef byval(%struct.Pixel) align 8 %3)
  %41 = load i32, ptr %7, align 4, !tbaa !6
  %42 = icmp sgt i32 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %40
  %44 = load i32, ptr %5, align 4, !tbaa !6
  %45 = mul nsw i32 2, %44
  %46 = load i32, ptr %7, align 4, !tbaa !6
  %47 = sub nsw i32 %46, %45
  store i32 %47, ptr %7, align 4, !tbaa !6
  %48 = load i32, ptr %4, align 4, !tbaa !6
  %49 = getelementptr inbounds %struct.Pixel, ptr %3, i32 0, i32 0
  %50 = getelementptr inbounds %struct.Tuple, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !14
  %52 = add i32 %51, %48
  store i32 %52, ptr %50, align 4, !tbaa !14
  br label %53

53:                                               ; preds = %43, %40
  %54 = load i32, ptr %6, align 4, !tbaa !6
  %55 = mul nsw i32 2, %54
  %56 = load i32, ptr %7, align 4, !tbaa !6
  %57 = add nsw i32 %56, %55
  store i32 %57, ptr %7, align 4, !tbaa !6
  %58 = getelementptr inbounds %struct.Pixel, ptr %3, i32 0, i32 0
  %59 = getelementptr inbounds %struct.Tuple, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !10
  %61 = add i32 %60, 1
  store i32 %61, ptr %59, align 4, !tbaa !10
  br label %32, !llvm.loop !15

62:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6, i64 12, i64 4, !6, i64 16, i64 4, !6, i64 20, i64 4, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"Pixel", !12, i64 0, !13, i64 8}
!12 = !{!"Tuple", !7, i64 0, !7, i64 4}
!13 = !{!"RGBA_Colors", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!14 = !{!11, !7, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.Pixel = type { %struct.Tuple, %struct.RGBA_Colors }
%struct.Tuple = type { i32, i32 }
%struct.RGBA_Colors = type { i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @PutPixel(ptr noundef byval(%struct.Pixel) align 8) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @LinearColorInterpolation(ptr noundef byval(%struct.Pixel) align 8, ptr noundef, ptr noundef byval(%struct.Pixel) align 8) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @DrawPixelLineX(ptr noundef byval(%struct.Pixel) align 8 %0, ptr noundef byval(%struct.Pixel) align 8 %1) local_unnamed_addr #0 {
  %3 = alloca %struct.Pixel, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %0, i64 24, i1 false), !tbaa.struct !5
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = sub i32 %5, %7
  %.inv = icmp sgt i32 %8, -1
  %spec.select = select i1 %.inv, i32 1, i32 -1
  %9 = load i32, ptr %3, align 8, !tbaa !14
  %10 = load i32, ptr %1, align 8, !tbaa !14
  %.not15 = icmp ugt i32 %9, %10
  br i1 %.not15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %spec.select14 = tail call i32 @llvm.abs.i32(i32 %8, i1 true)
  %11 = shl nsw i32 %8, 1
  %12 = load i32, ptr %0, align 8, !tbaa !14
  %13 = sub i32 %10, %12
  %14 = sub nsw i32 %11, %13
  %15 = shl nsw i32 %13, 1
  %16 = getelementptr inbounds i8, ptr %3, i64 4
  %17 = shl nuw nsw i32 %spec.select14, 1
  br label %18

18:                                               ; preds = %.lr.ph, %24
  %.016 = phi i32 [ %14, %.lr.ph ], [ %25, %24 ]
  call void @LinearColorInterpolation(ptr noundef nonnull byval(%struct.Pixel) align 8 %0, ptr noundef nonnull %3, ptr noundef nonnull byval(%struct.Pixel) align 8 %1)
  call void @PutPixel(ptr noundef nonnull byval(%struct.Pixel) align 8 %3)
  %19 = icmp sgt i32 %.016, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %18
  %21 = sub nsw i32 %.016, %15
  %22 = load i32, ptr %16, align 4, !tbaa !10
  %23 = add i32 %22, %spec.select
  store i32 %23, ptr %16, align 4, !tbaa !10
  br label %24

24:                                               ; preds = %20, %18
  %.1 = phi i32 [ %21, %20 ], [ %.016, %18 ]
  %25 = add nsw i32 %.1, %17
  %26 = load i32, ptr %3, align 8, !tbaa !14
  %27 = add i32 %26, 1
  store i32 %27, ptr %3, align 8, !tbaa !14
  %28 = load i32, ptr %1, align 8, !tbaa !14
  %.not = icmp ugt i32 %27, %28
  br i1 %.not, label %._crit_edge, label %18, !llvm.loop !15

._crit_edge:                                      ; preds = %24, %2
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6, i64 12, i64 4, !6, i64 16, i64 4, !6, i64 20, i64 4, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 4}
!11 = !{!"Pixel", !12, i64 0, !13, i64 8}
!12 = !{!"Tuple", !7, i64 0, !7, i64 4}
!13 = !{!"RGBA_Colors", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!14 = !{!11, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass