; LLVM IR from NOAA-PMEL/Ferret :: fer/ccr (wgif)

; 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._XImage = type { i32, i32, i32, i32, ptr, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, ptr, %struct.funcs }
%struct.funcs = type { ptr, ptr, ptr, ptr, ptr, ptr }

@data = external hidden global ptr, align 8
@iwidth = external hidden global i32, align 4
@iheight = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @wGIF(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._XImage, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr @data, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._XImage, ptr %15, i32 0, i32 10
  %17 = load i32, ptr %16, align 4, !tbaa !14
  store i32 %17, ptr @iwidth, align 4, !tbaa !15
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._XImage, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !16
  store i32 %20, ptr @iheight, align 4, !tbaa !15
  store i32 0, ptr %11, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %59, %5
  %22 = load i32, ptr %11, align 4, !tbaa !15
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._XImage, ptr %23, i32 0, i32 11
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = shl i32 1, %25
  %27 = icmp slt i32 %22, %26
  br i1 %27, label %28, label %62

28:                                               ; preds = %21
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !15
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = ashr i32 %33, 8
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !15
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  store i32 %34, ptr %38, align 4, !tbaa !15
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !15
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %39, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = ashr i32 %43, 8
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !15
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  store i32 %44, ptr %48, align 4, !tbaa !15
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !15
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !15
  %54 = ashr i32 %53, 8
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !15
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i32, ptr %55, i64 %57
  store i32 %54, ptr %58, align 4, !tbaa !15
  br label %59

59:                                               ; preds = %28
  %60 = load i32, ptr %11, align 4, !tbaa !15
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %11, align 4, !tbaa !15
  br label %21, !llvm.loop !18

62:                                               ; preds = %21
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._XImage, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !20
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._XImage, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !16
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._XImage, ptr %70, i32 0, i32 9
  %72 = load i32, ptr %71, align 8, !tbaa !21
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._XImage, ptr %73, i32 0, i32 11
  %75 = load i32, ptr %74, align 8, !tbaa !17
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  call void @GIFEncode(ptr noundef %63, i32 noundef %66, i32 noundef %69, i32 noundef 0, i32 noundef %72, i32 noundef %75, ptr noundef %76, ptr noundef %77, ptr noundef %78, ptr noundef @GetPixel)
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = call i32 @fclose(ptr noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @GIFEncode(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @GetPixel(i32 noundef, i32 noundef) #0

declare i32 @fclose(ptr noundef) #2

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

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 = { "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, !6, i64 16}
!10 = !{!"_XImage", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !6, i64 80, !13, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"funcs", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!14 = !{!10, !11, i64 44}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 4}
!17 = !{!10, !11, i64 48}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !11, i64 0}
!21 = !{!10, !11, i64 40}


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

@data = external hidden local_unnamed_addr global ptr, align 8
@iwidth = external hidden local_unnamed_addr global i32, align 4
@iheight = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @wGIF(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %7, ptr @data, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %1, i64 44
  %9 = load i32, ptr %8, align 4, !tbaa !14
  store i32 %9, ptr @iwidth, align 4, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !16
  store i32 %11, ptr @iheight, align 4, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %1, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !17
  %.not = icmp eq i32 %13, 31
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %14 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = ashr i32 %15, 8
  store i32 %16, ptr %14, align 4, !tbaa !15
  %17 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = ashr i32 %18, 8
  store i32 %19, ptr %17, align 4, !tbaa !15
  %20 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !15
  %22 = ashr i32 %21, 8
  store i32 %22, ptr %20, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %12, align 8, !tbaa !17
  %24 = shl nuw i32 1, %23
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next, %25
  br i1 %26, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !18

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %5
  %27 = phi i32 [ %11, %5 ], [ %.pre, %._crit_edge.loopexit ]
  %.lcssa = phi i32 [ 31, %5 ], [ %23, %._crit_edge.loopexit ]
  %28 = load i32, ptr %1, align 8, !tbaa !20
  %29 = getelementptr inbounds i8, ptr %1, i64 40
  %30 = load i32, ptr %29, align 8, !tbaa !21
  tail call void @GIFEncode(ptr noundef %0, i32 noundef %28, i32 noundef %27, i32 noundef 0, i32 noundef %30, i32 noundef %.lcssa, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef nonnull @GetPixel)
  %31 = tail call i32 @fclose(ptr noundef %0)
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @GetPixel(i32 noundef, i32 noundef) #0

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

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 16}
!6 = !{!"_XImage", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !10, i64 80, !12, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"funcs", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !7, i64 44}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !7, i64 4}
!17 = !{!6, !7, i64 48}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !7, i64 0}
!21 = !{!6, !7, i64 40}


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