; LLVM IR from dloebl/cgif :: tests (max_color_table_test)

; 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.st_gifconfig = type { ptr, ptr, i32, i32, i16, i16, i16, i16, ptr, ptr }
%struct.st_frameconfig = type { ptr, ptr, i32, i32, i16, i16, i8 }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %struct.st_gifconfig, align 8
  %4 = alloca %struct.st_frameconfig, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 48, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #6
  store i16 256, ptr %8, align 2, !tbaa !5
  %10 = call noalias ptr @malloc(i64 noundef 768) #7
  store ptr %10, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %11, i8 0, i64 768, i1 false)
  %12 = call noalias ptr @malloc(i64 noundef 10000) #7
  store ptr %12, ptr %5, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %13, i8 0, i64 10000, i1 false)
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 48, i1 false)
  %14 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 4
  store i16 100, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 5
  store i16 100, ptr %15, align 2, !tbaa !14
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 0
  store ptr %16, ptr %17, align 8, !tbaa !15
  %18 = load i16, ptr %8, align 2, !tbaa !5
  %19 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 6
  store i16 %18, ptr %19, align 4, !tbaa !16
  %20 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 1
  store ptr @.str, ptr %20, align 8, !tbaa !17
  %21 = call ptr @cgif_newgif(ptr noundef %3)
  store ptr %21, ptr %2, align 8, !tbaa !9
  %22 = load ptr, ptr %2, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %0
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = call i32 @fputs(ptr noundef @.str.1, ptr noundef %25)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %43

27:                                               ; preds = %0
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 32, i1 false)
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.st_frameconfig, ptr %4, i32 0, i32 1
  store ptr %28, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %2, align 8, !tbaa !9
  %31 = call i32 @cgif_addframe(ptr noundef %30, ptr noundef %4)
  store i32 %31, ptr %7, align 4, !tbaa !20
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %32) #6
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %33) #6
  %34 = load ptr, ptr %2, align 8, !tbaa !9
  %35 = call i32 @cgif_close(ptr noundef %34)
  store i32 %35, ptr %7, align 4, !tbaa !20
  %36 = load i32, ptr %7, align 4, !tbaa !20
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %27
  %39 = load ptr, ptr @stderr, align 8, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !20
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.2, i32 noundef %40) #6
  store i32 2, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %43

42:                                               ; preds = %27
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %43

43:                                               ; preds = %42, %38, %24
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  %44 = load i32, ptr %1, align 4
  ret i32 %44
}

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare ptr @cgif_newgif(ptr noundef) #4

declare i32 @fputs(ptr noundef, ptr noundef) #4

declare i32 @cgif_addframe(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

declare i32 @cgif_close(ptr noundef) #4

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #5

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 #5 = { 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" }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"short", !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, !6, i64 24}
!12 = !{!"st_gifconfig", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 26, !6, i64 28, !6, i64 30, !10, i64 32, !10, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 26}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !6, i64 28}
!17 = !{!12, !10, i64 8}
!18 = !{!19, !10, i64 8}
!19 = !{!"st_frameconfig", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 26, !7, i64 28}
!20 = !{!13, !13, i64 0}


; 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.st_gifconfig = type { ptr, ptr, i32, i32, i16, i16, i16, i16, ptr, ptr }
%struct.st_frameconfig = type { ptr, ptr, i32, i32, i16, i16, i8 }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.st_gifconfig, align 8
  %2 = alloca %struct.st_frameconfig, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #7
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #7
  %calloc = tail call dereferenceable_or_null(768) ptr @calloc(i64 1, i64 768)
  %calloc14 = tail call dereferenceable_or_null(10000) ptr @calloc(i64 1, i64 10000)
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %3, i8 0, i64 32, i1 false)
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  store i16 100, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 26
  store i16 100, ptr %5, align 2, !tbaa !12
  store ptr %calloc, ptr %1, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %1, i64 28
  store i16 256, ptr %6, align 4, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr @.str, ptr %7, align 8, !tbaa !15
  %8 = call ptr @cgif_newgif(ptr noundef nonnull %1) #7
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %0
  %11 = load ptr, ptr @stderr, align 8, !tbaa !16
  %12 = call i32 @fputs(ptr noundef nonnull @.str.1, ptr noundef %11) #8
  br label %20

13:                                               ; preds = %0
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %2, i8 0, i64 32, i1 false)
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %calloc14, ptr %14, align 8, !tbaa !17
  %15 = call i32 @cgif_addframe(ptr noundef nonnull %8, ptr noundef nonnull %2) #7
  call void @free(ptr noundef nonnull %calloc14) #7
  call void @free(ptr noundef nonnull %calloc) #7
  %16 = call i32 @cgif_close(ptr noundef nonnull %8) #7
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %20, label %17

17:                                               ; preds = %13
  %18 = load ptr, ptr @stderr, align 8, !tbaa !16
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.2, i32 noundef %16) #9
  br label %20

20:                                               ; preds = %13, %17, %10
  %.0 = phi i32 [ 1, %10 ], [ 2, %17 ], [ 0, %13 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #7
  ret i32 %.0
}

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

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

declare ptr @cgif_newgif(ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fputs(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #4

declare i32 @cgif_addframe(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

declare i32 @cgif_close(ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { 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" }
attributes #5 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #6 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #7 = { nounwind }
attributes #8 = { cold }
attributes #9 = { cold 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, !11, i64 24}
!6 = !{!"st_gifconfig", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 26, !11, i64 28, !11, i64 30, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !11, i64 26}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !11, i64 28}
!15 = !{!6, !7, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !7, i64 8}
!18 = !{!"st_frameconfig", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 26, !8, i64 28}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass