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

declare i32 @putc(i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @gdImageGd(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.gdImageStruct, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gdPutWord(i32 noundef %11, ptr noundef %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gdImageStruct, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gdPutWord(i32 noundef %15, ptr noundef %16)
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gdImageStruct, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = trunc i32 %19 to i8
  %21 = zext i8 %20 to i32
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 @putc(i32 noundef %21, ptr noundef %22)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.gdImageStruct, ptr %24, i32 0, i32 8
  %26 = load i32, ptr %25, align 4, !tbaa !14
  store i32 %26, ptr %8, align 4, !tbaa !15
  %27 = load i32, ptr %8, align 4, !tbaa !15
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %30

29:                                               ; preds = %2
  store i32 257, ptr %8, align 4, !tbaa !15
  br label %30

30:                                               ; preds = %29, %2
  %31 = load i32, ptr %8, align 4, !tbaa !15
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gdPutWord(i32 noundef %31, ptr noundef %32)
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %33

33:                                               ; preds = %67, %30
  %34 = load i32, ptr %7, align 4, !tbaa !15
  %35 = icmp slt i32 %34, 256
  br i1 %35, label %36, label %70

36:                                               ; preds = %33
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.gdImageStruct, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %7, align 4, !tbaa !15
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [256 x i32], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !15
  %43 = trunc i32 %42 to i8
  %44 = zext i8 %43 to i32
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = call i32 @putc(i32 noundef %44, ptr noundef %45)
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.gdImageStruct, ptr %47, i32 0, i32 5
  %49 = load i32, ptr %7, align 4, !tbaa !15
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [256 x i32], ptr %48, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !15
  %53 = trunc i32 %52 to i8
  %54 = zext i8 %53 to i32
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = call i32 @putc(i32 noundef %54, ptr noundef %55)
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.gdImageStruct, ptr %57, i32 0, i32 6
  %59 = load i32, ptr %7, align 4, !tbaa !15
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [256 x i32], ptr %58, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !15
  %63 = trunc i32 %62 to i8
  %64 = zext i8 %63 to i32
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = call i32 @putc(i32 noundef %64, ptr noundef %65)
  br label %67

67:                                               ; preds = %36
  %68 = load i32, ptr %7, align 4, !tbaa !15
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %7, align 4, !tbaa !15
  br label %33, !llvm.loop !16

70:                                               ; preds = %33
  store i32 0, ptr %6, align 4, !tbaa !15
  br label %71

71:                                               ; preds = %103, %70
  %72 = load i32, ptr %6, align 4, !tbaa !15
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.gdImageStruct, ptr %73, i32 0, i32 2
  %75 = load i32, ptr %74, align 4, !tbaa !12
  %76 = icmp slt i32 %72, %75
  br i1 %76, label %77, label %106

77:                                               ; preds = %71
  store i32 0, ptr %5, align 4, !tbaa !15
  br label %78

78:                                               ; preds = %99, %77
  %79 = load i32, ptr %5, align 4, !tbaa !15
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.gdImageStruct, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 8, !tbaa !9
  %83 = icmp slt i32 %79, %82
  br i1 %83, label %84, label %102

84:                                               ; preds = %78
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.gdImageStruct, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !18
  %88 = load i32, ptr %5, align 4, !tbaa !15
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds ptr, ptr %87, i64 %89
  %91 = load ptr, ptr %90, align 8, !tbaa !5
  %92 = load i32, ptr %6, align 4, !tbaa !15
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i8, ptr %91, i64 %93
  %95 = load i8, ptr %94, align 1, !tbaa !19
  %96 = zext i8 %95 to i32
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = call i32 @putc(i32 noundef %96, ptr noundef %97)
  br label %99

99:                                               ; preds = %84
  %100 = load i32, ptr %5, align 4, !tbaa !15
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %5, align 4, !tbaa !15
  br label %78, !llvm.loop !20

102:                                              ; preds = %78
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %6, align 4, !tbaa !15
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %6, align 4, !tbaa !15
  br label %71, !llvm.loop !21

106:                                              ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  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
  ret void
}

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 = { "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, !11, i64 8}
!10 = !{!"gdImageStruct", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 20, !7, i64 1044, !7, i64 2068, !7, i64 3092, !11, i64 4116, !6, i64 4120, !11, i64 4128, !6, i64 4136, !6, i64 4144, !7, i64 4152, !7, i64 5176, !11, i64 6200, !11, i64 6204, !6, i64 6208, !11, i64 6216, !11, i64 6220, !11, i64 6224, !11, i64 6228, !11, i64 6232}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 4116}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !6, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !17}
!21 = distinct !{!21, !17}


; 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: nounwind uwtable
declare dso_local void @gdPutWord(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @putc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @gdImageGd(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  tail call void @gdPutWord(i32 noundef %4, ptr noundef %1)
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !11
  tail call void @gdPutWord(i32 noundef %6, ptr noundef %1)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = and i32 %8, 255
  %10 = tail call i32 @putc(i32 noundef %9, ptr noundef %1)
  %11 = getelementptr inbounds i8, ptr %0, i64 4116
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = icmp eq i32 %12, -1
  %spec.store.select = select i1 %13, i32 257, i32 %12
  tail call void @gdPutWord(i32 noundef %spec.store.select, ptr noundef %1)
  %14 = getelementptr inbounds i8, ptr %0, i64 20
  %15 = getelementptr inbounds i8, ptr %0, i64 1044
  %16 = getelementptr inbounds i8, ptr %0, i64 2068
  br label %21

.preheader32:                                     ; preds = %21
  %17 = load i32, ptr %5, align 4, !tbaa !11
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.preheader.lr.ph, label %._crit_edge36

.preheader.lr.ph:                                 ; preds = %.preheader32
  %19 = load i32, ptr %3, align 8, !tbaa !5
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.preheader, label %._crit_edge36

21:                                               ; preds = %2, %21
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next, %21 ]
  %22 = getelementptr inbounds [256 x i32], ptr %14, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = and i32 %23, 255
  %25 = tail call i32 @putc(i32 noundef %24, ptr noundef %1)
  %26 = getelementptr inbounds [256 x i32], ptr %15, i64 0, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = and i32 %27, 255
  %29 = tail call i32 @putc(i32 noundef %28, ptr noundef %1)
  %30 = getelementptr inbounds [256 x i32], ptr %16, i64 0, i64 %indvars.iv
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = and i32 %31, 255
  %33 = tail call i32 @putc(i32 noundef %32, ptr noundef %1)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %.preheader32, label %21, !llvm.loop !15

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %34 = phi i32 [ %47, %._crit_edge ], [ %17, %.preheader.lr.ph ]
  %35 = phi i32 [ %48, %._crit_edge ], [ %19, %.preheader.lr.ph ]
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.lr.ph ], [ 0, %.preheader ]
  %37 = load ptr, ptr %0, align 8, !tbaa !17
  %38 = getelementptr inbounds ptr, ptr %37, i64 %indvars.iv39
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = getelementptr inbounds i8, ptr %39, i64 %indvars.iv42
  %41 = load i8, ptr %40, align 1, !tbaa !19
  %42 = zext i8 %41 to i32
  %43 = tail call i32 @putc(i32 noundef %42, ptr noundef %1)
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %44 = load i32, ptr %3, align 8, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next40, %45
  br i1 %46, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !20

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %5, align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %47 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %34, %.preheader ]
  %48 = phi i32 [ %44, %._crit_edge.loopexit ], [ %35, %.preheader ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %49 = sext i32 %47 to i64
  %50 = icmp slt i64 %indvars.iv.next43, %49
  br i1 %50, label %.preheader, label %._crit_edge36, !llvm.loop !21

._crit_edge36:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %.preheader32
  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" }
attributes #1 = { nofree nounwind "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 8}
!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 = !{!6, !10, i64 12}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 4116}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !7, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!8, !8, i64 0}
!20 = distinct !{!20, !16}
!21 = distinct !{!21, !16, !22}
!22 = !{!"llvm.loop.unswitch.partial.disable"}


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