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

; 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: 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_dhtEPhS1_ib(ptr noundef nonnull align 8 dereferenceable(13494) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i1 noundef zeroext %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %15 = zext i1 %4 to i8
  store i8 %15, ptr %10, align 1, !tbaa !11
  %16 = load ptr, ptr %6, align 8
  call void @_ZN4jpge12jpeg_encoder11emit_markerEi(ptr noundef nonnull align 8 dereferenceable(13494) %16, i32 noundef 196)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %30, %5
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = icmp sle i32 %18, 16
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %17
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %27 = zext i8 %26 to i32
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = add nsw i32 %28, %27
  store i32 %29, ptr %11, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %21
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %12, align 4, !tbaa !9
  br label %17, !llvm.loop !14

33:                                               ; preds = %20
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = add nsw i32 %34, 2
  %36 = add nsw i32 %35, 1
  %37 = add nsw i32 %36, 16
  call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %16, i32 noundef %37)
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = load i8, ptr %10, align 1, !tbaa !11, !range !16, !noundef !17
  %40 = trunc i8 %39 to i1
  %41 = zext i1 %40 to i32
  %42 = shl i32 %41, 4
  %43 = add nsw i32 %38, %42
  %44 = trunc i32 %43 to i8
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %16, i8 noundef zeroext %44)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %55, %33
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = icmp sle i32 %46, 16
  br i1 %47, label %49, label %48

48:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %58

49:                                               ; preds = %45
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !13
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %16, i8 noundef zeroext %54)
  br label %55

55:                                               ; preds = %49
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %13, align 4, !tbaa !9
  br label %45, !llvm.loop !18

58:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %70, %58
  %60 = load i32, ptr %14, align 4, !tbaa !9
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %64, label %63

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

64:                                               ; preds = %59
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i8, ptr %65, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !13
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %16, i8 noundef zeroext %69)
  br label %70

70:                                               ; preds = %64
  %71 = load i32, ptr %14, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %14, align 4, !tbaa !9
  br label %59, !llvm.loop !19

73:                                               ; preds = %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !15}
!19 = distinct !{!19, !15}


; 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_dhtEPhS1_ib(ptr noundef nonnull align 8 dereferenceable(13494) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3, i1 noundef zeroext %4) local_unnamed_addr #0 align 2 {
.preheader:
  tail call void @_ZN4jpge12jpeg_encoder11emit_markerEi(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef 196)
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  %6 = getelementptr inbounds i8, ptr %1, i64 2
  %7 = getelementptr inbounds i8, ptr %1, i64 3
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = getelementptr inbounds i8, ptr %1, i64 5
  %10 = getelementptr inbounds i8, ptr %1, i64 6
  %11 = getelementptr inbounds i8, ptr %1, i64 7
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = getelementptr inbounds i8, ptr %1, i64 9
  %14 = getelementptr inbounds i8, ptr %1, i64 10
  %15 = getelementptr inbounds i8, ptr %1, i64 11
  %16 = getelementptr inbounds i8, ptr %1, i64 12
  %17 = getelementptr inbounds i8, ptr %1, i64 13
  %18 = getelementptr inbounds i8, ptr %1, i64 14
  %19 = getelementptr inbounds i8, ptr %1, i64 15
  %20 = getelementptr inbounds i8, ptr %1, i64 16
  %21 = load <16 x i8>, ptr %5, align 1, !tbaa !5
  %22 = zext <16 x i8> %21 to <16 x i32>
  %23 = tail call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %22)
  %24 = add nuw nsw i32 %23, 19
  tail call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef %24)
  %25 = select i1 %4, i32 16, i32 0
  %26 = add nsw i32 %25, %3
  %27 = trunc i32 %26 to i8
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %27)
  %28 = load i8, ptr %5, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %28)
  %29 = load i8, ptr %6, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %29)
  %30 = load i8, ptr %7, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %30)
  %31 = load i8, ptr %8, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %31)
  %32 = load i8, ptr %9, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %32)
  %33 = load i8, ptr %10, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %33)
  %34 = load i8, ptr %11, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %34)
  %35 = load i8, ptr %12, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %35)
  %36 = load i8, ptr %13, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %36)
  %37 = load i8, ptr %14, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %37)
  %38 = load i8, ptr %15, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %38)
  %39 = load i8, ptr %16, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %39)
  %40 = load i8, ptr %17, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %40)
  %41 = load i8, ptr %18, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %41)
  %42 = load i8, ptr %19, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %42)
  %43 = load i8, ptr %20, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %43)
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %44 = zext nneg i32 %23 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %45 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %46 = load i8, ptr %45, align 1, !tbaa !5
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %46)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %47 = icmp ult i64 %indvars.iv.next, %44
  br i1 %47, label %.lr.ph, label %._crit_edge, !llvm.loop !8
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v16i32(<16 x i32>) #1

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 speculatable willreturn memory(none) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass