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

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

@__const.main.aPalette = external hidden unnamed_addr constant [6 x i8], align 1
@.str = external hidden unnamed_addr constant [44 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = 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 [6 x i8], align 1
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  call void @llvm.lifetime.start.p0(i64 48, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 6, ptr %6) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %6, ptr align 1 @__const.main.aPalette, i64 6, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #7
  store i8 2, ptr %8, align 1, !tbaa !5
  %10 = getelementptr inbounds [6 x i8], ptr %6, i64 0, i64 0
  %11 = load i8, ptr %8, align 1, !tbaa !5
  %12 = zext i8 %11 to i16
  call void @initGIFConfig(ptr noundef %3, ptr noundef %10, i16 noundef zeroext %12, i32 noundef 2, i16 noundef zeroext 100, i16 noundef zeroext 100)
  %13 = call ptr @cgif_newgif(ptr noundef %3)
  store ptr %13, ptr %2, align 8, !tbaa !8
  %14 = load ptr, ptr %2, align 8, !tbaa !8
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %0
  %17 = load ptr, ptr @stderr, align 8, !tbaa !8
  %18 = call i32 @fputs(ptr noundef @.str, ptr noundef %17)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %57

19:                                               ; preds = %0
  %20 = call noalias ptr @malloc(i64 noundef 10000) #8
  store ptr %20, ptr %5, align 8, !tbaa !8
  %21 = load ptr, ptr %5, align 8, !tbaa !8
  call void @llvm.memset.p0.i64(ptr align 1 %21, i8 0, i64 10000, i1 false)
  %22 = load ptr, ptr %5, align 8, !tbaa !8
  call void @initFrameConfig(ptr noundef %4, ptr noundef %22, i16 noundef zeroext 100, i32 noundef 3)
  %23 = load ptr, ptr %2, align 8, !tbaa !8
  %24 = call i32 @cgif_addframe(ptr noundef %23, ptr noundef %4)
  %25 = load ptr, ptr %5, align 8, !tbaa !8
  %26 = getelementptr inbounds i8, ptr %25, i64 7
  call void @llvm.memset.p0.i64(ptr align 1 %26, i8 1, i64 41, i1 false)
  %27 = load ptr, ptr %5, align 8, !tbaa !8
  %28 = getelementptr inbounds i8, ptr %27, i64 7
  %29 = getelementptr inbounds i8, ptr %28, i64 100
  call void @llvm.memset.p0.i64(ptr align 1 %29, i8 1, i64 41, i1 false)
  %30 = load ptr, ptr %5, align 8, !tbaa !8
  %31 = getelementptr inbounds i8, ptr %30, i64 7
  %32 = getelementptr inbounds i8, ptr %31, i64 200
  call void @llvm.memset.p0.i64(ptr align 1 %32, i8 1, i64 41, i1 false)
  %33 = load ptr, ptr %5, align 8, !tbaa !8
  %34 = getelementptr inbounds i8, ptr %33, i64 7
  %35 = getelementptr inbounds i8, ptr %34, i64 200
  call void @llvm.memset.p0.i64(ptr align 1 %35, i8 0, i64 29, i1 false)
  %36 = load ptr, ptr %5, align 8, !tbaa !8
  %37 = getelementptr inbounds i8, ptr %36, i64 7
  %38 = getelementptr inbounds i8, ptr %37, i64 300
  call void @llvm.memset.p0.i64(ptr align 1 %38, i8 1, i64 41, i1 false)
  %39 = load ptr, ptr %5, align 8, !tbaa !8
  %40 = getelementptr inbounds i8, ptr %39, i64 7
  %41 = getelementptr inbounds i8, ptr %40, i64 300
  call void @llvm.memset.p0.i64(ptr align 1 %41, i8 0, i64 23, i1 false)
  %42 = load ptr, ptr %5, align 8, !tbaa !8
  %43 = getelementptr inbounds i8, ptr %42, i64 7
  %44 = getelementptr inbounds i8, ptr %43, i64 400
  call void @llvm.memset.p0.i64(ptr align 1 %44, i8 0, i64 37, i1 false)
  %45 = load ptr, ptr %2, align 8, !tbaa !8
  %46 = call i32 @cgif_addframe(ptr noundef %45, ptr noundef %4)
  store i32 %46, ptr %7, align 4, !tbaa !10
  %47 = load ptr, ptr %5, align 8, !tbaa !8
  call void @free(ptr noundef %47) #7
  %48 = load ptr, ptr %2, align 8, !tbaa !8
  %49 = call i32 @cgif_close(ptr noundef %48)
  store i32 %49, ptr %7, align 4, !tbaa !10
  %50 = load i32, ptr %7, align 4, !tbaa !10
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %56

52:                                               ; preds = %19
  %53 = load ptr, ptr @stderr, align 8, !tbaa !8
  %54 = load i32, ptr %7, align 4, !tbaa !10
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.1, i32 noundef %54) #7
  store i32 2, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %57

56:                                               ; preds = %19
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %57

57:                                               ; preds = %56, %52, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 6, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 48, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  %58 = load i32, ptr %1, align 4
  ret i32 %58
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

declare ptr @cgif_newgif(ptr noundef) #3

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

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

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

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

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

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

declare i32 @cgif_close(ptr noundef) #3

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

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, 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 }

@__const.main.aPalette = external hidden unnamed_addr constant [6 x i8], align 1
@.str = external hidden unnamed_addr constant [44 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = 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
  %3 = alloca [6 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #8
  call void @llvm.lifetime.start.p0(i64 6, ptr nonnull %3) #8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %3, ptr noundef nonnull align 1 dereferenceable(6) @__const.main.aPalette, i64 6, i1 false)
  call void @initGIFConfig(ptr noundef nonnull %1, ptr noundef nonnull %3, i16 noundef zeroext 2, i32 noundef 2, i16 noundef zeroext 100, i16 noundef zeroext 100)
  %4 = call ptr @cgif_newgif(ptr noundef nonnull %1) #8
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %9

6:                                                ; preds = %0
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = call i32 @fputs(ptr noundef nonnull @.str, ptr noundef %7) #9
  br label %23

9:                                                ; preds = %0
  %calloc = call dereferenceable_or_null(10000) ptr @calloc(i64 1, i64 10000)
  call void @initFrameConfig(ptr noundef nonnull %2, ptr noundef %calloc, i16 noundef zeroext 100, i32 noundef 3)
  %10 = call i32 @cgif_addframe(ptr noundef nonnull %4, ptr noundef nonnull %2) #8
  %11 = getelementptr inbounds i8, ptr %calloc, i64 7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(41) %11, i8 1, i64 41, i1 false)
  %12 = getelementptr inbounds i8, ptr %calloc, i64 107
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(41) %12, i8 1, i64 41, i1 false)
  %13 = getelementptr inbounds i8, ptr %calloc, i64 207
  %14 = getelementptr inbounds i8, ptr %calloc, i64 236
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(41) %14, i8 1, i64 12, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(29) %13, i8 0, i64 29, i1 false)
  %15 = getelementptr inbounds i8, ptr %calloc, i64 307
  %16 = getelementptr inbounds i8, ptr %calloc, i64 330
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(41) %16, i8 1, i64 18, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(23) %15, i8 0, i64 23, i1 false)
  %17 = getelementptr inbounds i8, ptr %calloc, i64 407
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(37) %17, i8 0, i64 37, i1 false)
  %18 = call i32 @cgif_addframe(ptr noundef nonnull %4, ptr noundef nonnull %2) #8
  call void @free(ptr noundef %calloc) #8
  %19 = call i32 @cgif_close(ptr noundef nonnull %4) #8
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %23, label %20

20:                                               ; preds = %9
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.1, i32 noundef %19) #10
  br label %23

23:                                               ; preds = %9, %20, %6
  %.0 = phi i32 [ 1, %6 ], [ 2, %20 ], [ 0, %9 ]
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #8
  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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

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

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

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 #6

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 #7

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: readwrite) }
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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #8 = { nounwind }
attributes #9 = { cold }
attributes #10 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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