; 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: nounwind uwtable
define dso_local ptr @gdImageCreate(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %7 = call noalias ptr @malloc(i64 noundef 6240) #5
  store ptr %7, ptr %6, align 8, !tbaa !9
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = mul i64 8, %9
  %11 = call noalias ptr @malloc(i64 noundef %10) #5
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.gdImageStruct, ptr %12, i32 0, i32 0
  store ptr %11, ptr %13, align 8, !tbaa !11
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.gdImageStruct, ptr %14, i32 0, i32 9
  store ptr null, ptr %15, align 8, !tbaa !13
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.gdImageStruct, ptr %16, i32 0, i32 10
  store i32 0, ptr %17, align 8, !tbaa !14
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.gdImageStruct, ptr %18, i32 0, i32 11
  store ptr null, ptr %19, align 8, !tbaa !15
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.gdImageStruct, ptr %20, i32 0, i32 12
  store ptr null, ptr %21, align 8, !tbaa !16
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.gdImageStruct, ptr %22, i32 0, i32 17
  store ptr null, ptr %23, align 8, !tbaa !17
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %38, %2
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %41

28:                                               ; preds = %24
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = call noalias ptr @calloc(i64 noundef %30, i64 noundef 1) #6
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.gdImageStruct, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  store ptr %31, ptr %37, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %28
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %5, align 4, !tbaa !5
  br label %24, !llvm.loop !18

41:                                               ; preds = %24
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.gdImageStruct, ptr %43, i32 0, i32 1
  store i32 %42, ptr %44, align 8, !tbaa !20
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.gdImageStruct, ptr %46, i32 0, i32 2
  store i32 %45, ptr %47, align 4, !tbaa !21
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.gdImageStruct, ptr %48, i32 0, i32 3
  store i32 0, ptr %49, align 8, !tbaa !22
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.gdImageStruct, ptr %50, i32 0, i32 8
  store i32 -1, ptr %51, align 4, !tbaa !23
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.gdImageStruct, ptr %52, i32 0, i32 18
  store i32 0, ptr %53, align 8, !tbaa !24
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.gdImageStruct, ptr %54, i32 0, i32 19
  store i32 0, ptr %55, align 4, !tbaa !25
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.gdImageStruct, ptr %57, i32 0, i32 21
  store i32 %56, ptr %58, align 4, !tbaa !26
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.gdImageStruct, ptr %59, i32 0, i32 20
  store i32 0, ptr %60, align 8, !tbaa !27
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.gdImageStruct, ptr %62, i32 0, i32 22
  store i32 %61, ptr %63, align 8, !tbaa !28
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret ptr %64
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #3

; 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 = { nounwind allocsize(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 allocsize(0,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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind allocsize(0,1) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"gdImageStruct", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !7, i64 20, !7, i64 1044, !7, i64 2068, !7, i64 3092, !6, i64 4116, !10, i64 4120, !6, i64 4128, !10, i64 4136, !10, i64 4144, !7, i64 4152, !7, i64 5176, !6, i64 6200, !6, i64 6204, !10, i64 6208, !6, i64 6216, !6, i64 6220, !6, i64 6224, !6, i64 6228, !6, i64 6232}
!13 = !{!12, !10, i64 4120}
!14 = !{!12, !6, i64 4128}
!15 = !{!12, !10, i64 4136}
!16 = !{!12, !10, i64 4144}
!17 = !{!12, !10, i64 6208}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !6, i64 8}
!21 = !{!12, !6, i64 12}
!22 = !{!12, !6, i64 16}
!23 = !{!12, !6, i64 4116}
!24 = !{!12, !6, i64 6216}
!25 = !{!12, !6, i64 6220}
!26 = !{!12, !6, i64 6228}
!27 = !{!12, !6, i64 6224}
!28 = !{!12, !6, i64 6232}


; 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 nounwind memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @gdImageCreate(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(6240) ptr @malloc(i64 noundef 6240) #4
  %4 = sext i32 %0 to i64
  %5 = shl nsw i64 %4, 3
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #4
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 4120
  store ptr null, ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %3, i64 4128
  store i32 0, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %3, i64 4136
  %10 = getelementptr inbounds i8, ptr %3, i64 6208
  store ptr null, ptr %10, align 8, !tbaa !13
  %11 = icmp sgt i32 %0, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %9, i8 0, i64 16, i1 false)
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %12 = sext i32 %1 to i64
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %14 = tail call noalias ptr @calloc(i64 noundef %12, i64 noundef 1) #5
  %15 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  store ptr %14, ptr %15, align 8, !tbaa !14
  %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 %13, !llvm.loop !15

._crit_edge:                                      ; preds = %13, %2
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %0, ptr %16, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 %1, ptr %17, align 4, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 0, ptr %18, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %3, i64 4116
  store i32 -1, ptr %19, align 4, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %3, i64 6216
  store i32 0, ptr %20, align 8, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %3, i64 6220
  store i32 0, ptr %21, align 4, !tbaa !22
  %22 = getelementptr inbounds i8, ptr %3, i64 6228
  store i32 %0, ptr %22, align 4, !tbaa !23
  %23 = getelementptr inbounds i8, ptr %3, i64 6224
  store i32 0, ptr %23, align 8, !tbaa !24
  %24 = getelementptr inbounds i8, ptr %3, i64 6232
  store i32 %1, ptr %24, align 8, !tbaa !25
  ret ptr %3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { nofree nounwind memory(write, argmem: none, inaccessiblemem: 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" }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { nounwind allocsize(0,1) }

!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 = !{!"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, !7, i64 4120}
!12 = !{!6, !10, i64 4128}
!13 = !{!6, !7, i64 6208}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !10, i64 8}
!18 = !{!6, !10, i64 12}
!19 = !{!6, !10, i64 16}
!20 = !{!6, !10, i64 4116}
!21 = !{!6, !10, i64 6216}
!22 = !{!6, !10, i64 6220}
!23 = !{!6, !10, i64 6228}
!24 = !{!6, !10, i64 6224}
!25 = !{!6, !10, i64 6232}


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