; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/jpgd.ll (ZN4jpgd12jpeg_decoder14prep_in_bufferEv)

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

%"class.jpgd::jpeg_decoder" = type <{ [1 x %struct.__jmp_buf_tag], i32, [4 x i8], ptr, i32, i32, ptr, i32, [8 x i8], [4 x i8], [8 x ptr], [8 x ptr], [4 x ptr], i32, i32, [4 x i32], [4 x i32], [4 x i32], [4 x i32], [4 x i32], [4 x i32], i32, [4 x i32], [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [10 x i32], i32, i32, i32, i32, i32, i32, [4 x i8], [8 x ptr], [4 x ptr], [4 x ptr], i32, [4 x i32], [4 x i8], ptr, i32, i32, [64 x i8], [8320 x i8], [64 x i8], i32, i32, i32, i32, i32, i32, i32, i32, [4 x i32], ptr, [10 x i32], ptr, ptr, [256 x i32], [256 x i32], [256 x i32], [256 x i32], ptr, ptr, i32, i32, i8, i8, i8, [5 x i8] }>
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

; 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: mustprogress noreturn uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder10word_clearEPvtj(ptr noundef nonnull align 8 dereferenceable(13523), ptr noundef, i16 noundef zeroext, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder14prep_in_bufferEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 50
  store i32 0, ptr %5, align 8, !tbaa !9
  %6 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 53
  %7 = getelementptr inbounds [8320 x i8], ptr %6, i64 0, i64 0
  %8 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 49
  store ptr %7, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 77
  %10 = load i8, ptr %9, align 1, !tbaa !15, !range !16, !noundef !17
  %11 = trunc i8 %10 to i1
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  br label %62

13:                                               ; preds = %1
  br label %14

14:                                               ; preds = %48, %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %15 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 6
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 53
  %18 = getelementptr inbounds [8320 x i8], ptr %17, i64 0, i64 0
  %19 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 50
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  %23 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 50
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = sub nsw i32 8192, %24
  %26 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 77
  %27 = load ptr, ptr %16, align 8, !tbaa !19
  %28 = getelementptr inbounds ptr, ptr %27, i64 2
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(8) %16, ptr noundef %22, i32 noundef %25, ptr noundef %26)
  store i32 %30, ptr %3, align 4, !tbaa !21
  %31 = load i32, ptr %3, align 4, !tbaa !21
  %32 = icmp eq i32 %31, -1
  br i1 %32, label %33, label %34

33:                                               ; preds = %14
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %4, i32 noundef -226) #5
  unreachable

34:                                               ; preds = %14
  %35 = load i32, ptr %3, align 4, !tbaa !21
  %36 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 50
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = add nsw i32 %37, %35
  store i32 %38, ptr %36, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %39

39:                                               ; preds = %34
  %40 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 50
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = icmp slt i32 %41, 8192
  br i1 %42, label %43, label %48

43:                                               ; preds = %39
  %44 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 77
  %45 = load i8, ptr %44, align 1, !tbaa !15, !range !16, !noundef !17
  %46 = trunc i8 %45 to i1
  %47 = xor i1 %46, true
  br label %48

48:                                               ; preds = %43, %39
  %49 = phi i1 [ false, %39 ], [ %47, %43 ]
  br i1 %49, label %14, label %50, !llvm.loop !22

50:                                               ; preds = %48
  %51 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 50
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 75
  %54 = load i32, ptr %53, align 4, !tbaa !24
  %55 = add nsw i32 %54, %52
  store i32 %55, ptr %53, align 4, !tbaa !24
  %56 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 49
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %4, i32 0, i32 50
  %59 = load i32, ptr %58, align 8, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  call void @_ZN4jpgd12jpeg_decoder10word_clearEPvtj(ptr noundef nonnull align 8 dereferenceable(13523) %4, ptr noundef %61, i16 noundef zeroext -9729, i32 noundef 64)
  br label %62

62:                                               ; preds = %50, %12
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress noreturn 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 = { 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 = { 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 #4 = { nounwind }
attributes #5 = { noreturn }

!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 832}
!10 = !{!"_ZTSN4jpgd12jpeg_decoderE", !7, i64 0, !11, i64 200, !6, i64 208, !11, i64 216, !11, i64 220, !6, i64 224, !11, i64 232, !7, i64 236, !7, i64 248, !7, i64 312, !7, i64 376, !11, i64 408, !11, i64 412, !7, i64 416, !7, i64 432, !7, i64 448, !7, i64 464, !7, i64 480, !7, i64 496, !11, i64 512, !7, i64 516, !7, i64 532, !7, i64 548, !11, i64 564, !11, i64 568, !11, i64 572, !11, i64 576, !11, i64 580, !11, i64 584, !11, i64 588, !11, i64 592, !11, i64 596, !11, i64 600, !7, i64 604, !11, i64 644, !11, i64 648, !11, i64 652, !11, i64 656, !11, i64 660, !11, i64 664, !7, i64 672, !7, i64 736, !7, i64 768, !11, i64 800, !7, i64 804, !6, i64 824, !11, i64 832, !11, i64 836, !7, i64 840, !7, i64 904, !7, i64 9224, !11, i64 9288, !11, i64 9292, !11, i64 9296, !11, i64 9300, !11, i64 9304, !11, i64 9308, !11, i64 9312, !11, i64 9316, !7, i64 9320, !6, i64 9336, !7, i64 9344, !6, i64 9384, !6, i64 9392, !7, i64 9400, !7, i64 10424, !7, i64 11448, !7, i64 12472, !6, i64 13496, !6, i64 13504, !12, i64 13512, !11, i64 13516, !13, i64 13520, !13, i64 13521, !13, i64 13522}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN4jpgd11jpgd_statusE", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!10, !6, i64 824}
!15 = !{!10, !13, i64 13521}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !6, i64 224}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = !{!11, !11, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!10, !11, i64 13516}


; 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 noreturn uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder10word_clearEPvtj(ptr noundef nonnull align 8 dereferenceable(13523), ptr noundef, i16 noundef zeroext, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder14prep_in_bufferEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 832
  store i32 0, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 904
  %4 = getelementptr inbounds i8, ptr %0, i64 824
  store ptr %3, ptr %4, align 8, !tbaa !13
  %5 = getelementptr inbounds i8, ptr %0, i64 13521
  %6 = load i8, ptr %5, align 1, !tbaa !14, !range !15, !noundef !16
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %34, label %.preheader

.preheader:                                       ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 224
  br label %9

9:                                                ; preds = %.preheader, %25
  %10 = phi i32 [ 0, %.preheader ], [ %23, %25 ]
  %11 = load ptr, ptr %8, align 8, !tbaa !17
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds i8, ptr %3, i64 %12
  %14 = sub nsw i32 8192, %10
  %15 = load ptr, ptr %11, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = load ptr, ptr %16, align 8
  %18 = tail call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull %13, i32 noundef %14, ptr noundef nonnull %5)
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %21

20:                                               ; preds = %9
  tail call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef -226) #3
  unreachable

21:                                               ; preds = %9
  %22 = load i32, ptr %2, align 8, !tbaa !5
  %23 = add nsw i32 %22, %18
  store i32 %23, ptr %2, align 8, !tbaa !5
  %24 = icmp slt i32 %23, 8192
  br i1 %24, label %25, label %.critedge

25:                                               ; preds = %21
  %26 = load i8, ptr %5, align 1, !tbaa !14, !range !15, !noundef !16
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %.critedge, label %9, !llvm.loop !20

.critedge:                                        ; preds = %21, %25
  %28 = getelementptr inbounds i8, ptr %0, i64 13516
  %29 = load i32, ptr %28, align 4, !tbaa !22
  %30 = add nsw i32 %29, %23
  store i32 %30, ptr %28, align 4, !tbaa !22
  %31 = load ptr, ptr %4, align 8, !tbaa !13
  %32 = sext i32 %23 to i64
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  tail call void @_ZN4jpgd12jpeg_decoder10word_clearEPvtj(ptr noundef nonnull align 8 dereferenceable(13523) %0, ptr noundef %33, i16 noundef zeroext -9729, i32 noundef 64)
  br label %34

34:                                               ; preds = %1, %.critedge
  ret void
}

attributes #0 = { mustprogress noreturn 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 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 = { 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 #3 = { noreturn }

!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, !9, i64 832}
!6 = !{!"_ZTSN4jpgd12jpeg_decoderE", !7, i64 0, !9, i64 200, !10, i64 208, !9, i64 216, !9, i64 220, !10, i64 224, !9, i64 232, !7, i64 236, !7, i64 248, !7, i64 312, !7, i64 376, !9, i64 408, !9, i64 412, !7, i64 416, !7, i64 432, !7, i64 448, !7, i64 464, !7, i64 480, !7, i64 496, !9, i64 512, !7, i64 516, !7, i64 532, !7, i64 548, !9, i64 564, !9, i64 568, !9, i64 572, !9, i64 576, !9, i64 580, !9, i64 584, !9, i64 588, !9, i64 592, !9, i64 596, !9, i64 600, !7, i64 604, !9, i64 644, !9, i64 648, !9, i64 652, !9, i64 656, !9, i64 660, !9, i64 664, !7, i64 672, !7, i64 736, !7, i64 768, !9, i64 800, !7, i64 804, !10, i64 824, !9, i64 832, !9, i64 836, !7, i64 840, !7, i64 904, !7, i64 9224, !9, i64 9288, !9, i64 9292, !9, i64 9296, !9, i64 9300, !9, i64 9304, !9, i64 9308, !9, i64 9312, !9, i64 9316, !7, i64 9320, !10, i64 9336, !7, i64 9344, !10, i64 9384, !10, i64 9392, !7, i64 9400, !7, i64 10424, !7, i64 11448, !7, i64 12472, !10, i64 13496, !10, i64 13504, !11, i64 13512, !9, i64 13516, !12, i64 13520, !12, i64 13521, !12, i64 13522}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"_ZTSN4jpgd11jpgd_statusE", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!6, !10, i64 824}
!14 = !{!6, !12, i64 13521}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !10, i64 224}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !9, i64 13516}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass