; LLVM IR from zeux/meshoptimizer :: demo (main)

; 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.sdefl = type { i32, i32, [32768 x i32], [32768 x i32], i32, [87382 x %struct.sdefl_seqt], %struct.sdefl_freq, %struct.sdefl_codes }
%struct.sdefl_seqt = type { i32, i32 }
%struct.sdefl_freq = type { [288 x i32], [32 x i32] }
%struct.sdefl_codes = type { %struct.sdefl_code_words, %struct.sdefl_lens }
%struct.sdefl_code_words = type { [288 x i32], [32 x i32] }
%struct.sdefl_lens = type { [288 x i8], [32 x i8] }

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL11sdefl_comprP5sdeflPhPKhii(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local i32 @zsdeflate(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %14, ptr %13, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.sdefl, ptr %15, i32 0, i32 1
  store i32 0, ptr %16, align 4, !tbaa !11
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.sdefl, ptr %17, i32 0, i32 0
  store i32 0, ptr %18, align 4, !tbaa !17
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef %13, ptr noundef %19, i32 noundef 120, i32 noundef 8)
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef %13, ptr noundef %20, i32 noundef 1, i32 noundef 8)
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %13, align 8, !tbaa !5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = call noundef i32 @_ZL11sdefl_comprP5sdeflPhPKhii(ptr noundef %21, ptr noundef %22, ptr noundef %23, i32 noundef %24, i32 noundef %25)
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds i8, ptr %27, i64 %28
  store ptr %29, ptr %13, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = call noundef i32 @_ZL13sdefl_adler32jPKhi(i32 noundef 1, ptr noundef %30, i32 noundef %31)
  store i32 %32, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %43, %5
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 4
  br i1 %35, label %36, label %46

36:                                               ; preds = %33
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = lshr i32 %38, 24
  %40 = and i32 %39, 255
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef %13, ptr noundef %37, i32 noundef %40, i32 noundef 8)
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = shl i32 %41, 8
  store i32 %42, ptr %12, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %36
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %11, align 4, !tbaa !9
  br label %33, !llvm.loop !18

46:                                               ; preds = %33
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = ptrtoint ptr %47 to i64
  %50 = ptrtoint ptr %48 to i64
  %51 = sub i64 %49, %50
  %52 = trunc i64 %51 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret i32 %52
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13sdefl_adler32jPKhi(i32 noundef, ptr noundef, i32 noundef) #2

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

attributes #0 = { mustprogress 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 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS5sdefl", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 131080, !10, i64 262152, !7, i64 262156, !13, i64 961212, !14, i64 962492}
!13 = !{!"_ZTS10sdefl_freq", !7, i64 0, !7, i64 1152}
!14 = !{!"_ZTS11sdefl_codes", !15, i64 0, !16, i64 1280}
!15 = !{!"_ZTS16sdefl_code_words", !7, i64 0, !7, i64 1152}
!16 = !{!"_ZTS10sdefl_lens", !7, i64 0, !7, i64 288}
!17 = !{!12, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL11sdefl_comprP5sdeflPhPKhii(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local i32 @zsdeflate(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store ptr %1, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 0, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %0, align 4, !tbaa !16
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef nonnull %6, ptr noundef nonnull %0, i32 noundef 120, i32 noundef 8)
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef nonnull %6, ptr noundef nonnull %0, i32 noundef 1, i32 noundef 8)
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = call noundef i32 @_ZL11sdefl_comprP5sdeflPhPKhii(ptr noundef nonnull %0, ptr noundef %8, ptr noundef %2, i32 noundef %3, i32 noundef %4)
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds i8, ptr %10, i64 %11
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = call noundef i32 @_ZL13sdefl_adler32jPKhi(i32 noundef 1, ptr noundef %2, i32 noundef %3)
  %14 = lshr i32 %13, 24
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef nonnull %6, ptr noundef nonnull %0, i32 noundef %14, i32 noundef 8)
  %15 = lshr i32 %13, 16
  %16 = and i32 %15, 255
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef nonnull %6, ptr noundef nonnull %0, i32 noundef %16, i32 noundef 8)
  %17 = lshr i32 %13, 8
  %18 = and i32 %17, 255
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef nonnull %6, ptr noundef nonnull %0, i32 noundef %18, i32 noundef 8)
  %19 = and i32 %13, 255
  call void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef nonnull %6, ptr noundef nonnull %0, i32 noundef %19, i32 noundef 8)
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = ptrtoint ptr %1 to i64
  %23 = sub i64 %21, %22
  %24 = trunc i64 %23 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i32 %24
}

; 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 nounwind uwtable
declare hidden void @_ZL9sdefl_putPPhP5sdeflii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13sdefl_adler32jPKhi(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 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 #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++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"_ZTS5sdefl", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 131080, !11, i64 262152, !7, i64 262156, !12, i64 961212, !13, i64 962492}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS10sdefl_freq", !7, i64 0, !7, i64 1152}
!13 = !{!"_ZTS11sdefl_codes", !14, i64 0, !15, i64 1280}
!14 = !{!"_ZTS16sdefl_code_words", !7, i64 0, !7, i64 1152}
!15 = !{!"_ZTS10sdefl_lens", !7, i64 0, !7, i64 288}
!16 = !{!10, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass