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

; 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_sofEv(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 192)
  %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 3, %7
  %9 = add nsw i32 %8, 2
  %10 = add nsw i32 %9, 5
  %11 = add nsw i32 %10, 1
  call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %4, i32 noundef %11)
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext 8)
  %12 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 7
  %13 = load i32, ptr %12, align 8, !tbaa !15
  call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %4, i32 noundef %13)
  %14 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 6
  %15 = load i32, ptr %14, align 4, !tbaa !16
  call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %4, i32 noundef %15)
  %16 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 2
  %17 = load i8, ptr %16, align 4, !tbaa !9
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext %17)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !17
  br label %18

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

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

25:                                               ; preds = %18
  %26 = load i32, ptr %3, align 4, !tbaa !17
  %27 = add nsw i32 %26, 1
  %28 = trunc i32 %27 to i8
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext %28)
  %29 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 3
  %30 = load i32, ptr %3, align 4, !tbaa !17
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [3 x i8], ptr %29, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !18
  %34 = zext i8 %33 to i32
  %35 = shl i32 %34, 4
  %36 = getelementptr inbounds %"class.jpge::jpeg_encoder", ptr %4, i32 0, i32 4
  %37 = load i32, ptr %3, align 4, !tbaa !17
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [3 x i8], ptr %36, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !18
  %41 = zext i8 %40 to i32
  %42 = add nsw i32 %35, %41
  %43 = trunc i32 %42 to i8
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext %43)
  %44 = load i32, ptr %3, align 4, !tbaa !17
  %45 = icmp sgt i32 %44, 0
  %46 = zext i1 %45 to i8
  call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %4, i8 noundef zeroext %46)
  br label %47

47:                                               ; preds = %25
  %48 = load i32, ptr %3, align 4, !tbaa !17
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %3, align 4, !tbaa !17
  br label %18, !llvm.loop !19

50:                                               ; preds = %24
  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 = !{!10, !12, i64 32}
!16 = !{!10, !12, i64 28}
!17 = !{!12, !12, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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_sofEv(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 192)
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = load i8, ptr %2, align 4, !tbaa !5
  %4 = zext i8 %3 to i32
  %5 = mul nuw nsw i32 %4, 3
  %6 = add nuw nsw i32 %5, 8
  tail call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef %6)
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext 8)
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load i32, ptr %7, align 8, !tbaa !14
  tail call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef %8)
  %9 = getelementptr inbounds i8, ptr %0, i64 28
  %10 = load i32, ptr %9, align 4, !tbaa !15
  tail call void @_ZN4jpge12jpeg_encoder9emit_wordEj(ptr noundef nonnull align 8 dereferenceable(13494) %0, i32 noundef %10)
  %11 = 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 %11)
  %12 = load i8, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i8 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %13 = getelementptr inbounds i8, ptr %0, i64 21
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  br label %15

._crit_edge:                                      ; preds = %15, %1
  ret void

15:                                               ; preds = %.lr.ph, %15
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = trunc nuw i64 %indvars.iv.next to i8
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %16)
  %17 = getelementptr inbounds [3 x i8], ptr %13, i64 0, i64 %indvars.iv
  %18 = load i8, ptr %17, align 1, !tbaa !16
  %19 = shl i8 %18, 4
  %20 = getelementptr inbounds [3 x i8], ptr %14, i64 0, i64 %indvars.iv
  %21 = load i8, ptr %20, align 1, !tbaa !16
  %22 = add i8 %19, %21
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %22)
  %23 = icmp ne i64 %indvars.iv, 0
  %24 = zext i1 %23 to i8
  tail call void @_ZN4jpge12jpeg_encoder9emit_byteEh(ptr noundef nonnull align 8 dereferenceable(13494) %0, i8 noundef zeroext %24)
  %25 = load i8, ptr %2, align 4, !tbaa !5
  %26 = zext i8 %25 to i64
  %27 = icmp ult i64 %indvars.iv.next, %26
  br i1 %27, label %15, label %._crit_edge, !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 = !{!6, !11, i64 32}
!15 = !{!6, !11, i64 28}
!16 = !{!8, !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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