; LLVM IR from drohmer/cgp :: library/third_party/src/jpeg/jpge.ll (ZN4jpge12jpeg_encoder16process_scanlineEPKv)

; 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.jpge::jpeg_encoder" = type <{ ptr, %"struct.jpge::params", i8, [3 x i8], [3 x i8], i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x ptr], i8, [3 x i8], [64 x i32], [64 x i16], [2 x [64 x i32]], [4 x [256 x i32]], [4 x [256 x i8]], [4 x [17 x i8]], [4 x [256 x i8]], [4 x [256 x i32]], [3 x i32], [2048 x i8], [4 x i8], ptr, i32, i32, i32, i8, i8, [2 x i8] }>
%"struct.jpge::params" = type <{ i32, i32, i8, i8, [2 x i8] }>

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4jpge12jpeg_encoder20process_end_of_imageEv(ptr noundef nonnull align 8 dereferenceable(13494)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4jpge12jpeg_encoder8load_mcuEPKv(ptr noundef nonnull align 8 dereferenceable(13494), ptr noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4jpge12jpeg_encoder16process_scanlineEPKv(ptr noundef nonnull align 8 dereferenceable(13494) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8
  %7 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %6, i32 0, i32 35
  %8 = load i8, ptr %7, align 4, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = icmp slt i32 %9, 1
  br i1 %10, label %16, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %6, i32 0, i32 35
  %13 = load i8, ptr %12, align 4, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = icmp sgt i32 %14, 2
  br i1 %15, label %16, label %17

16:                                               ; preds = %11, %2
  store i1 false, ptr %3, align 1
  br label %35

17:                                               ; preds = %11
  %18 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %6, i32 0, i32 36
  %19 = load i8, ptr %18, align 1, !tbaa !15, !range !16, !noundef !17
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %31

21:                                               ; preds = %17
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %28, label %24

24:                                               ; preds = %21
  %25 = call noundef zeroext i1 @_ZN4jpge12jpeg_encoder20process_end_of_imageEv(ptr noundef nonnull align 8 dereferenceable(13494) %6)
  br i1 %25, label %27, label %26

26:                                               ; preds = %24
  store i1 false, ptr %3, align 1
  br label %35

27:                                               ; preds = %24
  br label %30

28:                                               ; preds = %21
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN4jpge12jpeg_encoder8load_mcuEPKv(ptr noundef nonnull align 8 dereferenceable(13494) %6, ptr noundef %29)
  br label %30

30:                                               ; preds = %28, %27
  br label %31

31:                                               ; preds = %30, %17
  %32 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %6, i32 0, i32 36
  %33 = load i8, ptr %32, align 1, !tbaa !15, !range !16, !noundef !17
  %34 = trunc i8 %33 to i1
  store i1 %34, ptr %3, align 1
  br label %35

35:                                               ; preds = %31, %26, %16
  %36 = load i1, ptr %3, align 1
  ret i1 %36
}

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

!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, !7, i64 13492}
!10 = !{!"_ZTSN4jpge12jpeg_encoderE", !6, i64 0, !11, i64 8, !7, i64 20, !7, i64 21, !7, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !7, i64 72, !7, i64 200, !7, i64 204, !7, i64 460, !7, i64 588, !7, i64 1100, !7, i64 5196, !7, i64 6220, !7, i64 6288, !7, i64 7312, !7, i64 11408, !7, i64 11420, !6, i64 13472, !12, i64 13480, !12, i64 13484, !12, i64 13488, !7, i64 13492, !14, i64 13493}
!11 = !{!"_ZTSN4jpge6paramsE", !12, i64 0, !13, i64 4, !14, i64 8, !14, i64 9}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSN4jpge13subsampling_tE", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!10, !14, i64 13493}
!16 = !{i8 0, i8 2}
!17 = !{}


; 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 noundef zeroext i1 @_ZN4jpge12jpeg_encoder20process_end_of_imageEv(ptr noundef nonnull align 8 dereferenceable(13494)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4jpge12jpeg_encoder16process_scanlineEPKv(ptr noundef nonnull align 8 dereferenceable(13494) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 13492
  %4 = load i8, ptr %3, align 4, !tbaa !5
  %5 = add i8 %4, -3
  %or.cond = icmp ult i8 %5, -2
  br i1 %or.cond, label %17, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 13493
  %8 = load i8, ptr %7, align 1, !tbaa !14, !range !15, !noundef !16
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %10, label %14

10:                                               ; preds = %6
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %11, label %13

11:                                               ; preds = %10
  %12 = tail call noundef zeroext i1 @_ZN4jpge12jpeg_encoder20process_end_of_imageEv(ptr noundef nonnull align 8 dereferenceable(13494) %0)
  br i1 %12, label %14, label %17

13:                                               ; preds = %10
  tail call void @_ZN4jpge12jpeg_encoder8load_mcuEPKv(ptr noundef nonnull align 8 dereferenceable(13494) %0, ptr noundef nonnull %1)
  br label %14

14:                                               ; preds = %13, %11, %6
  %15 = load i8, ptr %7, align 1, !tbaa !14, !range !15, !noundef !16
  %16 = trunc nuw i8 %15 to i1
  br label %17

17:                                               ; preds = %11, %2, %14
  %.0 = phi i1 [ %16, %14 ], [ false, %2 ], [ false, %11 ]
  ret i1 %.0
}

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

!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, !8, i64 13492}
!6 = !{!"_ZTSN4jpge12jpeg_encoderE", !7, i64 0, !10, i64 8, !8, i64 20, !8, i64 21, !8, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !8, i64 72, !8, i64 200, !8, i64 204, !8, i64 460, !8, i64 588, !8, i64 1100, !8, i64 5196, !8, i64 6220, !8, i64 6288, !8, i64 7312, !8, i64 11408, !8, i64 11420, !7, i64 13472, !11, i64 13480, !11, i64 13484, !11, i64 13488, !8, i64 13492, !13, i64 13493}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4jpge6paramsE", !11, i64 0, !12, i64 4, !13, i64 8, !13, i64 9}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_ZTSN4jpge13subsampling_tE", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !13, i64 13493}
!15 = !{i8 0, i8 2}
!16 = !{}


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