; LLVM IR from team-charls/charls :: src/jpeg_stream_reader.ll (ZN6charls18jpeg_stream_reader21read_next_marker_codeEv)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN6charls18jpeg_stream_reader21read_next_marker_codeEv(ptr noundef nonnull align 8 dereferenceable(192) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  %5 = call noundef zeroext i8 @_ZN6charls18jpeg_stream_reader17read_byte_checkedEv(ptr noundef nonnull align 8 dereferenceable(192) %4)
  store i8 %5, ptr %3, align 1, !tbaa !9
  %6 = load i8, ptr %3, align 1, !tbaa !9
  %7 = icmp ne i8 %6, -1
  %8 = xor i1 %7, true
  %9 = xor i1 %8, true
  %10 = zext i1 %9 to i64
  %11 = call i64 @llvm.expect.i64(i64 %10, i64 0)
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  call void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef 10) #5
  unreachable

14:                                               ; preds = %1
  br label %15

15:                                               ; preds = %17, %14
  %16 = call noundef zeroext i8 @_ZN6charls18jpeg_stream_reader17read_byte_checkedEv(ptr noundef nonnull align 8 dereferenceable(192) %4)
  store i8 %16, ptr %3, align 1, !tbaa !9
  br label %17

17:                                               ; preds = %15
  %18 = load i8, ptr %3, align 1, !tbaa !9
  %19 = icmp eq i8 %18, -1
  br i1 %19, label %15, label %20, !llvm.loop !10

20:                                               ; preds = %17
  %21 = load i8, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  ret i8 %21
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: mustprogress noinline noreturn uwtable
declare dso_local void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN6charls18jpeg_stream_reader17read_byte_checkedEv(ptr noundef nonnull align 8 dereferenceable(192)) #0 align 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { mustprogress noinline 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; 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
define dso_local noundef zeroext range(i8 0, -1) i8 @_ZN6charls18jpeg_stream_reader21read_next_marker_codeEv(ptr noundef nonnull align 8 dereferenceable(192) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef zeroext i8 @_ZN6charls18jpeg_stream_reader17read_byte_checkedEv(ptr noundef nonnull align 8 dereferenceable(192) %0)
  %.not = icmp eq i8 %2, -1
  br i1 %.not, label %.preheader, label %3, !prof !5

3:                                                ; preds = %1
  tail call void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef 10) #2
  unreachable

.preheader:                                       ; preds = %1, %.preheader
  %4 = tail call noundef zeroext i8 @_ZN6charls18jpeg_stream_reader17read_byte_checkedEv(ptr noundef nonnull align 8 dereferenceable(192) %0)
  %5 = icmp eq i8 %4, -1
  br i1 %5, label %.preheader, label %6, !llvm.loop !6

6:                                                ; preds = %.preheader
  ret i8 %4
}

; Function Attrs: mustprogress noinline noreturn uwtable
declare dso_local void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN6charls18jpeg_stream_reader17read_byte_checkedEv(ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #0 align 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 = { mustprogress noinline 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 = { 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 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}


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