; LLVM IR from NOAA-PMEL/Ferret :: xgks/src/lib (gd)

; 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.gdPoint = type { i32, i32 }

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

; 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
declare dso_local void @gdImageLine(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @gdImagePolygon(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %4
  store i32 1, ptr %12, align 4
  br label %68

16:                                               ; preds = %4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gdPoint, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !11
  store i32 %19, ptr %10, align 4, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.gdPoint, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !13
  store i32 %22, ptr %11, align 4, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.gdPoint, ptr %26, i64 %29
  %31 = getelementptr inbounds %struct.gdPoint, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.gdPoint, ptr %33, i64 %36
  %38 = getelementptr inbounds %struct.gdPoint, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = load i32, ptr %8, align 4, !tbaa !9
  call void @gdImageLine(ptr noundef %23, i32 noundef %24, i32 noundef %25, i32 noundef %32, i32 noundef %39, i32 noundef %40)
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %64, %16
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %67

45:                                               ; preds = %41
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.gdPoint, ptr %46, i32 1
  store ptr %47, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.gdPoint, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.gdPoint, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !13
  %57 = load i32, ptr %8, align 4, !tbaa !9
  call void @gdImageLine(ptr noundef %48, i32 noundef %49, i32 noundef %50, i32 noundef %53, i32 noundef %56, i32 noundef %57)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.gdPoint, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !11
  store i32 %60, ptr %10, align 4, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.gdPoint, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !13
  store i32 %63, ptr %11, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %45
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !9
  br label %41, !llvm.loop !14

67:                                               ; preds = %41
  store i32 0, ptr %12, align 4
  br label %68

68:                                               ; preds = %67, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %69 = load i32, ptr %12, align 4
  switch i32 %69, label %71 [
    i32 0, label %70
    i32 1, label %70
  ]

70:                                               ; preds = %68, %68
  ret void

71:                                               ; preds = %68
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"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.gdPoint = type { i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @gdImageLine(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @gdImagePolygon(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %.loopexit, label %5

5:                                                ; preds = %4
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !10
  %9 = sext i32 %2 to i64
  %10 = getelementptr %struct.gdPoint, ptr %1, i64 %9
  %11 = getelementptr i8, ptr %10, i64 -8
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = getelementptr i8, ptr %10, i64 -4
  %14 = load i32, ptr %13, align 4, !tbaa !10
  tail call void @gdImageLine(ptr noundef %0, i32 noundef %6, i32 noundef %8, i32 noundef %12, i32 noundef %14, i32 noundef %3)
  %15 = icmp sgt i32 %2, 1
  br i1 %15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.029 = phi i32 [ %21, %.lr.ph ], [ %8, %5 ]
  %.02228 = phi i32 [ %20, %.lr.ph ], [ %6, %5 ]
  %.02327 = phi i32 [ %22, %.lr.ph ], [ 1, %5 ]
  %.02426 = phi ptr [ %16, %.lr.ph ], [ %1, %5 ]
  %16 = getelementptr inbounds i8, ptr %.02426, i64 8
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.02426, i64 12
  %19 = load i32, ptr %18, align 4, !tbaa !10
  tail call void @gdImageLine(ptr noundef %0, i32 noundef %.02228, i32 noundef %.029, i32 noundef %17, i32 noundef %19, i32 noundef %3)
  %20 = load i32, ptr %16, align 4, !tbaa !5
  %21 = load i32, ptr %18, align 4, !tbaa !10
  %22 = add nuw nsw i32 %.02327, 1
  %exitcond.not = icmp eq i32 %22, %2
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %5, %4
  ret void
}

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

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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