; LLVM IR from simbody/simbody :: Simbody/Visualizer/simbody-visualizer/lodepng.ll (Z17LodeFlate_inflateP8ucvectorPKhmm)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z17LodeFlate_inflateP8ucvectorPKhmm(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 0, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %77, %4
  %17 = load i32, ptr %11, align 4, !tbaa !11
  %18 = icmp ne i32 %17, 0
  %19 = xor i1 %18, true
  br i1 %19, label %20, label %78

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = add i64 %21, 2
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = mul i64 %23, 8
  %25 = icmp uge i64 %22, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store i32 52, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %75

27:                                               ; preds = %20
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = call noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef %10, ptr noundef %30)
  %32 = zext i8 %31 to i32
  store i32 %32, ptr %11, align 4, !tbaa !11
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %33, i64 %34
  %36 = call noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef %10, ptr noundef %35)
  %37 = zext i8 %36 to i32
  %38 = mul nsw i32 1, %37
  store i32 %38, ptr %14, align 4, !tbaa !11
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = call noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef %10, ptr noundef %41)
  %43 = zext i8 %42 to i32
  %44 = mul nsw i32 2, %43
  %45 = load i32, ptr %14, align 4, !tbaa !11
  %46 = add i32 %45, %44
  store i32 %46, ptr %14, align 4, !tbaa !11
  %47 = load i32, ptr %14, align 4, !tbaa !11
  %48 = icmp eq i32 %47, 3
  br i1 %48, label %49, label %50

49:                                               ; preds = %27
  store i32 20, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %75

50:                                               ; preds = %27
  %51 = load i32, ptr %14, align 4, !tbaa !11
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %60

53:                                               ; preds = %50
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = call noundef i32 @_ZL20inflateNoCompressionP8ucvectorPKhPmS3_m(ptr noundef %54, ptr noundef %57, ptr noundef %10, ptr noundef %12, i64 noundef %58)
  store i32 %59, ptr %13, align 4, !tbaa !11
  br label %68

60:                                               ; preds = %50
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load i64, ptr %9, align 8, !tbaa !9
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  %65 = load i64, ptr %8, align 8, !tbaa !9
  %66 = load i32, ptr %14, align 4, !tbaa !11
  %67 = call noundef i32 @_ZL19inflateHuffmanBlockP8ucvectorPKhPmS3_mj(ptr noundef %61, ptr noundef %64, ptr noundef %10, ptr noundef %12, i64 noundef %65, i32 noundef %66)
  store i32 %67, ptr %13, align 4, !tbaa !11
  br label %68

68:                                               ; preds = %60, %53
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %13, align 4, !tbaa !11
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %74

72:                                               ; preds = %69
  %73 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %73, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %75

74:                                               ; preds = %69
  store i32 0, ptr %15, align 4
  br label %75

75:                                               ; preds = %74, %72, %49, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %76 = load i32, ptr %15, align 4
  switch i32 %76, label %86 [
    i32 0, label %77
  ]

77:                                               ; preds = %75
  br label %16, !llvm.loop !13

78:                                               ; preds = %16
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i64, ptr %12, align 8, !tbaa !9
  %81 = call noundef i32 @_ZL15ucvector_resizeP8ucvectorm(ptr noundef %79, i64 noundef %80)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %84, label %83

83:                                               ; preds = %78
  store i32 9916, ptr %13, align 4, !tbaa !11
  br label %84

84:                                               ; preds = %83, %78
  %85 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %85, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %86

86:                                               ; preds = %84, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %87 = load i32, ptr %5, align 4
  ret i32 %87
}

; 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 noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef, ptr noundef) #2

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

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

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

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

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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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
define dso_local noundef i32 @_Z17LodeFlate_inflateP8ucvectorPKhmm(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i64 0, ptr %6, align 8, !tbaa !5
  %7 = shl i64 %2, 3
  %8 = getelementptr inbounds i8, ptr %1, i64 %3
  br label %9

9:                                                ; preds = %26, %4
  %.026 = phi i32 [ 0, %4 ], [ %15, %26 ]
  %.not = icmp eq i32 %.026, 0
  br i1 %.not, label %10, label %27

10:                                               ; preds = %9
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = add i64 %11, 2
  %.not33 = icmp ult i64 %12, %7
  br i1 %.not33, label %13, label %.thread

13:                                               ; preds = %10
  %14 = call noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef nonnull %5, ptr noundef %8)
  %15 = zext i8 %14 to i32
  %16 = call noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef nonnull %5, ptr noundef %8)
  %17 = zext i8 %16 to i32
  %18 = call noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef nonnull %5, ptr noundef %8)
  %19 = zext i8 %18 to i32
  %20 = shl nuw nsw i32 %19, 1
  %21 = add nuw nsw i32 %20, %17
  switch i32 %21, label %24 [
    i32 3, label %.thread
    i32 0, label %22
  ]

22:                                               ; preds = %13
  %23 = call noundef i32 @_ZL20inflateNoCompressionP8ucvectorPKhPmS3_m(ptr noundef %0, ptr noundef %8, ptr noundef nonnull %5, ptr noundef nonnull %6, i64 noundef %2)
  br label %26

24:                                               ; preds = %13
  %25 = call noundef i32 @_ZL19inflateHuffmanBlockP8ucvectorPKhPmS3_mj(ptr noundef %0, ptr noundef %8, ptr noundef nonnull %5, ptr noundef nonnull %6, i64 noundef %2, i32 noundef %21)
  br label %26

26:                                               ; preds = %24, %22
  %.1 = phi i32 [ %23, %22 ], [ %25, %24 ]
  %.not34 = icmp eq i32 %.1, 0
  br i1 %.not34, label %9, label %.thread, !llvm.loop !9

27:                                               ; preds = %9
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = call noundef i32 @_ZL15ucvector_resizeP8ucvectorm(ptr noundef %0, i64 noundef %28)
  %.not32 = icmp eq i32 %29, 0
  %spec.select = select i1 %.not32, i32 9916, i32 0
  br label %.thread

.thread:                                          ; preds = %13, %10, %26, %27
  %.230 = phi i32 [ %spec.select, %27 ], [ 52, %10 ], [ 20, %13 ], [ %.1, %26 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i32 %.230
}

; 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 noundef zeroext i8 @_ZL17readBitFromStreamPmPKh(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

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

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass