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

; 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_dqtEv(ptr noundef nonnull align 8 dereferenceable(13494) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %38, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %6, i32 0, i32 2
  %10 = load i8, ptr %9, align 4, !tbaa !11
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 3
  %13 = zext i1 %12 to i64
  %14 = select i1 %12, i32 2, i32 1
  %15 = icmp slt i32 %8, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %7
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %41

17:                                               ; preds = %7
  call void @_ZN4jpge12jpeg_encoder11emit_markerEi(ptr noundef nonnull align 8 dereferenceable(13494) %6, i32 noundef 219)
  call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %6, i32 noundef 67)
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = trunc i32 %18 to i8
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %6, i8 noundef zeroext %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %34, %17
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 64
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %37

24:                                               ; preds = %20
  %25 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %6, i32 0, i32 22
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2 x [64 x i32]], ptr %25, i64 0, i64 %27
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [64 x i32], ptr %28, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = trunc i32 %32 to i8
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %6, i8 noundef zeroext %33)
  br label %34

34:                                               ; preds = %24
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %5, align 4, !tbaa !9
  br label %20, !llvm.loop !16

37:                                               ; preds = %23
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !18

41:                                               ; preds = %16
  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, !7, i64 20}
!12 = !{!"_ZTSN4jpge12jpeg_encoderE", !6, i64 0, !13, i64 8, !7, i64 20, !7, i64 21, !7, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, 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, !10, i64 13480, !10, i64 13484, !10, i64 13488, !7, i64 13492, !15, i64 13493}
!13 = !{!"_ZTSN4jpge6paramsE", !10, i64 0, !14, i64 4, !15, i64 8, !15, i64 9}
!14 = !{!"_ZTSN4jpge13subsampling_tE", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !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 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_dqtEv(ptr noundef nonnull align 8 dereferenceable(13494) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = getelementptr inbounds i8, ptr %0, i64 588
  br label %5

4:                                                ; preds = %8
  ret void

5:                                                ; preds = %1, %8
  %6 = phi i1 [ true, %1 ], [ false, %8 ]
  %indvars.iv11 = phi i64 [ 0, %1 ], [ 1, %8 ]
  tail call void @_ZN4jpge12jpeg_encoder11emit_markerEi(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef 219)
  tail call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef 67)
  %7 = trunc nuw nsw i64 %indvars.iv11 to i8
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %7)
  br label %12

8:                                                ; preds = %12
  %9 = load i8, ptr %2, align 4, !tbaa !5
  %10 = icmp eq i8 %9, 3
  %11 = and i1 %10, %6
  br i1 %11, label %5, label %4, !llvm.loop !14

12:                                               ; preds = %5, %12
  %indvars.iv = phi i64 [ 0, %5 ], [ %indvars.iv.next, %12 ]
  %13 = getelementptr inbounds [2 x [64 x i32]], ptr %3, i64 0, i64 %indvars.iv11, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !16
  %15 = trunc i32 %14 to i8
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %15)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 64
  br i1 %exitcond.not, label %8, label %12, !llvm.loop !17
}

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}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !15}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass