; LLVM IR from Slingshot-Physics/slingshot-community :: common/json/src (json_verify)

; 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.json_parse_stack_s = type { i32, i32, ptr }
%struct.json_string_s = type { i32, i32, ptr }

@.str.21 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_initialize(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_delete(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_allocate(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_append(ptr noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @json_verify_print_stack(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @json_verify_char_type(ptr noundef, i32 noundef) #0

declare i32 @json_character_type(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @json_verify(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.json_parse_stack_s, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  call void @json_parse_stack_initialize(ptr noundef %4)
  call void @json_parse_stack_allocate(ptr noundef %4)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.json_string_s, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %11, i64 0
  %13 = load i8, ptr %12, align 1, !tbaa !12
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 123
  br i1 %15, label %16, label %17

16:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %62

17:                                               ; preds = %1
  call void @json_parse_stack_append(ptr noundef %4, i32 noundef 0)
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !13
  br label %19

19:                                               ; preds = %49, %18
  %20 = load i32, ptr %7, align 4, !tbaa !13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.json_string_s, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = icmp ult i32 %20, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  store i32 2, ptr %5, align 4
  br label %52

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.json_string_s, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !13
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !12
  store i8 %33, ptr %8, align 1, !tbaa !12
  %34 = load i8, ptr %8, align 1, !tbaa !12
  %35 = sext i8 %34 to i32
  %36 = call i32 @json_character_type(i32 noundef %35)
  %37 = call i32 @json_verify_char_type(ptr noundef %4, i32 noundef %36)
  store i32 %37, ptr %6, align 4, !tbaa !13
  %38 = load i32, ptr %6, align 4, !tbaa !13
  %39 = icmp slt i32 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %26
  %41 = load i32, ptr %7, align 4, !tbaa !13
  %42 = load i8, ptr %8, align 1, !tbaa !12
  %43 = sext i8 %42 to i32
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.21, i32 noundef %41, i32 noundef %43)
  call void @json_verify_print_stack(ptr noundef %4)
  call void @json_parse_stack_delete(ptr noundef %4)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %46

45:                                               ; preds = %26
  call void @json_verify_print_stack(ptr noundef %4)
  store i32 0, ptr %5, align 4
  br label %46

46:                                               ; preds = %45, %40
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %47 = load i32, ptr %5, align 4
  switch i32 %47, label %52 [
    i32 0, label %48
  ]

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %7, align 4, !tbaa !13
  %51 = add i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !13
  br label %19, !llvm.loop !15

52:                                               ; preds = %46, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %53 = load i32, ptr %5, align 4
  switch i32 %53, label %61 [
    i32 2, label %54
  ]

54:                                               ; preds = %52
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.22)
  %56 = getelementptr inbounds %struct.json_parse_stack_s, ptr %4, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !17
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %54
  call void @json_verify_print_stack(ptr noundef %4)
  call void @json_parse_stack_delete(ptr noundef %4)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %61

60:                                               ; preds = %54
  call void @json_verify_print_stack(ptr noundef %4)
  call void @json_parse_stack_delete(ptr noundef %4)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %61

61:                                               ; preds = %60, %59, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %62

62:                                               ; preds = %61, %16
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  %63 = load i32, ptr %2, align 4
  ret i32 %63
}

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, !6, i64 8}
!10 = !{!"json_string_s", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !11, i64 0}
!18 = !{!"json_parse_stack_s", !11, i64 0, !11, i64 4, !6, i64 8}


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

%struct.json_parse_stack_s = type { i32, i32, ptr }

@.str.21 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_initialize(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_delete(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_allocate(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @json_parse_stack_append(ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @json_verify_print_stack(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @json_verify_char_type(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @json_character_type(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @json_verify(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca %struct.json_parse_stack_s, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  call void @json_parse_stack_initialize(ptr noundef nonnull %2)
  call void @json_parse_stack_allocate(ptr noundef nonnull %2)
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i8, ptr %4, align 1, !tbaa !11
  %.not = icmp eq i8 %5, 123
  br i1 %.not, label %6, label %24

6:                                                ; preds = %1
  call void @json_parse_stack_append(ptr noundef nonnull %2, i32 noundef 0)
  %7 = load i32, ptr %0, align 8, !tbaa !12
  %.not1618 = icmp ugt i32 %7, 1
  br i1 %.not1618, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %6, %15
  %indvars.iv = phi i64 [ %indvars.iv.next, %15 ], [ 1, %6 ]
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !11
  %11 = sext i8 %10 to i32
  %12 = call i32 @json_character_type(i32 noundef %11) #4
  %13 = call i32 @json_verify_char_type(ptr noundef nonnull %2, i32 noundef %12)
  %14 = icmp sgt i32 %13, -1
  br i1 %14, label %15, label %18

15:                                               ; preds = %.lr.ph
  call void @json_verify_print_stack(ptr noundef nonnull %2)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr %0, align 8, !tbaa !12
  %17 = zext i32 %16 to i64
  %.not16 = icmp ult i64 %indvars.iv.next, %17
  br i1 %.not16, label %.lr.ph, label %.critedge, !llvm.loop !13

18:                                               ; preds = %.lr.ph
  %19 = trunc nuw i64 %indvars.iv to i32
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21, i32 noundef %19, i32 noundef %11)
  call void @json_verify_print_stack(ptr noundef nonnull %2)
  call void @json_parse_stack_delete(ptr noundef nonnull %2)
  br label %24

.critedge:                                        ; preds = %15, %6
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22)
  %22 = load i32, ptr %2, align 8, !tbaa !15
  %23 = icmp eq i32 %22, 0
  call void @json_verify_print_stack(ptr noundef nonnull %2)
  call void @json_parse_stack_delete(ptr noundef nonnull %2)
  %. = select i1 %23, i32 -1, i32 1
  br label %24

24:                                               ; preds = %.critedge, %18, %1
  %.4 = phi i32 [ -1, %1 ], [ -1, %18 ], [ %., %.critedge ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  ret i32 %.4
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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, !10, i64 8}
!6 = !{!"json_string_s", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !7, i64 0}
!16 = !{!"json_parse_stack_s", !7, i64 0, !7, i64 4, !10, i64 8}


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