; LLVM IR from JayXon/Leanify :: lib/zopfli (deflate)

; 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.ZopfliOptions = type { i32, i32, i32, i32, i32, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [61 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @ZopfliDeflatePart(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliDeflate(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #1 {
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store i32 %2, ptr %11, align 4, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i64 %4, ptr %13, align 8, !tbaa !11
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %22 = load ptr, ptr %16, align 8, !tbaa !5
  %23 = load i64, ptr %22, align 8, !tbaa !11
  store i64 %23, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  store i64 0, ptr %18, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %61, %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %25 = load i64, ptr %18, align 8, !tbaa !11
  %26 = add i64 %25, 1000000
  %27 = load i64, ptr %13, align 8, !tbaa !11
  %28 = icmp uge i64 %26, %27
  %29 = zext i1 %28 to i32
  store i32 %29, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %24
  %33 = load i32, ptr %19, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br label %35

35:                                               ; preds = %32, %24
  %36 = phi i1 [ false, %24 ], [ %34, %32 ]
  %37 = zext i1 %36 to i32
  store i32 %37, ptr %20, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %38 = load i32, ptr %19, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %35
  %41 = load i64, ptr %13, align 8, !tbaa !11
  %42 = load i64, ptr %18, align 8, !tbaa !11
  %43 = sub i64 %41, %42
  br label %45

44:                                               ; preds = %35
  br label %45

45:                                               ; preds = %44, %40
  %46 = phi i64 [ %43, %40 ], [ 1000000, %44 ]
  store i64 %46, ptr %21, align 8, !tbaa !11
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %20, align 4, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i64, ptr %18, align 8, !tbaa !11
  %52 = load i64, ptr %18, align 8, !tbaa !11
  %53 = load i64, ptr %21, align 8, !tbaa !11
  %54 = add i64 %52, %53
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = load ptr, ptr %16, align 8, !tbaa !5
  call void @ZopfliDeflatePart(ptr noundef %47, i32 noundef %48, i32 noundef %49, ptr noundef %50, i64 noundef %51, i64 noundef %54, ptr noundef %55, ptr noundef %56, ptr noundef %57)
  %58 = load i64, ptr %21, align 8, !tbaa !11
  %59 = load i64, ptr %18, align 8, !tbaa !11
  %60 = add i64 %59, %58
  store i64 %60, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  br label %61

61:                                               ; preds = %45
  %62 = load i64, ptr %18, align 8, !tbaa !11
  %63 = load i64, ptr %13, align 8, !tbaa !11
  %64 = icmp ult i64 %62, %63
  br i1 %64, label %24, label %65, !llvm.loop !13

65:                                               ; preds = %61
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ZopfliOptions, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 4, !tbaa !15
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %89

70:                                               ; preds = %65
  %71 = load ptr, ptr @stderr, align 8, !tbaa !5
  %72 = load i64, ptr %13, align 8, !tbaa !11
  %73 = load ptr, ptr %16, align 8, !tbaa !5
  %74 = load i64, ptr %73, align 8, !tbaa !11
  %75 = load i64, ptr %17, align 8, !tbaa !11
  %76 = sub i64 %74, %75
  %77 = load i64, ptr %13, align 8, !tbaa !11
  %78 = load ptr, ptr %16, align 8, !tbaa !5
  %79 = load i64, ptr %78, align 8, !tbaa !11
  %80 = load i64, ptr %17, align 8, !tbaa !11
  %81 = sub i64 %79, %80
  %82 = sub i64 %77, %81
  %83 = uitofp i64 %82 to double
  %84 = fmul double 1.000000e+02, %83
  %85 = load i64, ptr %13, align 8, !tbaa !11
  %86 = uitofp i64 %85 to double
  %87 = fdiv double %84, %86
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str, i64 noundef %72, i64 noundef %76, double noundef %87) #3
  br label %89

89:                                               ; preds = %70, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 0}
!16 = !{!"ZopfliOptions", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliDeflate(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) local_unnamed_addr #0 {
  %9 = load i64, ptr %7, align 8, !tbaa !5
  %10 = icmp ne i32 %2, 0
  br label %11

11:                                               ; preds = %11, %8
  %.0 = phi i64 [ 0, %8 ], [ %18, %11 ]
  %12 = add i64 %.0, 1000000
  %13 = icmp uge i64 %12, %4
  %14 = and i1 %10, %13
  %15 = zext i1 %14 to i32
  %16 = sub i64 %4, %.0
  %17 = select i1 %13, i64 %16, i64 1000000
  %18 = add i64 %17, %.0
  tail call void @ZopfliDeflatePart(ptr noundef %0, i32 noundef %1, i32 noundef %15, ptr noundef %3, i64 noundef %.0, i64 noundef %18, ptr noundef %5, ptr noundef %6, ptr noundef nonnull %7)
  %19 = icmp ult i64 %18, %4
  br i1 %19, label %11, label %20, !llvm.loop !9

20:                                               ; preds = %11
  %21 = load i32, ptr %0, align 4, !tbaa !11
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %32, label %22

22:                                               ; preds = %20
  %23 = load ptr, ptr @stderr, align 8, !tbaa !14
  %24 = load i64, ptr %7, align 8, !tbaa !5
  %25 = sub i64 %24, %9
  %26 = sub i64 %4, %25
  %27 = uitofp i64 %26 to double
  %28 = fmul double %27, 1.000000e+02
  %29 = uitofp i64 %4 to double
  %30 = fdiv double %28, %29
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str, i64 noundef %4, i64 noundef %25, double noundef %30) #2
  br label %32

32:                                               ; preds = %22, %20
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 #2 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 0}
!12 = !{!"ZopfliOptions", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass