; LLVM IR from Softmotions/iowow :: src/json (iwjson)

; 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_xstr_json_printer(ptr noundef %0, i32 noundef %1, i8 noundef signext %2, i32 noundef %3, ptr noundef %4) #3 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i8 %2, ptr %9, align 1, !tbaa !11
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %18, ptr %12, align 8, !tbaa !5
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %5
  store i64 70017, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %102

22:                                               ; preds = %5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %58, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %57

28:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %51, %28
  %30 = load i32, ptr %14, align 4, !tbaa !9
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 2, ptr %13, align 4
  br label %54

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = call i64 @iwxstr_cat(ptr noundef %35, ptr noundef %9, i64 noundef 1)
  store i64 %36, ptr %15, align 8, !tbaa !12
  %37 = load i64, ptr %15, align 8, !tbaa !12
  %38 = icmp ne i64 %37, 0
  %39 = xor i1 %38, true
  %40 = xor i1 %39, true
  %41 = zext i1 %40 to i32
  %42 = sext i32 %41 to i64
  %43 = call i64 @llvm.expect.i64(i64 %42, i64 0)
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %34
  %46 = load i64, ptr %15, align 8, !tbaa !12
  store i64 %46, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %48

47:                                               ; preds = %34
  store i32 0, ptr %13, align 4
  br label %48

48:                                               ; preds = %47, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  %49 = load i32, ptr %13, align 4
  switch i32 %49, label %54 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %14, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %14, align 4, !tbaa !9
  br label %29, !llvm.loop !14

54:                                               ; preds = %48, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %55 = load i32, ptr %13, align 4
  switch i32 %55, label %102 [
    i32 2, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %25
  br label %101

58:                                               ; preds = %22
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = icmp slt i32 %59, 0
  br i1 %60, label %61, label %65

61:                                               ; preds = %58
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = call i64 @strlen(ptr noundef %62) #6
  %64 = trunc i64 %63 to i32
  store i32 %64, ptr %8, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %61, %58
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %69, label %68

68:                                               ; preds = %65
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %68, %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %95, %69
  %71 = load i32, ptr %16, align 4, !tbaa !9
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %70
  store i32 5, ptr %13, align 4
  br label %98

75:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = call i64 @iwxstr_cat(ptr noundef %76, ptr noundef %77, i64 noundef %79)
  store i64 %80, ptr %17, align 8, !tbaa !12
  %81 = load i64, ptr %17, align 8, !tbaa !12
  %82 = icmp ne i64 %81, 0
  %83 = xor i1 %82, true
  %84 = xor i1 %83, true
  %85 = zext i1 %84 to i32
  %86 = sext i32 %85 to i64
  %87 = call i64 @llvm.expect.i64(i64 %86, i64 0)
  %88 = icmp ne i64 %87, 0
  br i1 %88, label %89, label %91

89:                                               ; preds = %75
  %90 = load i64, ptr %17, align 8, !tbaa !12
  store i64 %90, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %92

91:                                               ; preds = %75
  store i32 0, ptr %13, align 4
  br label %92

92:                                               ; preds = %91, %89
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  %93 = load i32, ptr %13, align 4
  switch i32 %93, label %98 [
    i32 0, label %94
  ]

94:                                               ; preds = %92
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %16, align 4, !tbaa !9
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %16, align 4, !tbaa !9
  br label %70, !llvm.loop !16

98:                                               ; preds = %92, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  %99 = load i32, ptr %13, align 4
  switch i32 %99, label %102 [
    i32 5, label %100
  ]

100:                                              ; preds = %98
  br label %101

101:                                              ; preds = %100, %57
  store i64 0, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %102

102:                                              ; preds = %101, %98, %54, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %103 = load i64, ptr %6, align 8
  ret i64 %103
}

declare i64 @iwxstr_cat(ptr noundef, ptr noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { nounwind willreturn memory(read) "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 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 = { "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_xstr_json_printer(ptr noundef %0, i32 noundef %1, i8 noundef signext %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca i8, align 1
  store i8 %2, ptr %6, align 1, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %.thread, label %7

7:                                                ; preds = %5
  %.not41 = icmp eq ptr %0, null
  br i1 %.not41, label %8, label %12

8:                                                ; preds = %7
  %.not4457 = icmp sgt i32 %3, 0
  br i1 %.not4457, label %.lr.ph59, label %.thread

9:                                                ; preds = %.lr.ph59
  %10 = add nuw nsw i32 %.03058, 1
  %exitcond65.not = icmp eq i32 %10, %3
  br i1 %exitcond65.not, label %.thread, label %.lr.ph59, !llvm.loop !8

.lr.ph59:                                         ; preds = %8, %9
  %.03058 = phi i32 [ %10, %9 ], [ 0, %8 ]
  %11 = call i64 @iwxstr_cat(ptr noundef nonnull %4, ptr noundef nonnull %6, i64 noundef 1) #4
  %.not43 = icmp eq i64 %11, 0
  br i1 %.not43, label %9, label %.thread

12:                                               ; preds = %7
  %13 = icmp slt i32 %1, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %12
  %15 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %16 = trunc i64 %15 to i32
  br label %17

17:                                               ; preds = %14, %12
  %.029 = phi i32 [ %16, %14 ], [ %1, %12 ]
  %spec.store.select = tail call i32 @llvm.umax.i32(i32 %3, i32 1)
  %18 = sext i32 %.029 to i64
  %.not4753 = icmp sgt i32 %spec.store.select, 0
  br i1 %.not4753, label %.lr.ph, label %.thread

19:                                               ; preds = %.lr.ph
  %20 = add nuw nsw i32 %.02854, 1
  %exitcond.not = icmp eq i32 %20, %spec.store.select
  br i1 %exitcond.not, label %.thread, label %.lr.ph, !llvm.loop !10

.lr.ph:                                           ; preds = %17, %19
  %.02854 = phi i32 [ %20, %19 ], [ 0, %17 ]
  %21 = tail call i64 @iwxstr_cat(ptr noundef nonnull %4, ptr noundef nonnull %0, i64 noundef %18) #4
  %.not46 = icmp eq i64 %21, 0
  br i1 %.not46, label %19, label %.thread

.thread:                                          ; preds = %19, %.lr.ph, %9, %.lr.ph59, %17, %8, %5
  %.6 = phi i64 [ 70017, %5 ], [ 0, %8 ], [ 0, %17 ], [ 0, %9 ], [ %11, %.lr.ph59 ], [ 0, %19 ], [ %21, %.lr.ph ]
  ret i64 %.6
}

declare i64 @iwxstr_cat(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass