; 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.gdImageStruct = type { ptr, i32, i32, i32, [256 x i32], [256 x i32], [256 x i32], [256 x i32], i32, ptr, i32, ptr, ptr, [256 x i32], [256 x i32], i32, i32, ptr, i32, i32, i32, 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
define dso_local i32 @gdImageColorAllocate(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %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 %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 -1, ptr %11, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %30, %4
  %14 = load i32, ptr %10, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gdImageStruct, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %33

19:                                               ; preds = %13
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.gdImageStruct, ptr %20, i32 0, i32 7
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [256 x i32], ptr %21, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %19
  %28 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %28, ptr %11, align 4, !tbaa !9
  br label %33

29:                                               ; preds = %19
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %10, align 4, !tbaa !9
  br label %13, !llvm.loop !13

33:                                               ; preds = %27, %13
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %36, label %48

36:                                               ; preds = %33
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.gdImageStruct, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !11
  store i32 %39, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 256
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %73

43:                                               ; preds = %36
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.gdImageStruct, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 8, !tbaa !11
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %45, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %43, %33
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.gdImageStruct, ptr %50, i32 0, i32 4
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [256 x i32], ptr %51, i64 0, i64 %53
  store i32 %49, ptr %54, align 4, !tbaa !9
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.gdImageStruct, ptr %56, i32 0, i32 5
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [256 x i32], ptr %57, i64 0, i64 %59
  store i32 %55, ptr %60, align 4, !tbaa !9
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.gdImageStruct, ptr %62, i32 0, i32 6
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [256 x i32], ptr %63, i64 0, i64 %65
  store i32 %61, ptr %66, align 4, !tbaa !9
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.gdImageStruct, ptr %67, i32 0, i32 7
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [256 x i32], ptr %68, i64 0, i64 %70
  store i32 0, ptr %71, align 4, !tbaa !9
  %72 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %72, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %73

73:                                               ; preds = %48, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %74 = load i32, ptr %5, align 4
  ret i32 %74
}

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 16}
!12 = !{!"gdImageStruct", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !7, i64 1044, !7, i64 2068, !7, i64 3092, !10, i64 4116, !6, i64 4120, !10, i64 4128, !6, i64 4136, !6, i64 4144, !7, i64 4152, !7, i64 5176, !10, i64 6200, !10, i64 6204, !6, i64 6208, !10, i64 6216, !10, i64 6220, !10, i64 6224, !10, i64 6228, !10, i64 6232}
!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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local i32 @gdImageColorAllocate(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 3092
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %9

9:                                                ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %10 = getelementptr inbounds [256 x i32], ptr %8, i64 0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %.loopexit.loopexit

12:                                               ; preds = %9
  %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 %9, !llvm.loop !12

._crit_edge:                                      ; preds = %12
  %13 = icmp eq i32 %6, 256
  br i1 %13, label %25, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %4, %._crit_edge
  %14 = add nsw i32 %6, 1
  store i32 %14, ptr %5, align 8, !tbaa !5
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %9
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %._crit_edge.thread
  %.1 = phi i32 [ %6, %._crit_edge.thread ], [ %15, %.loopexit.loopexit ]
  %16 = getelementptr inbounds i8, ptr %0, i64 20
  %17 = sext i32 %.1 to i64
  %18 = getelementptr inbounds [256 x i32], ptr %16, i64 0, i64 %17
  store i32 %1, ptr %18, align 4, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %0, i64 1044
  %20 = getelementptr inbounds [256 x i32], ptr %19, i64 0, i64 %17
  store i32 %2, ptr %20, align 4, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %0, i64 2068
  %22 = getelementptr inbounds [256 x i32], ptr %21, i64 0, i64 %17
  store i32 %3, ptr %22, align 4, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %0, i64 3092
  %24 = getelementptr inbounds [256 x i32], ptr %23, i64 0, i64 %17
  store i32 0, ptr %24, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %._crit_edge, %.loopexit
  %.023 = phi i32 [ %.1, %.loopexit ], [ -1, %._crit_edge ]
  ret i32 %.023
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !10, i64 16}
!6 = !{!"gdImageStruct", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !8, i64 20, !8, i64 1044, !8, i64 2068, !8, i64 3092, !10, i64 4116, !7, i64 4120, !10, i64 4128, !7, i64 4136, !7, i64 4144, !8, i64 4152, !8, i64 5176, !10, i64 6200, !10, i64 6204, !7, i64 6208, !10, i64 6216, !10, i64 6220, !10, i64 6224, !10, i64 6228, !10, i64 6232}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass