; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/jpgd.ll (ZN4jpgd12jpeg_decoder15read_dqt_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: mustprogress uwtable
declare dso_local noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523), i64 noundef, i1 noundef zeroext) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder15read_dqt_markerEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) #2 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
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %9 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %8, i32 noundef 16)
  store i32 %9, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp ult i32 %10, 2
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %8, i32 noundef -253) #5
  unreachable

13:                                               ; preds = %1
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sub i32 %14, 2
  store i32 %15, ptr %6, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %79, %13
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %83

19:                                               ; preds = %16
  %20 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %8, i32 noundef 8)
  store i32 %20, ptr %3, align 4, !tbaa !9
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = ashr i32 %21, 4
  store i32 %22, ptr %5, align 4, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = and i32 %23, 15
  store i32 %24, ptr %3, align 4, !tbaa !9
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = icmp sge i32 %25, 4
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %8, i32 noundef -252) #5
  unreachable

28:                                               ; preds = %19
  %29 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %8, i32 0, i32 12
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4 x ptr], ptr %29, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %41, label %35

35:                                               ; preds = %28
  %36 = call noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523) %8, i64 noundef 128, i1 noundef zeroext false)
  %37 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %8, i32 0, i32 12
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [4 x ptr], ptr %37, i64 0, i64 %39
  store ptr %36, ptr %40, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %35, %28
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %65, %41
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = icmp slt i32 %43, 64
  br i1 %44, label %45, label %68

45:                                               ; preds = %42
  %46 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %8, i32 noundef 8)
  store i32 %46, ptr %7, align 4, !tbaa !9
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %45
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = shl i32 %50, 8
  %52 = call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %8, i32 noundef 8)
  %53 = add i32 %51, %52
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %49, %45
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = trunc i32 %55 to i16
  %57 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %8, i32 0, i32 12
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [4 x ptr], ptr %57, i64 0, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i16, ptr %61, i64 %63
  store i16 %56, ptr %64, align 2, !tbaa !11
  br label %65

65:                                               ; preds = %54
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !9
  br label %42, !llvm.loop !13

68:                                               ; preds = %42
  store i32 65, ptr %4, align 4, !tbaa !9
  %69 = load i32, ptr %5, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = add nsw i32 %72, 64
  store i32 %73, ptr %4, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %71, %68
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = icmp ult i32 %75, %76
  br i1 %77, label %78, label %79

78:                                               ; preds = %74
  call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %8, i32 noundef -237) #5
  unreachable

79:                                               ; preds = %74
  %80 = load i32, ptr %4, align 4, !tbaa !9
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = sub i32 %81, %80
  store i32 %82, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !15

83:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  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
  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 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 = { 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 uwtable
declare dso_local noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523), i64 noundef, i1 noundef zeroext) local_unnamed_addr #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) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder15read_dqt_markerEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 16)
  %3 = icmp ult i32 %2, 2
  br i1 %3, label %4, label %5

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

5:                                                ; preds = %1
  %6 = add i32 %2, -2
  %.not31 = icmp eq i32 %6, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 376
  br label %10

8:                                                ; preds = %.split30.us
  %9 = sub i32 %.02132, %spec.select
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !5

10:                                               ; preds = %.lr.ph, %8
  %.02132 = phi i32 [ %6, %.lr.ph ], [ %9, %8 ]
  %11 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 8)
  %12 = and i32 %11, 15
  %13 = icmp ugt i32 %12, 3
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %10
  %16 = zext nneg i32 %12 to i64
  %17 = getelementptr inbounds [4 x ptr], ptr %7, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !7
  %.not25 = icmp eq ptr %18, null
  br i1 %.not25, label %19, label %21

19:                                               ; preds = %15
  %20 = tail call noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523) %0, i64 noundef 128, i1 noundef zeroext false)
  store ptr %20, ptr %17, align 8, !tbaa !7
  br label %21

21:                                               ; preds = %19, %15
  %.not27 = icmp ult i32 %11, 16
  br i1 %.not27, label %.split.us, label %.split

.split.us:                                        ; preds = %21, %.split.us
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.split.us ], [ 0, %21 ]
  %22 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 8)
  %23 = trunc i32 %22 to i16
  %24 = load ptr, ptr %17, align 8, !tbaa !7
  %25 = getelementptr inbounds i16, ptr %24, i64 %indvars.iv35
  store i16 %23, ptr %25, align 2, !tbaa !11
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next36, 64
  br i1 %exitcond38.not, label %.split30.us, label %.split.us, !llvm.loop !13

.split:                                           ; preds = %21, %.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.split ], [ 0, %21 ]
  %26 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 8)
  %27 = shl i32 %26, 8
  %28 = tail call noundef i32 @_ZN4jpgd12jpeg_decoder8get_bitsEi(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef 8)
  %29 = add i32 %28, %27
  %30 = trunc i32 %29 to i16
  %31 = load ptr, ptr %17, align 8, !tbaa !7
  %32 = getelementptr inbounds i16, ptr %31, i64 %indvars.iv
  store i16 %30, ptr %32, align 2, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 64
  br i1 %exitcond.not, label %.split30.us, label %.split, !llvm.loop !13

.split30.us:                                      ; preds = %.split, %.split.us
  %spec.select = phi i32 [ 65, %.split.us ], [ 129, %.split ]
  %33 = icmp ult i32 %.02132, %spec.select
  br i1 %33, label %34, label %8

34:                                               ; preds = %.split30.us
  tail call void @_ZN4jpgd12jpeg_decoder13stop_decodingENS_11jpgd_statusE(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef -237) #3
  unreachable

._crit_edge:                                      ; preds = %8, %5
  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 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 = { 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, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = distinct !{!13, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass