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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder17locate_soi_markerEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %8 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %7, i32 noundef 8)
  store i32 %8, ptr %3, align 4, !tbaa !9
  %9 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %7, i32 noundef 8)
  store i32 %9, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 255
  br i1 %11, label %12, label %16

12:                                               ; preds = %1
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 216
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  store i32 1, ptr %6, align 4
  br label %47

16:                                               ; preds = %12, %1
  store i32 4096, ptr %5, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %37, %16
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = add i32 %18, -1
  store i32 %19, ptr %5, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

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

22:                                               ; preds = %17
  %23 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %23, ptr %3, align 4, !tbaa !9
  %24 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %7, i32 noundef 8)
  store i32 %24, ptr %4, align 4, !tbaa !9
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 255
  br i1 %26, label %27, label %37

27:                                               ; preds = %22
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 216
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  br label %38

31:                                               ; preds = %27
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 217
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %7, i32 noundef -239) #5
  unreachable

35:                                               ; preds = %31
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %22
  br label %17, !llvm.loop !11

38:                                               ; preds = %30
  %39 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %7, i32 0, i32 56
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = lshr i32 %40, 24
  %42 = and i32 %41, 255
  store i32 %42, ptr %4, align 4, !tbaa !9
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 255
  br i1 %44, label %45, label %46

45:                                               ; preds = %38
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %7, i32 noundef -239) #5
  unreachable

46:                                               ; preds = %38
  store i32 0, ptr %6, align 4
  br label %47

47:                                               ; preds = %46, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %48 = load i32, ptr %6, align 4
  switch i32 %48, label %50 [
    i32 0, label %49
    i32 1, label %49
  ]

49:                                               ; preds = %47, %47
  ret void

50:                                               ; preds = %47
  unreachable
}

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 = { 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 9292}
!14 = !{!"_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, !15, i64 13512, !10, i64 13516, !16, i64 13520, !16, i64 13521, !16, i64 13522}
!15 = !{!"_ZTSN4jpgd11jpgd_statusE", !7, i64 0}
!16 = !{!"bool", !7, i64 0}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder17locate_soi_markerEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) local_unnamed_addr #2 align 2 {
  %2 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 8)
  %3 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 8)
  %4 = icmp eq i32 %2, 255
  %5 = icmp eq i32 %3, 216
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %19, label %.preheader

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

.preheader:                                       ; preds = %1, %12
  %7 = phi i32 [ %13, %12 ], [ 4095, %1 ]
  %.0912 = phi i32 [ %8, %12 ], [ %3, %1 ]
  %8 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 8)
  %9 = icmp eq i32 %.0912, 255
  br i1 %9, label %10, label %12

10:                                               ; preds = %.preheader
  switch i32 %8, label %12 [
    i32 216, label %15
    i32 217, label %11
  ]

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

12:                                               ; preds = %10, %.preheader
  %13 = add nsw i32 %7, -1
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %6, label %.preheader, !llvm.loop !5

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 9292
  %17 = load i32, ptr %16, align 4, !tbaa !7
  %.not = icmp ugt i32 %17, -16777217
  br i1 %.not, label %19, label %18

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

19:                                               ; preds = %15, %1
  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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !11, i64 9292}
!8 = !{!"_ZTSN4jpgd12jpeg_decoderE", !9, i64 0, !11, i64 200, !12, i64 208, !11, i64 216, !11, i64 220, !12, i64 224, !11, i64 232, !9, i64 236, !9, i64 248, !9, i64 312, !9, i64 376, !11, i64 408, !11, i64 412, !9, i64 416, !9, i64 432, !9, i64 448, !9, i64 464, !9, i64 480, !9, i64 496, !11, i64 512, !9, i64 516, !9, i64 532, !9, 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, !9, i64 604, !11, i64 644, !11, i64 648, !11, i64 652, !11, i64 656, !11, i64 660, !11, i64 664, !9, i64 672, !9, i64 736, !9, i64 768, !11, i64 800, !9, i64 804, !12, i64 824, !11, i64 832, !11, i64 836, !9, i64 840, !9, i64 904, !9, 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, !9, i64 9320, !12, i64 9336, !9, i64 9344, !12, i64 9384, !12, i64 9392, !9, i64 9400, !9, i64 10424, !9, i64 11448, !9, i64 12472, !12, i64 13496, !12, i64 13504, !13, i64 13512, !11, i64 13516, !14, i64 13520, !14, i64 13521, !14, i64 13522}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"_ZTSN4jpgd11jpgd_statusE", !9, i64 0}
!14 = !{!"bool", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass