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

; 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 uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder13load_next_rowEv(ptr noundef nonnull align 8 dereferenceable(13523)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder15decode_next_rowEv(ptr noundef nonnull align 8 dereferenceable(13523)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder8find_eoiEv(ptr noundef nonnull align 8 dereferenceable(13523)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4jpgd12jpeg_decoder19decode_next_mcu_rowEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 0
  %7 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %6, i64 0, i64 0
  %8 = call i32 @_setjmp(ptr noundef %7) #4
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  br label %52

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #5
  %12 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = and i32 %13, 1
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %26

16:                                               ; preds = %11
  %17 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 13
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = icmp eq i32 %18, 4
  br i1 %19, label %24, label %20

20:                                               ; preds = %16
  %21 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 13
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = icmp eq i32 %22, 3
  br label %24

24:                                               ; preds = %20, %16
  %25 = phi i1 [ true, %16 ], [ %23, %20 ]
  br label %26

26:                                               ; preds = %24, %11
  %27 = phi i1 [ false, %11 ], [ %25, %24 ]
  %28 = zext i1 %27 to i8
  store i8 %28, ptr %4, align 1, !tbaa !15
  %29 = load i8, ptr %4, align 1, !tbaa !15, !range !16, !noundef !17
  %30 = trunc i8 %29 to i1
  br i1 %30, label %31, label %35

31:                                               ; preds = %26
  %32 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 66
  %33 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 67
  call void @_ZSt4swapIPhENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS4_ESt18is_move_assignableIS4_EEE5valueEvE4typeERS4_SD_(ptr noundef nonnull align 8 dereferenceable(8) %32, ptr noundef nonnull align 8 dereferenceable(8) %33) #5
  %34 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 78
  store i8 1, ptr %34, align 2, !tbaa !18
  br label %35

35:                                               ; preds = %31, %26
  %36 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 7
  %37 = load i32, ptr %36, align 8, !tbaa !19
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  call void @_ZN4jpgd12jpeg_decoder13load_next_rowEv(ptr noundef nonnull align 8 dereferenceable(13523) %5)
  br label %41

40:                                               ; preds = %35
  call void @_ZN4jpgd12jpeg_decoder15decode_next_rowEv(ptr noundef nonnull align 8 dereferenceable(13523) %5)
  br label %41

41:                                               ; preds = %40, %39
  %42 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 36
  %43 = load i32, ptr %42, align 4, !tbaa !20
  %44 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 30
  %45 = load i32, ptr %44, align 8, !tbaa !21
  %46 = icmp sle i32 %43, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  call void @_ZN4jpgd12jpeg_decoder8find_eoiEv(ptr noundef nonnull align 8 dereferenceable(13523) %5)
  br label %48

48:                                               ; preds = %47, %41
  %49 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 30
  %50 = load i32, ptr %49, align 8, !tbaa !21
  %51 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 37
  store i32 %50, ptr %51, align 8, !tbaa !22
  store i32 0, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #5
  br label %52

52:                                               ; preds = %48, %10
  %53 = load i32, ptr %2, align 4
  ret i32 %53
}

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIPhENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS4_ESt18is_move_assignableIS4_EEE5valueEvE4typeERS4_SD_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind returns_twice "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 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 #4 = { nounwind returns_twice }
attributes #5 = { 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, !11, i64 200}
!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, !11, i64 408}
!15 = !{!13, !13, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !13, i64 13522}
!19 = !{!10, !11, i64 232}
!20 = !{!10, !11, i64 644}
!21 = !{!10, !11, i64 584}
!22 = !{!10, !11, i64 648}


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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder15decode_next_rowEv(ptr noundef nonnull align 8 dereferenceable(13523)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4jpgd12jpeg_decoder8find_eoiEv(ptr noundef nonnull align 8 dereferenceable(13523)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1, 1) i32 @_ZN4jpgd12jpeg_decoder19decode_next_mcu_rowEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) local_unnamed_addr #0 align 2 {
  %2 = call i32 @_setjmp(ptr noundef nonnull %0) #3
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %27

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 200
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = and i32 %5, 1
  %.not3 = icmp eq i32 %6, 0
  br i1 %.not3, label %.critedge, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 408
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %.off = add i32 %9, -3
  %switch = icmp ult i32 %.off, 2
  br i1 %switch, label %10, label %.critedge

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 9384
  %12 = getelementptr inbounds i8, ptr %0, i64 9392
  call void @_ZSt4swapIPhENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS4_ESt18is_move_assignableIS4_EEE5valueEvE4typeERS4_SD_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull align 8 dereferenceable(8) %12) #4
  %13 = getelementptr inbounds i8, ptr %0, i64 13522
  store i8 1, ptr %13, align 2, !tbaa !14
  br label %.critedge

.critedge:                                        ; preds = %7, %3, %10
  %14 = getelementptr inbounds i8, ptr %0, i64 232
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %.not4 = icmp eq i32 %15, 0
  br i1 %.not4, label %17, label %16

16:                                               ; preds = %.critedge
  call void @_ZN4jpgd12jpeg_decoder13load_next_rowEv(ptr noundef nonnull align 8 dereferenceable(13523) %0)
  br label %18

17:                                               ; preds = %.critedge
  call void @_ZN4jpgd12jpeg_decoder15decode_next_rowEv(ptr noundef nonnull align 8 dereferenceable(13523) %0)
  br label %18

18:                                               ; preds = %17, %16
  %19 = getelementptr inbounds i8, ptr %0, i64 644
  %20 = load i32, ptr %19, align 4, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 584
  %22 = load i32, ptr %21, align 8, !tbaa !17
  %.not5 = icmp sgt i32 %20, %22
  br i1 %.not5, label %24, label %23

23:                                               ; preds = %18
  call void @_ZN4jpgd12jpeg_decoder8find_eoiEv(ptr noundef nonnull align 8 dereferenceable(13523) %0)
  %.pre = load i32, ptr %21, align 8, !tbaa !17
  br label %24

24:                                               ; preds = %23, %18
  %25 = phi i32 [ %.pre, %23 ], [ %22, %18 ]
  %26 = getelementptr inbounds i8, ptr %0, i64 648
  store i32 %25, ptr %26, align 8, !tbaa !18
  br label %27

27:                                               ; preds = %1, %24
  %.0 = phi i32 [ 0, %24 ], [ -1, %1 ]
  ret i32 %.0
}

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIPhENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS4_ESt18is_move_assignableIS4_EEE5valueEvE4typeERS4_SD_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 = { nounwind returns_twice "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 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 returns_twice }
attributes #4 = { 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, !9, i64 200}
!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, !9, i64 408}
!14 = !{!6, !12, i64 13522}
!15 = !{!6, !9, i64 232}
!16 = !{!6, !9, i64 644}
!17 = !{!6, !9, i64 584}
!18 = !{!6, !9, i64 648}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass