; LLVM IR from jingweizhanghuai/Morn :: src/image/morn_image_geometry.ll (PolygonSetup)

; 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.MImagePoint = type { float, float }
%struct.MList = type { i32, ptr }

@.str = external hidden unnamed_addr constant [87 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__._PolygonSetup = external hidden unnamed_addr constant [14 x i8], align 1

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @_PolygonSetup(ptr noundef %0, i32 noundef %1, float noundef %2, float noundef %3, float noundef %4, float noundef %5, float noundef %6, float noundef %7, float noundef %8, float noundef %9, float noundef %10, float noundef %11, float noundef %12, float noundef %13, float noundef %14, float noundef %15, float noundef %16, float noundef %17) #2 {
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca float, align 4
  %22 = alloca float, align 4
  %23 = alloca float, align 4
  %24 = alloca float, align 4
  %25 = alloca float, align 4
  %26 = alloca float, align 4
  %27 = alloca float, align 4
  %28 = alloca float, align 4
  %29 = alloca float, align 4
  %30 = alloca float, align 4
  %31 = alloca float, align 4
  %32 = alloca float, align 4
  %33 = alloca float, align 4
  %34 = alloca float, align 4
  %35 = alloca float, align 4
  %36 = alloca float, align 4
  %37 = alloca i32, align 4
  %38 = alloca i32, align 4
  %39 = alloca [8 x float], align 16
  %40 = alloca [8 x float], align 16
  %41 = alloca i32, align 4
  %42 = alloca %struct.MImagePoint, align 4
  store ptr %0, ptr %19, align 8, !tbaa !5
  store i32 %1, ptr %20, align 4, !tbaa !9
  store float %2, ptr %21, align 4, !tbaa !11
  store float %3, ptr %22, align 4, !tbaa !11
  store float %4, ptr %23, align 4, !tbaa !11
  store float %5, ptr %24, align 4, !tbaa !11
  store float %6, ptr %25, align 4, !tbaa !11
  store float %7, ptr %26, align 4, !tbaa !11
  store float %8, ptr %27, align 4, !tbaa !11
  store float %9, ptr %28, align 4, !tbaa !11
  store float %10, ptr %29, align 4, !tbaa !11
  store float %11, ptr %30, align 4, !tbaa !11
  store float %12, ptr %31, align 4, !tbaa !11
  store float %13, ptr %32, align 4, !tbaa !11
  store float %14, ptr %33, align 4, !tbaa !11
  store float %15, ptr %34, align 4, !tbaa !11
  store float %16, ptr %35, align 4, !tbaa !11
  store float %17, ptr %36, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %37) #3
  %44 = load ptr, ptr %19, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %50, label %46

46:                                               ; preds = %43
  %47 = load ptr, ptr %19, align 8, !tbaa !5
  %48 = ptrtoint ptr %47 to i64
  %49 = icmp eq i64 %48, -1
  br label %50

50:                                               ; preds = %46, %43
  %51 = phi i1 [ true, %43 ], [ %49, %46 ]
  %52 = zext i1 %51 to i32
  store i32 %52, ptr %37, align 4, !tbaa !9
  %53 = load i32, ptr %37, align 4, !tbaa !9
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %50
  %56 = load i32, ptr %37, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %56, i32 noundef -1, ptr noundef @.str, i32 noundef 305, ptr noundef @__FUNCTION__._PolygonSetup, ptr noundef @.str.2)
  br label %57

57:                                               ; preds = %55, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %37) #3
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %38) #3
  %60 = load i32, ptr %20, align 4, !tbaa !9
  %61 = icmp sle i32 %60, 0
  br i1 %61, label %65, label %62

62:                                               ; preds = %59
  %63 = load i32, ptr %20, align 4, !tbaa !9
  %64 = icmp sgt i32 %63, 8
  br label %65

65:                                               ; preds = %62, %59
  %66 = phi i1 [ true, %59 ], [ %64, %62 ]
  %67 = zext i1 %66 to i32
  store i32 %67, ptr %38, align 4, !tbaa !9
  %68 = load i32, ptr %38, align 4, !tbaa !9
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %72

70:                                               ; preds = %65
  %71 = load i32, ptr %38, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %71, i32 noundef -1, ptr noundef @.str, i32 noundef 306, ptr noundef @__FUNCTION__._PolygonSetup, ptr noundef @.str.2)
  br label %72

72:                                               ; preds = %70, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %38) #3
  br label %73

73:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 32, ptr %39) #3
  %74 = load float, ptr %21, align 4, !tbaa !11
  store float %74, ptr %39, align 4, !tbaa !11
  %75 = getelementptr inbounds float, ptr %39, i64 1
  %76 = load float, ptr %23, align 4, !tbaa !11
  store float %76, ptr %75, align 4, !tbaa !11
  %77 = getelementptr inbounds float, ptr %39, i64 2
  %78 = load float, ptr %25, align 4, !tbaa !11
  store float %78, ptr %77, align 4, !tbaa !11
  %79 = getelementptr inbounds float, ptr %39, i64 3
  %80 = load float, ptr %27, align 4, !tbaa !11
  store float %80, ptr %79, align 4, !tbaa !11
  %81 = getelementptr inbounds float, ptr %39, i64 4
  %82 = load float, ptr %29, align 4, !tbaa !11
  store float %82, ptr %81, align 4, !tbaa !11
  %83 = getelementptr inbounds float, ptr %39, i64 5
  %84 = load float, ptr %31, align 4, !tbaa !11
  store float %84, ptr %83, align 4, !tbaa !11
  %85 = getelementptr inbounds float, ptr %39, i64 6
  %86 = load float, ptr %33, align 4, !tbaa !11
  store float %86, ptr %85, align 4, !tbaa !11
  %87 = getelementptr inbounds float, ptr %39, i64 7
  %88 = load float, ptr %35, align 4, !tbaa !11
  store float %88, ptr %87, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 32, ptr %40) #3
  %89 = load float, ptr %22, align 4, !tbaa !11
  store float %89, ptr %40, align 4, !tbaa !11
  %90 = getelementptr inbounds float, ptr %40, i64 1
  %91 = load float, ptr %24, align 4, !tbaa !11
  store float %91, ptr %90, align 4, !tbaa !11
  %92 = getelementptr inbounds float, ptr %40, i64 2
  %93 = load float, ptr %26, align 4, !tbaa !11
  store float %93, ptr %92, align 4, !tbaa !11
  %94 = getelementptr inbounds float, ptr %40, i64 3
  %95 = load float, ptr %28, align 4, !tbaa !11
  store float %95, ptr %94, align 4, !tbaa !11
  %96 = getelementptr inbounds float, ptr %40, i64 4
  %97 = load float, ptr %30, align 4, !tbaa !11
  store float %97, ptr %96, align 4, !tbaa !11
  %98 = getelementptr inbounds float, ptr %40, i64 5
  %99 = load float, ptr %32, align 4, !tbaa !11
  store float %99, ptr %98, align 4, !tbaa !11
  %100 = getelementptr inbounds float, ptr %40, i64 6
  %101 = load float, ptr %34, align 4, !tbaa !11
  store float %101, ptr %100, align 4, !tbaa !11
  %102 = getelementptr inbounds float, ptr %40, i64 7
  %103 = load float, ptr %36, align 4, !tbaa !11
  store float %103, ptr %102, align 4, !tbaa !11
  %104 = load ptr, ptr %19, align 8, !tbaa !5
  call void @mListClear(ptr noundef %104)
  call void @llvm.lifetime.start.p0(i64 4, ptr %41) #3
  store i32 0, ptr %41, align 4, !tbaa !9
  br label %105

105:                                              ; preds = %123, %73
  %106 = load i32, ptr %41, align 4, !tbaa !9
  %107 = load i32, ptr %20, align 4, !tbaa !9
  %108 = icmp slt i32 %106, %107
  br i1 %108, label %110, label %109

109:                                              ; preds = %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %41) #3
  br label %126

110:                                              ; preds = %105
  call void @llvm.lifetime.start.p0(i64 8, ptr %42) #3
  %111 = load i32, ptr %41, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [8 x float], ptr %39, i64 0, i64 %112
  %114 = load float, ptr %113, align 4, !tbaa !11
  %115 = getelementptr inbounds %struct.MImagePoint, ptr %42, i32 0, i32 0
  store float %114, ptr %115, align 4, !tbaa !13
  %116 = load i32, ptr %41, align 4, !tbaa !9
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [8 x float], ptr %40, i64 0, i64 %117
  %119 = load float, ptr %118, align 4, !tbaa !11
  %120 = getelementptr inbounds %struct.MImagePoint, ptr %42, i32 0, i32 1
  store float %119, ptr %120, align 4, !tbaa !15
  %121 = load ptr, ptr %19, align 8, !tbaa !5
  %122 = call ptr @mListWrite(ptr noundef %121, i32 noundef -1, ptr noundef %42, i32 noundef 8)
  call void @llvm.lifetime.end.p0(i64 8, ptr %42) #3
  br label %123

123:                                              ; preds = %110
  %124 = load i32, ptr %41, align 4, !tbaa !9
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %41, align 4, !tbaa !9
  br label %105, !llvm.loop !16

126:                                              ; preds = %109
  %127 = load ptr, ptr %19, align 8, !tbaa !5
  %128 = load ptr, ptr %19, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.MList, ptr %128, i32 0, i32 1
  %130 = load ptr, ptr %129, align 8, !tbaa !18
  %131 = getelementptr inbounds ptr, ptr %130, i64 0
  %132 = load ptr, ptr %131, align 8, !tbaa !5
  %133 = call ptr @mListWrite(ptr noundef %127, i32 noundef -1, ptr noundef %132, i32 noundef 8)
  %134 = load ptr, ptr %19, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.MList, ptr %134, i32 0, i32 0
  %136 = load i32, ptr %135, align 8, !tbaa !20
  %137 = sub nsw i32 %136, 1
  %138 = load ptr, ptr %19, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.MList, ptr %138, i32 0, i32 0
  store i32 %137, ptr %139, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 32, ptr %40) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %39) #3
  ret void
}

declare void @mListClear(ptr noundef) #1

declare ptr @mListWrite(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"MImagePoint", !12, i64 0, !12, i64 4}
!15 = !{!14, !12, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 8}
!19 = !{!"MList", !10, i64 0, !6, i64 8}
!20 = !{!19, !10, i64 0}


; 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.MImagePoint = type { float, float }

@.str = external hidden unnamed_addr constant [87 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__._PolygonSetup = external hidden unnamed_addr constant [14 x i8], align 1

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @_PolygonSetup(ptr noundef %0, i32 noundef %1, float noundef %2, float noundef %3, float noundef %4, float noundef %5, float noundef %6, float noundef %7, float noundef %8, float noundef %9, float noundef %10, float noundef %11, float noundef %12, float noundef %13, float noundef %14, float noundef %15, float noundef %16, float noundef %17) local_unnamed_addr #2 {
  %19 = alloca [8 x float], align 16
  %20 = alloca [8 x float], align 16
  %21 = alloca %struct.MImagePoint, align 4
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %27 [
    i64 -1, label %22
    i64 0, label %22
  ]

22:                                               ; preds = %18, %18
  %23 = icmp eq ptr %0, null
  %24 = icmp eq ptr %0, inttoptr (i64 -1 to ptr)
  %25 = or i1 %23, %24
  %26 = zext i1 %25 to i32
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %26, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 305, ptr noundef nonnull @__FUNCTION__._PolygonSetup, ptr noundef nonnull @.str.2) #3
  br label %27

27:                                               ; preds = %18, %22
  %28 = add i32 %1, -9
  %29 = icmp ult i32 %28, -8
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 306, ptr noundef nonnull @__FUNCTION__._PolygonSetup, ptr noundef nonnull @.str.2) #3
  br label %31

31:                                               ; preds = %30, %27
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %19) #3
  store float %2, ptr %19, align 16, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %19, i64 4
  store float %4, ptr %32, align 4, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %19, i64 8
  store float %6, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %19, i64 12
  store float %8, ptr %34, align 4, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %19, i64 16
  store float %10, ptr %35, align 16, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %19, i64 20
  store float %12, ptr %36, align 4, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %19, i64 24
  store float %14, ptr %37, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %19, i64 28
  store float %16, ptr %38, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %20) #3
  store float %3, ptr %20, align 16, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %20, i64 4
  store float %5, ptr %39, align 4, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %20, i64 8
  store float %7, ptr %40, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %20, i64 12
  store float %9, ptr %41, align 4, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %20, i64 16
  store float %11, ptr %42, align 16, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %20, i64 20
  store float %13, ptr %43, align 4, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %20, i64 24
  store float %15, ptr %44, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %20, i64 28
  store float %17, ptr %45, align 4, !tbaa !5
  tail call void @mListClear(ptr noundef %0) #3
  %46 = icmp sgt i32 %1, 0
  br i1 %46, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %31
  %47 = getelementptr inbounds i8, ptr %21, i64 4
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %54

._crit_edge:                                      ; preds = %54, %31
  %48 = getelementptr inbounds i8, ptr %0, i64 8
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = call ptr @mListWrite(ptr noundef %0, i32 noundef -1, ptr noundef %50, i32 noundef 8) #3
  %52 = load i32, ptr %0, align 8, !tbaa !14
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %0, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %20) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %19) #3
  ret void

54:                                               ; preds = %.lr.ph, %54
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %54 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %21) #3
  %55 = getelementptr inbounds [8 x float], ptr %19, i64 0, i64 %indvars.iv
  %56 = load float, ptr %55, align 4, !tbaa !5
  store float %56, ptr %21, align 4, !tbaa !15
  %57 = getelementptr inbounds [8 x float], ptr %20, i64 0, i64 %indvars.iv
  %58 = load float, ptr %57, align 4, !tbaa !5
  store float %58, ptr %47, align 4, !tbaa !17
  %59 = call ptr @mListWrite(ptr noundef %0, i32 noundef -1, ptr noundef nonnull %21, i32 noundef 8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %21) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %54, !llvm.loop !18
}

declare void @mListClear(ptr noundef) local_unnamed_addr #1

declare ptr @mListWrite(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"MList", !11, i64 0, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"MImagePoint", !6, i64 0, !6, i64 4}
!17 = !{!16, !6, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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