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

; 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: mustprogress uwtable
declare dso_local void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494), i8 noundef zeroext) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpge12jpeg_encoder8emit_sosEv(ptr noundef nonnull align 8 dereferenceable(13494) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @_ZN4jpge12jpeg_encoder11emit_markerEi(ptr noundef nonnull align 8 dereferenceable(13494) %4, i32 noundef 218)
  %5 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 2
  %6 = load i8, ptr %5, align 4, !tbaa !9
  %7 = zext i8 %6 to i32
  %8 = mul nsw i32 2, %7
  %9 = add nsw i32 %8, 2
  %10 = add nsw i32 %9, 1
  %11 = add nsw i32 %10, 3
  call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %4, i32 noundef %11)
  %12 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 2
  %13 = load i8, ptr %12, align 4, !tbaa !9
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %14

14:                                               ; preds = %30, %1
  %15 = load i32, ptr %3, align 4, !tbaa !15
  %16 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 2
  %17 = load i8, ptr %16, align 4, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %33

21:                                               ; preds = %14
  %22 = load i32, ptr %3, align 4, !tbaa !15
  %23 = add nsw i32 %22, 1
  %24 = trunc i32 %23 to i8
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext %24)
  %25 = load i32, ptr %3, align 4, !tbaa !15
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext 0)
  br label %29

28:                                               ; preds = %21
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext 17)
  br label %29

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

30:                                               ; preds = %29
  %31 = load i32, ptr %3, align 4, !tbaa !15
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !15
  br label %14, !llvm.loop !16

33:                                               ; preds = %20
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext 0)
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext 63)
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext 0)
  ret void
}

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 }

!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 20}
!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 = distinct !{!16, !17}
!17 = !{!"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
declare dso_local void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494), i8 noundef zeroext) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpge12jpeg_encoder8emit_sosEv(ptr noundef nonnull align 8 dereferenceable(13494) %0) local_unnamed_addr #0 align 2 {
  tail call void @_ZN4jpge12jpeg_encoder11emit_markerEi(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef 218)
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = load i8, ptr %2, align 4, !tbaa !5
  %4 = zext i8 %3 to i32
  %5 = shl nuw nsw i32 %4, 1
  %6 = add nuw nsw i32 %5, 6
  tail call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef %6)
  %7 = load i8, ptr %2, align 4, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %7)
  %8 = load i8, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %._crit_edge, label %9

9:                                                ; preds = %1
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext 1)
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext 0)
  %.pre = load i8, ptr %2, align 4, !tbaa !5
  %10 = icmp ugt i8 %.pre, 1
  br i1 %10, label %.lr.ph.peel.next, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.peel.next, %9, %1
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext 0)
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext 63)
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext 0)
  ret void

.lr.ph.peel.next:                                 ; preds = %9, %.lr.ph.peel.next
  %.04 = phi i32 [ %11, %.lr.ph.peel.next ], [ 1, %9 ]
  %11 = add nuw nsw i32 %.04, 1
  %12 = trunc i32 %11 to i8
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %12)
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext 17)
  %.pre6 = load i8, ptr %2, align 4, !tbaa !5
  %13 = zext i8 %.pre6 to i32
  %14 = icmp ult i32 %11, %13
  br i1 %14, label %.lr.ph.peel.next, label %._crit_edge, !llvm.loop !14
}

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 20}
!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 = distinct !{!14, !15, !16}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass