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

; 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: 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

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

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

9:                                                ; preds = %1
  %10 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 18
  %11 = load i8, ptr %10, align 8, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp slt i32 %12, 16
  br i1 %13, label %14, label %45

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %15 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 18
  %16 = load i8, ptr %15, align 8, !tbaa !9
  %17 = zext i8 %16 to i32
  store i32 %17, ptr %4, align 4, !tbaa !15
  br label %18

18:                                               ; preds = %41, %14
  %19 = load i32, ptr %4, align 4, !tbaa !15
  %20 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 16
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %44

24:                                               ; preds = %18
  %25 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 17
  %26 = load i32, ptr %4, align 4, !tbaa !15
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [16 x ptr], ptr %25, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 17
  %31 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 18
  %32 = load i8, ptr %31, align 8, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [16 x ptr], ptr %30, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 13
  %39 = load i32, ptr %38, align 8, !tbaa !17
  %40 = sext i32 %39 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %29, ptr align 1 %37, i64 %40, i1 false)
  br label %41

41:                                               ; preds = %24
  %42 = load i32, ptr %4, align 4, !tbaa !15
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !15
  br label %18, !llvm.loop !18

44:                                               ; preds = %23
  br label %45

45:                                               ; preds = %44, %9
  call void @_ZN4jpge12jpeg_encoder15process_mcu_rowEv(ptr noundef nonnull align 8 dereferenceable(13494) %5)
  br label %46

46:                                               ; preds = %45, %1
  %47 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %5, i32 0, i32 35
  %48 = load i8, ptr %47, align 4, !tbaa !20
  %49 = zext i8 %48 to i32
  %50 = icmp eq i32 %49, 1
  br i1 %50, label %51, label %53

51:                                               ; preds = %46
  %52 = call noundef zeroext i1 @_ZN4jpge12jpeg_encoder18terminate_pass_oneEv(ptr noundef nonnull align 8 dereferenceable(13494) %5)
  store i1 %52, ptr %2, align 1
  br label %55

53:                                               ; preds = %46
  %54 = call noundef zeroext i1 @_ZN4jpge12jpeg_encoder18terminate_pass_twoEv(ptr noundef nonnull align 8 dereferenceable(13494) %5)
  store i1 %54, ptr %2, align 1
  br label %55

55:                                               ; preds = %53, %51
  %56 = load i1, ptr %2, align 1
  ret i1 %56
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !7, i64 200}
!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 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 68}
!17 = !{!10, !12, i64 56}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !7, i64 13492}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4jpge12jpeg_encoder20process_end_of_imageEv(ptr noundef nonnull align 8 dereferenceable(13494) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 200
  %3 = load i8, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %27, label %4

4:                                                ; preds = %1
  %5 = icmp ult i8 %3, 16
  br i1 %5, label %6, label %.loopexit

6:                                                ; preds = %4
  %7 = zext nneg i8 %3 to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 68
  %9 = load i32, ptr %8, align 4, !tbaa !14
  %10 = icmp sgt i32 %9, %7
  br i1 %10, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 72
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = zext nneg i8 %3 to i64
  br label %14

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ %13, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %15 = getelementptr inbounds [16 x ptr], ptr %11, i64 0, i64 %indvars.iv
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = load i8, ptr %2, align 8, !tbaa !5
  %18 = zext i8 %17 to i64
  %19 = add nsw i64 %18, -1
  %20 = getelementptr inbounds [16 x ptr], ptr %11, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load i32, ptr %12, align 8, !tbaa !16
  %23 = sext i32 %22 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %16, ptr align 1 %21, i64 %23, i1 false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load i32, ptr %8, align 4, !tbaa !14
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next, %25
  br i1 %26, label %14, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %14, %6, %4
  tail call void @_ZN4jpge12jpeg_encoder15process_mcu_rowEv(ptr noundef nonnull align 8 dereferenceable(13494) %0)
  br label %27

27:                                               ; preds = %.loopexit, %1
  %28 = getelementptr inbounds i8, ptr %0, i64 13492
  %29 = load i8, ptr %28, align 4, !tbaa !19
  %30 = icmp eq i8 %29, 1
  br i1 %30, label %31, label %33

31:                                               ; preds = %27
  %32 = tail call noundef zeroext i1 @_ZN4jpge12jpeg_encoder18terminate_pass_oneEv(ptr noundef nonnull align 8 dereferenceable(13494) %0)
  br label %35

33:                                               ; preds = %27
  %34 = tail call noundef zeroext i1 @_ZN4jpge12jpeg_encoder18terminate_pass_twoEv(ptr noundef nonnull align 8 dereferenceable(13494) %0)
  br label %35

35:                                               ; preds = %33, %31
  %.04 = phi i1 [ %32, %31 ], [ %34, %33 ]
  ret i1 %.04
}

attributes #0 = { mustprogress nocallback nofree 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" }

!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 200}
!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, !11, i64 68}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !11, i64 56}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !8, i64 13492}


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