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

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

; 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

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) #1

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_fstream_json_printer(ptr noundef %0, i32 noundef %1, i8 noundef signext %2, i32 noundef %3, ptr noundef %4) #5 {
  %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 ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  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) #8
  %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 %87

22:                                               ; preds = %5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %52, 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 %51

28:                                               ; preds = %25
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = call ptr @llvm.stacksave.p0()
  store ptr %31, ptr %14, align 8
  %32 = alloca i8, i64 %30, align 16
  store i64 %30, ptr %15, align 8
  %33 = load i8, ptr %9, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = trunc i32 %34 to i8
  call void @llvm.memset.p0.i64(ptr align 16 %32, i8 %35, i64 %30, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #8
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = call i64 @fwrite(ptr noundef %32, i64 noundef 1, i64 noundef %37, ptr noundef %38)
  store i64 %39, ptr %16, align 8, !tbaa !12
  %40 = load i64, ptr %16, align 8, !tbaa !12
  %41 = icmp ne i64 %40, %30
  br i1 %41, label %42, label %46

42:                                               ; preds = %28
  %43 = call ptr @__errno_location() #9
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = call i64 @iwrc_set_errno(i64 noundef 70002, i32 noundef %44)
  store i64 %45, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %47

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

47:                                               ; preds = %46, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #8
  %48 = load ptr, ptr %14, align 8
  call void @llvm.stackrestore.p0(ptr %48)
  %49 = load i32, ptr %13, align 4
  switch i32 %49, label %87 [
    i32 0, label %50
  ]

50:                                               ; preds = %47
  br label %51

51:                                               ; preds = %50, %25
  br label %86

52:                                               ; preds = %22
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %59

55:                                               ; preds = %52
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = call i64 @strlen(ptr noundef %56) #10
  %58 = trunc i64 %57 to i32
  store i32 %58, ptr %8, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %55, %52
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %63, label %62

62:                                               ; preds = %59
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %62, %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #8
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %80, %63
  %65 = load i32, ptr %17, align 4, !tbaa !9
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  store i32 2, ptr %13, align 4
  br label %83

69:                                               ; preds = %64
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.3, i32 noundef %71, ptr noundef %72) #8
  %74 = icmp slt i32 %73, 0
  br i1 %74, label %75, label %79

75:                                               ; preds = %69
  %76 = call ptr @__errno_location() #9
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = call i64 @iwrc_set_errno(i64 noundef 70002, i32 noundef %77)
  store i64 %78, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %83

79:                                               ; preds = %69
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %17, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %17, align 4, !tbaa !9
  br label %64, !llvm.loop !14

83:                                               ; preds = %75, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  %84 = load i32, ptr %13, align 4
  switch i32 %84, label %87 [
    i32 2, label %85
  ]

85:                                               ; preds = %83
  br label %86

86:                                               ; preds = %85, %51
  store i64 0, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %87

87:                                               ; preds = %86, %83, %47, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  %88 = load i64, ptr %6, align 8
  ret i64 %88
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #6

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #6

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #7

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


; 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.3 = external hidden unnamed_addr constant [5 x i8], align 1

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_fstream_json_printer(ptr noundef %0, i32 noundef %1, i8 noundef signext %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #4 {
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %.loopexit, label %6

6:                                                ; preds = %5
  %.not30 = icmp eq ptr %0, null
  br i1 %.not30, label %7, label %18

7:                                                ; preds = %6
  %.not31 = icmp eq i32 %3, 0
  br i1 %.not31, label %.loopexit, label %8

8:                                                ; preds = %7
  %9 = zext i32 %3 to i64
  %10 = tail call ptr @llvm.stacksave.p0()
  %11 = alloca i8, i64 %9, align 16
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %11, i8 %2, i64 %9, i1 false)
  %12 = sext i32 %3 to i64
  %13 = call i64 @fwrite(ptr noundef nonnull %11, i64 noundef 1, i64 noundef %12, ptr noundef nonnull %4)
  %.not32 = icmp eq i64 %13, %9
  br i1 %.not32, label %.thread, label %14

.thread:                                          ; preds = %8
  tail call void @llvm.stackrestore.p0(ptr %10)
  br label %.loopexit

14:                                               ; preds = %8
  %15 = tail call ptr @__errno_location() #8
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = tail call i64 @iwrc_set_errno(i64 noundef 70002, i32 noundef %16) #9
  tail call void @llvm.stackrestore.p0(ptr %10)
  br label %.loopexit

18:                                               ; preds = %6
  %19 = icmp slt i32 %1, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #10
  %22 = trunc i64 %21 to i32
  br label %23

23:                                               ; preds = %20, %18
  %.023 = phi i32 [ %22, %20 ], [ %1, %18 ]
  %spec.store.select = tail call i32 @llvm.umax.i32(i32 %3, i32 1)
  %.not3438 = icmp sgt i32 %spec.store.select, 0
  br i1 %.not3438, label %.lr.ph, label %.loopexit

24:                                               ; preds = %.lr.ph
  %25 = add nuw nsw i32 %.039, 1
  %exitcond.not = icmp eq i32 %25, %spec.store.select
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %23, %24
  %.039 = phi i32 [ %25, %24 ], [ 0, %23 ]
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %4, ptr noundef nonnull @.str.3, i32 noundef %.023, ptr noundef nonnull %0) #9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %.thread36, label %24

.thread36:                                        ; preds = %.lr.ph
  %28 = tail call ptr @__errno_location() #8
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = tail call i64 @iwrc_set_errno(i64 noundef 70002, i32 noundef %29) #9
  br label %.loopexit

.loopexit:                                        ; preds = %24, %23, %7, %.thread, %.thread36, %14, %5
  %.2 = phi i64 [ %17, %14 ], [ 70017, %5 ], [ %30, %.thread36 ], [ 0, %.thread ], [ 0, %7 ], [ 0, %23 ], [ 0, %24 ]
  ret i64 %.2
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #5

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #5

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

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

attributes #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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 #5 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #6 = { 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" }
attributes #7 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { nounwind }
attributes #10 = { 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 = !{!"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: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass