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

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4jpgd12jpeg_decoder19get_bits_no_markersEi(ptr noundef nonnull align 8 dereferenceable(13523), i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder15process_restartEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) #4 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  store i32 1536, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %14, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %17

9:                                                ; preds = %6
  %10 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_charEv(ptr noundef nonnull align 8 dereferenceable(13523) %5)
  %11 = icmp eq i32 %10, 255
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  br label %17

13:                                               ; preds = %9
  br label %14

14:                                               ; preds = %13
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !11

17:                                               ; preds = %12, %6
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %5, i32 noundef -229) #6
  unreachable

21:                                               ; preds = %17
  br label %22

22:                                               ; preds = %30, %21
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %22
  %26 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_charEv(ptr noundef nonnull align 8 dereferenceable(13523) %5)
  store i32 %26, ptr %4, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 255
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  br label %33

29:                                               ; preds = %25
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %3, align 4, !tbaa !9
  br label %22, !llvm.loop !13

33:                                               ; preds = %28, %22
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

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

37:                                               ; preds = %33
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 59
  %40 = load i32, ptr %39, align 8, !tbaa !14
  %41 = add nsw i32 %40, 208
  %42 = icmp ne i32 %38, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %5, i32 noundef -229) #6
  unreachable

44:                                               ; preds = %37
  %45 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 63
  %46 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 14
  %47 = load i32, ptr %46, align 4, !tbaa !18
  %48 = sext i32 %47 to i64
  %49 = mul i64 %48, 4
  call void @llvm.memset.p0.i64(ptr align 8 %45, i8 0, i64 %49, i1 false)
  %50 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 46
  store i32 0, ptr %50, align 8, !tbaa !19
  %51 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 57
  %52 = load i32, ptr %51, align 8, !tbaa !20
  %53 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 58
  store i32 %52, ptr %53, align 4, !tbaa !21
  %54 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 59
  %55 = load i32, ptr %54, align 8, !tbaa !14
  %56 = add nsw i32 %55, 1
  %57 = and i32 %56, 7
  %58 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 59
  store i32 %57, ptr %58, align 8, !tbaa !14
  %59 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 55
  store i32 16, ptr %59, align 8, !tbaa !22
  %60 = call noundef i32 @_ZN4jpgd12jpeg_decoder19get_bits_no_markersEi(ptr noundef nonnull align 8 dereferenceable(13523) %5, i32 noundef 16)
  %61 = call noundef i32 @_ZN4jpgd12jpeg_decoder19get_bits_no_markersEi(ptr noundef nonnull align 8 dereferenceable(13523) %5, i32 noundef 16)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4jpgd12jpeg_decoder8get_charEv(ptr noundef nonnull align 8 dereferenceable(13523)) #3 align 2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint 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 = { 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 #5 = { nounwind }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !10, i64 9304}
!15 = !{!"_ZTSN4jpgd12jpeg_decoderE", !7, i64 0, !10, i64 200, !6, i64 208, !10, i64 216, !10, i64 220, !6, i64 224, !10, i64 232, !7, i64 236, !7, i64 248, !7, i64 312, !7, i64 376, !10, i64 408, !10, i64 412, !7, i64 416, !7, i64 432, !7, i64 448, !7, i64 464, !7, i64 480, !7, i64 496, !10, i64 512, !7, i64 516, !7, i64 532, !7, i64 548, !10, i64 564, !10, i64 568, !10, i64 572, !10, i64 576, !10, i64 580, !10, i64 584, !10, i64 588, !10, i64 592, !10, i64 596, !10, i64 600, !7, i64 604, !10, i64 644, !10, i64 648, !10, i64 652, !10, i64 656, !10, i64 660, !10, i64 664, !7, i64 672, !7, i64 736, !7, i64 768, !10, i64 800, !7, i64 804, !6, i64 824, !10, i64 832, !10, i64 836, !7, i64 840, !7, i64 904, !7, i64 9224, !10, i64 9288, !10, i64 9292, !10, i64 9296, !10, i64 9300, !10, i64 9304, !10, i64 9308, !10, i64 9312, !10, 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, !16, i64 13512, !10, i64 13516, !17, i64 13520, !17, i64 13521, !17, i64 13522}
!16 = !{!"_ZTSN4jpgd11jpgd_statusE", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!15, !10, i64 412}
!19 = !{!15, !10, i64 800}
!20 = !{!15, !10, i64 9296}
!21 = !{!15, !10, i64 9300}
!22 = !{!15, !10, i64 9288}


; 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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4jpgd12jpeg_decoder19get_bits_no_markersEi(ptr noundef nonnull align 8 dereferenceable(13523), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder15process_restartEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) local_unnamed_addr #3 align 2 {
  br label %2

2:                                                ; preds = %1, %5
  %.0716 = phi i32 [ 1536, %1 ], [ %6, %5 ]
  %3 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_charEv(ptr noundef nonnull align 8 dereferenceable(13523) %0)
  %4 = icmp eq i32 %3, 255
  br i1 %4, label %.preheader, label %5

5:                                                ; preds = %2
  %6 = add nsw i32 %.0716, -1
  %7 = icmp ugt i32 %.0716, 1
  br i1 %7, label %2, label %9, !llvm.loop !5

.preheader:                                       ; preds = %2
  %8 = icmp sgt i32 %.0716, 0
  br i1 %8, label %.lr.ph, label %.thread

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

.lr.ph:                                           ; preds = %.preheader, %11
  %.1817 = phi i32 [ %12, %11 ], [ %.0716, %.preheader ]
  %10 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_charEv(ptr noundef nonnull align 8 dereferenceable(13523) %0)
  %.not = icmp eq i32 %10, 255
  br i1 %.not, label %11, label %.thread

11:                                               ; preds = %.lr.ph
  %12 = add nsw i32 %.1817, -1
  %13 = icmp sgt i32 %.1817, 1
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %11
  br i1 %8, label %14, label %.thread

14:                                               ; preds = %._crit_edge
  tail call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef -229) #4
  unreachable

.thread:                                          ; preds = %.lr.ph, %.preheader, %._crit_edge
  %.113 = phi i32 [ 255, %._crit_edge ], [ 0, %.preheader ], [ %10, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %0, i64 9304
  %16 = load i32, ptr %15, align 8, !tbaa !8
  %17 = add nsw i32 %16, 208
  %.not11 = icmp eq i32 %.113, %17
  br i1 %.not11, label %19, label %18

18:                                               ; preds = %.thread
  tail call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef -229) #4
  unreachable

19:                                               ; preds = %.thread
  %20 = getelementptr inbounds i8, ptr %0, i64 9320
  %21 = getelementptr inbounds i8, ptr %0, i64 412
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = sext i32 %22 to i64
  %24 = shl nsw i64 %23, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %20, i8 0, i64 %24, i1 false)
  %25 = getelementptr inbounds i8, ptr %0, i64 800
  store i32 0, ptr %25, align 8, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %0, i64 9296
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 9300
  store i32 %27, ptr %28, align 4, !tbaa !19
  %29 = add nsw i32 %16, 1
  %30 = and i32 %29, 7
  store i32 %30, ptr %15, align 8, !tbaa !8
  %31 = getelementptr inbounds i8, ptr %0, i64 9288
  store i32 16, ptr %31, align 8, !tbaa !20
  %32 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder19get_bits_no_markersEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 16)
  %33 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder19get_bits_no_markersEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 16)
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4jpgd12jpeg_decoder8get_charEv(ptr noundef nonnull align 8 dereferenceable(13523)) local_unnamed_addr #2 align 2

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass