; LLVM IR from ebiggers/libdeflate :: programs (test_checksums)

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

@rng_seed = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  call void @begin_program(ptr noundef %10)
  call void @alloc_guarded_buffer(i64 noundef 262144, ptr noundef %6, ptr noundef %7)
  %11 = call i64 @time(ptr noundef null) #5
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr @rng_seed, align 4, !tbaa !5
  %13 = load i32, ptr @rng_seed, align 4, !tbaa !5
  call void @srand(i32 noundef %13) #5
  call void @test_initial_values(ptr noundef @adler32_libdeflate, i32 noundef 1)
  call void @test_initial_values(ptr noundef @adler32_zlib, i32 noundef 1)
  call void @test_initial_values(ptr noundef @crc32_libdeflate, i32 noundef 0)
  call void @test_initial_values(ptr noundef @crc32_zlib, i32 noundef 0)
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %14, ptr noundef %15, i64 noundef 256, i32 noundef 5000)
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %16, ptr noundef %17, i64 noundef 1024, i32 noundef 500)
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %18, ptr noundef %19, i64 noundef 32768, i32 noundef 50)
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %20, ptr noundef %21, i64 noundef 262144, i32 noundef 50)
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %22, i8 -1, i64 32768, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %46, %2
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = icmp ult i32 %24, 20
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %49

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 -983056, ptr %9, align 4, !tbaa !5
  br label %33

31:                                               ; preds = %27
  %32 = call i32 @select_initial_adler()
  store i32 %32, ptr %9, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %31, %30
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  %35 = load i32, ptr %9, align 4, !tbaa !5
  call void @test_adler32(ptr noundef %34, i64 noundef 5553, i32 noundef %35)
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = call i32 @rand() #5
  %38 = srem i32 %37, 32769
  %39 = sext i32 %38 to i64
  %40 = load i32, ptr %9, align 4, !tbaa !5
  call void @test_adler32(ptr noundef %36, i64 noundef %39, i32 noundef %40)
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = call i32 @rand() #5
  %43 = srem i32 %42, 32768
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %41, i64 %44
  store i8 -2, ptr %45, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %46

46:                                               ; preds = %33
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = add i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !5
  br label %23, !llvm.loop !12

49:                                               ; preds = %26
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !9
  call void @free_guarded_buffer(ptr noundef %50, ptr noundef %51)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  ret i32 0
}

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

declare void @begin_program(ptr noundef) #2

declare void @alloc_guarded_buffer(i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #3

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @select_initial_adler() #0

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

; Function Attrs: nounwind
declare i32 @rand() #3

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

declare void @free_guarded_buffer(ptr noundef, ptr noundef) #2

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 "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@rng_seed = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
.peel.next:
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  tail call void @begin_program(ptr noundef %1) #5
  call void @alloc_guarded_buffer(i64 noundef 262144, ptr noundef nonnull %2, ptr noundef nonnull %3) #5
  %4 = call i64 @time(ptr noundef null) #5
  %5 = trunc i64 %4 to i32
  store i32 %5, ptr @rng_seed, align 4, !tbaa !5
  call void @srand(i32 noundef %5) #5
  call void @test_initial_values(ptr noundef nonnull @adler32_libdeflate, i32 noundef 1)
  call void @test_initial_values(ptr noundef nonnull @adler32_zlib, i32 noundef 1)
  call void @test_initial_values(ptr noundef nonnull @crc32_libdeflate, i32 noundef 0)
  call void @test_initial_values(ptr noundef nonnull @crc32_zlib, i32 noundef 0)
  %6 = load ptr, ptr %2, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %6, ptr noundef %7, i64 noundef 256, i32 noundef 5000)
  %8 = load ptr, ptr %2, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %8, ptr noundef %9, i64 noundef 1024, i32 noundef 500)
  %10 = load ptr, ptr %2, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %10, ptr noundef %11, i64 noundef 32768, i32 noundef 50)
  %12 = load ptr, ptr %2, align 8, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !9
  call void @test_random_buffers(ptr noundef %12, ptr noundef %13, i64 noundef 262144, i32 noundef 50)
  %14 = load ptr, ptr %2, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(32768) %14, i8 -1, i64 32768, i1 false)
  call void @test_adler32(ptr noundef %14, i64 noundef 5553, i32 noundef -983056)
  %15 = load ptr, ptr %2, align 8, !tbaa !9
  %16 = call i32 @rand() #5
  %17 = srem i32 %16, 32769
  %18 = sext i32 %17 to i64
  call void @test_adler32(ptr noundef %15, i64 noundef %18, i32 noundef -983056)
  %19 = load ptr, ptr %2, align 8, !tbaa !9
  %20 = call i32 @rand() #5
  %21 = srem i32 %20, 32768
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %19, i64 %22
  store i8 -2, ptr %23, align 1, !tbaa !11
  br label %26

.loopexit:                                        ; preds = %26
  %24 = load ptr, ptr %2, align 8, !tbaa !9
  %25 = load ptr, ptr %3, align 8, !tbaa !9
  call void @free_guarded_buffer(ptr noundef %24, ptr noundef %25) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret i32 0

26:                                               ; preds = %.peel.next, %26
  %.056 = phi i32 [ 1, %.peel.next ], [ %38, %26 ]
  %27 = call i32 @select_initial_adler()
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  call void @test_adler32(ptr noundef %28, i64 noundef 5553, i32 noundef %27)
  %29 = load ptr, ptr %2, align 8, !tbaa !9
  %30 = call i32 @rand() #5
  %31 = srem i32 %30, 32769
  %32 = sext i32 %31 to i64
  call void @test_adler32(ptr noundef %29, i64 noundef %32, i32 noundef %27)
  %33 = load ptr, ptr %2, align 8, !tbaa !9
  %34 = call i32 @rand() #5
  %35 = srem i32 %34, 32768
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  store i8 -2, ptr %37, align 1, !tbaa !11
  %38 = add nuw nsw i32 %.056, 1
  %exitcond.not = icmp eq i32 %38, 20
  br i1 %exitcond.not, label %.loopexit, label %26, !llvm.loop !12
}

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

declare void @begin_program(ptr noundef) local_unnamed_addr #2

declare void @alloc_guarded_buffer(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #3

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @select_initial_adler() local_unnamed_addr #0

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

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

declare void @free_guarded_buffer(ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { "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 "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13, !14}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass