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

; 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 [36 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 [6 x i8], align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 6, ptr %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 @__const.main.aPalette, i64 6, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 48, i1 false)
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 32, i1 false)
  %8 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 4
  store i16 100, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 5
  store i16 100, ptr %9, align 2, !tbaa !12
  %10 = getelementptr inbounds [6 x i8], ptr %5, i64 0, i64 0
  %11 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 0
  store ptr %10, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 6
  store i16 2, ptr %12, align 4, !tbaa !14
  %13 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 8
  store ptr @pWriteFn, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds %struct.st_gifconfig, ptr %3, i32 0, i32 9
  store ptr null, ptr %14, align 8, !tbaa !16
  %15 = call ptr @cgif_newgif(ptr noundef %3)
  store ptr %15, ptr %2, align 8, !tbaa !17
  %16 = load ptr, ptr %2, align 8, !tbaa !17
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %21

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

21:                                               ; preds = %0
  %22 = load ptr, ptr %2, align 8, !tbaa !17
  %23 = call i32 @cgif_close(ptr noundef %22)
  store i32 %23, ptr %6, align 4, !tbaa !18
  %24 = load i32, ptr %6, align 4, !tbaa !18
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %30

27:                                               ; preds = %21
  %28 = load ptr, ptr @stderr, align 8, !tbaa !17
  %29 = call i32 @fputs(ptr noundef @.str.1, ptr noundef %28)
  store i32 2, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %30

30:                                               ; preds = %27, %26, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 6, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %31 = load i32, ptr %1, align 4
  ret i32 %31
}

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

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

declare ptr @cgif_newgif(ptr noundef) #4

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

declare i32 @cgif_close(ptr noundef) #4

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

!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 32}
!16 = !{!6, !7, i64 40}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !10, 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 }

@__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 [36 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 [6 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 6, ptr nonnull %2) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %2, ptr noundef nonnull align 1 dereferenceable(6) @__const.main.aPalette, i64 6, i1 false)
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %3, i8 0, i64 24, 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 %2, ptr %1, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %1, i64 28
  store i16 2, ptr %6, align 4, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  store ptr @pWriteFn, ptr %7, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %1, i64 40
  store ptr null, ptr %8, align 8, !tbaa !16
  %9 = call ptr @cgif_newgif(ptr noundef nonnull %1) #6
  %10 = icmp eq ptr %9, null
  br i1 %10, label %.sink.split, label %11

11:                                               ; preds = %0
  %12 = call i32 @cgif_close(ptr noundef nonnull %9) #6
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %.sink.split, label %15

.sink.split:                                      ; preds = %11, %0
  %.str.1.sink = phi ptr [ @.str, %0 ], [ @.str.1, %11 ]
  %.0.ph = phi i32 [ 1, %0 ], [ 2, %11 ]
  %13 = load ptr, ptr @stderr, align 8, !tbaa !17
  %14 = call i32 @fputs(ptr noundef nonnull %.str.1.sink, ptr noundef %13) #7
  br label %15

15:                                               ; preds = %.sink.split, %11
  %.0 = phi i32 [ 0, %11 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #6
  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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

declare ptr @cgif_newgif(ptr noundef) local_unnamed_addr #4

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

declare i32 @cgif_close(ptr noundef) 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

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 = { mustprogress 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 = { 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 #6 = { nounwind }
attributes #7 = { cold }

!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 32}
!16 = !{!6, !7, i64 40}
!17 = !{!7, !7, i64 0}


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