; LLVM IR from Razakhel/RaZ :: extern/simdjson/simdjson.ll (ZN8simdjson8internal18decimal_left_shiftERNS0_7decimalEj)

; 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"

%"struct.simdjson::internal::decimal" = type { i32, i32, i8, i8, [768 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
define dso_local void @_ZN8simdjson8internal18decimal_left_shiftERNS0_7decimalEj(ptr noundef nonnull align 4 dereferenceable(780) %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  br label %129

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = call noundef i32 @_ZN8simdjson8internal12_GLOBAL__N_135number_of_digits_decimal_left_shiftERNS0_7decimalEj(ptr noundef nonnull align 4 dereferenceable(780) %19, i32 noundef %20)
  store i32 %21, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = sub i32 %24, 1
  store i32 %25, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = sub i32 %28, 1
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = add i32 %29, %30
  store i32 %31, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !14
  br label %32

32:                                               ; preds = %71, %18
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp sge i32 %33, 0
  br i1 %34, label %35, label %77

35:                                               ; preds = %32
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %36, i32 0, i32 4
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [768 x i8], ptr %37, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !16
  %42 = zext i8 %41 to i64
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = shl i64 %42, %44
  %46 = load i64, ptr %8, align 8, !tbaa !14
  %47 = add i64 %46, %45
  store i64 %47, ptr %8, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %48 = load i64, ptr %8, align 8, !tbaa !14
  %49 = udiv i64 %48, 10
  store i64 %49, ptr %9, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %50 = load i64, ptr %8, align 8, !tbaa !14
  %51 = load i64, ptr %9, align 8, !tbaa !14
  %52 = mul i64 10, %51
  %53 = sub i64 %50, %52
  store i64 %53, ptr %10, align 8, !tbaa !14
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = icmp ult i32 %54, 768
  br i1 %55, label %56, label %64

56:                                               ; preds = %35
  %57 = load i64, ptr %10, align 8, !tbaa !14
  %58 = trunc i64 %57 to i8
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %59, i32 0, i32 4
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds [768 x i8], ptr %60, i64 0, i64 %62
  store i8 %58, ptr %63, align 1, !tbaa !16
  br label %71

64:                                               ; preds = %35
  %65 = load i64, ptr %10, align 8, !tbaa !14
  %66 = icmp ugt i64 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %68, i32 0, i32 3
  store i8 1, ptr %69, align 1, !tbaa !17
  br label %70

70:                                               ; preds = %67, %64
  br label %71

71:                                               ; preds = %70, %56
  %72 = load i64, ptr %9, align 8, !tbaa !14
  store i64 %72, ptr %8, align 8, !tbaa !14
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = add i32 %73, -1
  store i32 %74, ptr %7, align 4, !tbaa !9
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %32, !llvm.loop !18

77:                                               ; preds = %32
  br label %78

78:                                               ; preds = %105, %77
  %79 = load i64, ptr %8, align 8, !tbaa !14
  %80 = icmp ugt i64 %79, 0
  br i1 %80, label %81, label %109

81:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %82 = load i64, ptr %8, align 8, !tbaa !14
  %83 = udiv i64 %82, 10
  store i64 %83, ptr %11, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %84 = load i64, ptr %8, align 8, !tbaa !14
  %85 = load i64, ptr %11, align 8, !tbaa !14
  %86 = mul i64 10, %85
  %87 = sub i64 %84, %86
  store i64 %87, ptr %12, align 8, !tbaa !14
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = icmp ult i32 %88, 768
  br i1 %89, label %90, label %98

90:                                               ; preds = %81
  %91 = load i64, ptr %12, align 8, !tbaa !14
  %92 = trunc i64 %91 to i8
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %93, i32 0, i32 4
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = zext i32 %95 to i64
  %97 = getelementptr inbounds [768 x i8], ptr %94, i64 0, i64 %96
  store i8 %92, ptr %97, align 1, !tbaa !16
  br label %105

98:                                               ; preds = %81
  %99 = load i64, ptr %12, align 8, !tbaa !14
  %100 = icmp ugt i64 %99, 0
  br i1 %100, label %101, label %104

101:                                              ; preds = %98
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  %103 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %102, i32 0, i32 3
  store i8 1, ptr %103, align 1, !tbaa !17
  br label %104

104:                                              ; preds = %101, %98
  br label %105

105:                                              ; preds = %104, %90
  %106 = load i64, ptr %11, align 8, !tbaa !14
  store i64 %106, ptr %8, align 8, !tbaa !14
  %107 = load i32, ptr %7, align 4, !tbaa !9
  %108 = add i32 %107, -1
  store i32 %108, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %78, !llvm.loop !20

109:                                              ; preds = %78
  %110 = load i32, ptr %5, align 4, !tbaa !9
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %111, i32 0, i32 0
  %113 = load i32, ptr %112, align 4, !tbaa !11
  %114 = add i32 %113, %110
  store i32 %114, ptr %112, align 4, !tbaa !11
  %115 = load ptr, ptr %3, align 8, !tbaa !5
  %116 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %115, i32 0, i32 0
  %117 = load i32, ptr %116, align 4, !tbaa !11
  %118 = icmp ugt i32 %117, 768
  br i1 %118, label %119, label %122

119:                                              ; preds = %109
  %120 = load ptr, ptr %3, align 8, !tbaa !5
  %121 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %120, i32 0, i32 0
  store i32 768, ptr %121, align 4, !tbaa !11
  br label %122

122:                                              ; preds = %119, %109
  %123 = load i32, ptr %5, align 4, !tbaa !9
  %124 = load ptr, ptr %3, align 8, !tbaa !5
  %125 = getelementptr inbounds %"struct.simdjson::internal::decimal", ptr %124, i32 0, i32 1
  %126 = load i32, ptr %125, align 4, !tbaa !21
  %127 = add nsw i32 %126, %123
  store i32 %127, ptr %125, align 4, !tbaa !21
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN8simdjson8internal12_GLOBAL__N_14trimERNS0_7decimalE(ptr noundef nonnull align 4 dereferenceable(780) %128)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %129

129:                                              ; preds = %122, %17
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN8simdjson8internal12_GLOBAL__N_135number_of_digits_decimal_left_shiftERNS0_7decimalEj(ptr noundef nonnull align 4 dereferenceable(780), i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZN8simdjson8internal12_GLOBAL__N_14trimERNS0_7decimalE(ptr noundef nonnull align 4 dereferenceable(780)) #3

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 = { mustprogress nounwind 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 = { inlinehint mustprogress nounwind 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 #4 = { 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, !10, i64 0}
!12 = !{!"_ZTSN8simdjson8internal7decimalE", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 9, !7, i64 10}
!13 = !{!"bool", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!12, !13, i64 9}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{!12, !10, i64 4}


; 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 nounwind uwtable
define dso_local void @_ZN8simdjson8internal18decimal_left_shiftERNS0_7decimalEj(ptr noundef nonnull align 4 dereferenceable(780) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %51, label %5

5:                                                ; preds = %2
  %6 = tail call noundef i32 @_ZN8simdjson8internal12_GLOBAL__N_135number_of_digits_decimal_left_shiftERNS0_7decimalEj(ptr noundef nonnull align 4 dereferenceable(780) %0, i32 noundef %1)
  %7 = load i32, ptr %0, align 4, !tbaa !5
  %8 = add i32 %7, -1
  %9 = icmp sgt i32 %8, -1
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %10 = add i32 %8, %6
  %11 = getelementptr inbounds i8, ptr %0, i64 10
  %12 = zext nneg i32 %1 to i64
  %13 = getelementptr inbounds i8, ptr %0, i64 9
  %14 = zext nneg i32 %8 to i64
  br label %17

.preheader:                                       ; preds = %32
  %.not51 = icmp ult i64 %22, 10
  br i1 %.not51, label %._crit_edge, label %.lr.ph54

.lr.ph54:                                         ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %0, i64 9
  %16 = getelementptr inbounds i8, ptr %0, i64 10
  br label %35

17:                                               ; preds = %.lr.ph, %32
  %indvars.iv = phi i64 [ %14, %.lr.ph ], [ %indvars.iv.next, %32 ]
  %.04148 = phi i32 [ %10, %.lr.ph ], [ %33, %32 ]
  %.04247 = phi i64 [ 0, %.lr.ph ], [ %23, %32 ]
  %18 = getelementptr inbounds [768 x i8], ptr %11, i64 0, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = zext i8 %19 to i64
  %21 = shl i64 %20, %12
  %22 = add i64 %21, %.04247
  %23 = udiv i64 %22, 10
  %.neg45 = mul i64 %23, -10
  %24 = add i64 %.neg45, %22
  %25 = icmp ult i32 %.04148, 768
  br i1 %25, label %26, label %30

26:                                               ; preds = %17
  %27 = trunc i64 %24 to i8
  %28 = zext nneg i32 %.04148 to i64
  %29 = getelementptr inbounds [768 x i8], ptr %11, i64 0, i64 %28
  store i8 %27, ptr %29, align 1, !tbaa !11
  br label %32

30:                                               ; preds = %17
  %.not46 = icmp eq i64 %24, 0
  br i1 %.not46, label %32, label %31

31:                                               ; preds = %30
  store i8 1, ptr %13, align 1, !tbaa !12
  br label %32

32:                                               ; preds = %30, %31, %26
  %33 = add i32 %.04148, -1
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %34 = icmp sgt i64 %indvars.iv, 0
  br i1 %34, label %17, label %.preheader, !llvm.loop !13

35:                                               ; preds = %.lr.ph54, %45
  %.153 = phi i32 [ %33, %.lr.ph54 ], [ %46, %45 ]
  %.14352 = phi i64 [ %23, %.lr.ph54 ], [ %36, %45 ]
  %36 = udiv i64 %.14352, 10
  %.neg = mul nsw i64 %36, -10
  %37 = add nsw i64 %.neg, %.14352
  %38 = icmp ult i32 %.153, 768
  br i1 %38, label %39, label %43

39:                                               ; preds = %35
  %40 = trunc i64 %37 to i8
  %41 = zext nneg i32 %.153 to i64
  %42 = getelementptr inbounds [768 x i8], ptr %16, i64 0, i64 %41
  store i8 %40, ptr %42, align 1, !tbaa !11
  br label %45

43:                                               ; preds = %35
  %.not44 = icmp eq i64 %37, 0
  br i1 %.not44, label %45, label %44

44:                                               ; preds = %43
  store i8 1, ptr %15, align 1, !tbaa !12
  br label %45

45:                                               ; preds = %43, %44, %39
  %46 = add i32 %.153, -1
  %.not = icmp ult i64 %.14352, 10
  br i1 %.not, label %._crit_edge, label %35, !llvm.loop !15

._crit_edge:                                      ; preds = %45, %5, %.preheader
  %47 = add i32 %7, %6
  %spec.select = tail call i32 @llvm.umin.i32(i32 %47, i32 768)
  store i32 %spec.select, ptr %0, align 4, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %0, i64 4
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = add nsw i32 %49, %6
  store i32 %50, ptr %48, align 4, !tbaa !16
  tail call void @_ZN8simdjson8internal12_GLOBAL__N_14trimERNS0_7decimalE(ptr noundef nonnull align 4 dereferenceable(780) %0)
  br label %51

51:                                               ; preds = %2, %._crit_edge
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN8simdjson8internal12_GLOBAL__N_135number_of_digits_decimal_left_shiftERNS0_7decimalEj(ptr noundef nonnull align 4 dereferenceable(780), i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZN8simdjson8internal12_GLOBAL__N_14trimERNS0_7decimalE(ptr noundef nonnull align 4 dereferenceable(780)) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

attributes #0 = { mustprogress nounwind 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 = { inlinehint mustprogress nounwind 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN8simdjson8internal7decimalE", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 9, !8, i64 10}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!6, !10, i64 9}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!6, !7, i64 4}


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