; LLVM IR from microsoft/LightAIMD :: src (json)

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

@.str = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @json_unescape_string(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %51, %49, %3
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %15, label %52

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = add i64 %17, 1
  store i64 %18, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds i32, ptr %16, i64 %17
  %20 = load i32, ptr %19, align 4, !tbaa !11
  store i32 %20, ptr %9, align 4, !tbaa !11
  %21 = load i32, ptr %9, align 4, !tbaa !11
  %22 = icmp ne i32 %21, 92
  br i1 %22, label %23, label %29

23:                                               ; preds = %15
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = add i64 %26, 1
  store i64 %27, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds i32, ptr %25, i64 %26
  store i32 %24, ptr %28, align 4, !tbaa !11
  store i32 2, ptr %10, align 4
  br label %49, !llvm.loop !13

29:                                               ; preds = %15
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = add i64 %31, 1
  store i64 %32, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds i32, ptr %30, i64 %31
  %34 = load i32, ptr %33, align 4, !tbaa !11
  store i32 %34, ptr %9, align 4, !tbaa !11
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = icmp eq i32 %35, 34
  br i1 %36, label %40, label %37

37:                                               ; preds = %29
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = icmp eq i32 %38, 92
  br i1 %39, label %40, label %46

40:                                               ; preds = %37, %29
  %41 = load i32, ptr %9, align 4, !tbaa !11
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = add i64 %43, 1
  store i64 %44, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds i32, ptr %42, i64 %43
  store i32 %41, ptr %45, align 4, !tbaa !11
  store i32 2, ptr %10, align 4
  br label %49, !llvm.loop !13

46:                                               ; preds = %37
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %48

48:                                               ; preds = %46
  store i32 0, ptr %10, align 4
  br label %49

49:                                               ; preds = %48, %40, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %50 = load i32, ptr %10, align 4
  switch i32 %50, label %54 [
    i32 0, label %51
    i32 2, label %11
  ]

51:                                               ; preds = %49
  br label %11, !llvm.loop !13

52:                                               ; preds = %11
  %53 = load i64, ptr %8, align 8, !tbaa !9
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %53

54:                                               ; preds = %49
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@.str = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local i64 @json_unescape_string(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %.not21 = icmp eq i64 %1, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %19
  %.020 = phi i64 [ %.1, %19 ], [ 0, %3 ]
  %.01619 = phi i64 [ %.117, %19 ], [ 0, %3 ]
  %4 = add nuw i64 %.01619, 1
  %5 = getelementptr inbounds i32, ptr %0, i64 %.01619
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 92
  br i1 %.not, label %10, label %7

7:                                                ; preds = %.lr.ph
  %8 = add i64 %.020, 1
  %9 = getelementptr inbounds i32, ptr %2, i64 %.020
  store i32 %6, ptr %9, align 4, !tbaa !5
  br label %19, !llvm.loop !9

10:                                               ; preds = %.lr.ph
  %11 = add i64 %.01619, 2
  %12 = getelementptr inbounds i32, ptr %0, i64 %4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  switch i32 %13, label %17 [
    i32 92, label %14
    i32 34, label %14
  ]

14:                                               ; preds = %10, %10
  %15 = add i64 %.020, 1
  %16 = getelementptr inbounds i32, ptr %2, i64 %.020
  store i32 %13, ptr %16, align 4, !tbaa !5
  br label %19, !llvm.loop !9

17:                                               ; preds = %10
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %19

19:                                               ; preds = %17, %14, %7
  %.117 = phi i64 [ %4, %7 ], [ %11, %14 ], [ %11, %17 ]
  %.1 = phi i64 [ %8, %7 ], [ %15, %14 ], [ %.020, %17 ]
  %20 = icmp ult i64 %.117, %1
  br i1 %20, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %19, %3
  %.0.lcssa = phi i64 [ 0, %3 ], [ %.1, %19 ]
  ret i64 %.0.lcssa
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree nounwind "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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass