; LLVM IR from MaJerle/lwjson :: tests/test_json_data_types (test_json_data_types)

; 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.test_path_type_t = type { ptr, i32 }
%struct.lwjson_t = type { ptr, i64, i64, %struct.lwjson_token, %struct.anon.0 }
%struct.lwjson_token = type { ptr, i32, ptr, i64, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, i64 }
%struct.anon.0 = type { i8 }

@.str = external hidden unnamed_addr constant [744 x i8], align 1
@__const.test_run.paths_types = external hidden unnamed_addr constant [34 x %struct.test_path_type_t], align 16
@.str.35 = external hidden unnamed_addr constant [30 x i8], align 1
@lwjson = external hidden global %struct.lwjson_t, align 8
@tokens = external hidden global [4096 x %struct.lwjson_token], align 16
@.str.36 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @test_run() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [34 x %struct.test_path_type_t], align 16
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr @.str, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 544, ptr %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.test_run.paths_types, i64 544, i1 false)
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.35)
  %10 = call i32 @lwjson_init(ptr noundef @lwjson, ptr noundef @tokens, i64 noundef 4096)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %0
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.36)
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %80

14:                                               ; preds = %0
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = call i32 @lwjson_parse(ptr noundef @lwjson, ptr noundef %15)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %14
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.37)
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %80

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %66, %20
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = icmp ult i64 %22, 34
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %69

25:                                               ; preds = %21
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds [34 x %struct.test_path_type_t], ptr %6, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.test_path_type_t, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 16, !tbaa !11
  %30 = call ptr @lwjson_find(ptr noundef @lwjson, ptr noundef %29)
  store ptr %30, ptr %2, align 8, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !9
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %43

33:                                               ; preds = %25
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = trunc i64 %34 to i32
  %36 = load i64, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds [34 x %struct.test_path_type_t], ptr %6, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.test_path_type_t, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 16, !tbaa !11
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.38, i32 noundef %35, ptr noundef %39)
  %41 = load i64, ptr %3, align 8, !tbaa !5
  %42 = add i64 %41, 1
  store i64 %42, ptr %3, align 8, !tbaa !5
  br label %66

43:                                               ; preds = %25
  %44 = load ptr, ptr %2, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.lwjson_token, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = load i64, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds [34 x %struct.test_path_type_t], ptr %6, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.test_path_type_t, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !16
  %51 = icmp eq i32 %46, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %43
  %53 = load i64, ptr %4, align 8, !tbaa !5
  %54 = add i64 %53, 1
  store i64 %54, ptr %4, align 8, !tbaa !5
  br label %65

55:                                               ; preds = %43
  %56 = load i64, ptr %8, align 8, !tbaa !5
  %57 = trunc i64 %56 to i32
  %58 = load i64, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds [34 x %struct.test_path_type_t], ptr %6, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.test_path_type_t, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 16, !tbaa !11
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.39, i32 noundef %57, ptr noundef %61)
  %63 = load i64, ptr %3, align 8, !tbaa !5
  %64 = add i64 %63, 1
  store i64 %64, ptr %3, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %55, %52
  br label %66

66:                                               ; preds = %65, %33
  %67 = load i64, ptr %8, align 8, !tbaa !5
  %68 = add i64 %67, 1
  store i64 %68, ptr %8, align 8, !tbaa !5
  br label %21, !llvm.loop !17

69:                                               ; preds = %24
  %70 = call i32 @lwjson_free(ptr noundef @lwjson)
  %71 = load i64, ptr %4, align 8, !tbaa !5
  %72 = trunc i64 %71 to i32
  %73 = load i64, ptr %3, align 8, !tbaa !5
  %74 = trunc i64 %73 to i32
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.40, i32 noundef %72, i32 noundef %74)
  %76 = load i64, ptr %3, align 8, !tbaa !5
  %77 = icmp ugt i64 %76, 0
  %78 = zext i1 %77 to i64
  %79 = select i1 %77, i32 -1, i32 0
  store i32 %79, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %80

80:                                               ; preds = %69, %18, %12
  call void @llvm.lifetime.end.p0(i64 544, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %81 = load i32, ptr %1, align 4
  ret i32 %81
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

declare i32 @lwjson_init(ptr noundef, ptr noundef, i64 noundef) #3

declare i32 @lwjson_parse(ptr noundef, ptr noundef) #3

declare ptr @lwjson_find(ptr noundef, ptr noundef) #3

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

declare i32 @lwjson_free(ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 8}
!15 = !{!"lwjson_token", !10, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !7, i64 32}
!16 = !{!12, !13, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.test_path_type_t = type { ptr, i32 }
%struct.lwjson_t = type { ptr, i64, i64, %struct.lwjson_token, %struct.anon.0 }
%struct.lwjson_token = type { ptr, i32, ptr, i64, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, i64 }
%struct.anon.0 = type { i8 }

@.str = external hidden unnamed_addr constant [744 x i8], align 1
@__const.test_run.paths_types = external hidden unnamed_addr constant [34 x %struct.test_path_type_t], align 16
@.str.35 = external hidden unnamed_addr constant [30 x i8], align 1
@lwjson = external hidden global %struct.lwjson_t, align 8
@tokens = external hidden global [4096 x %struct.lwjson_token], align 16
@.str.36 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @test_run() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.35)
  %2 = tail call i32 @lwjson_init(ptr noundef nonnull @lwjson, ptr noundef nonnull @tokens, i64 noundef 4096) #3
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %5, label %3

3:                                                ; preds = %0
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.36)
  br label %36

5:                                                ; preds = %0
  %6 = tail call i32 @lwjson_parse(ptr noundef nonnull @lwjson, ptr noundef nonnull @.str) #3
  %.not22 = icmp eq i32 %6, 0
  br i1 %.not22, label %.preheader, label %7

7:                                                ; preds = %5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.37)
  br label %36

9:                                                ; preds = %34
  %10 = tail call i32 @lwjson_free(ptr noundef nonnull @lwjson) #3
  %11 = trunc i64 %.120 to i32
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.40, i32 noundef %.1, i32 noundef %11)
  %.not23 = icmp ne i64 %.120, 0
  %13 = sext i1 %.not23 to i32
  br label %36

.preheader:                                       ; preds = %5, %34
  %.026 = phi i64 [ %35, %34 ], [ 0, %5 ]
  %.01825 = phi i32 [ %.1, %34 ], [ 0, %5 ]
  %.01924 = phi i64 [ %.120, %34 ], [ 0, %5 ]
  %14 = getelementptr inbounds [34 x %struct.test_path_type_t], ptr @__const.test_run.paths_types, i64 0, i64 %.026
  %15 = load ptr, ptr %14, align 16, !tbaa !5
  %16 = tail call ptr @lwjson_find(ptr noundef nonnull @lwjson, ptr noundef %15) #3
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %.preheader
  %19 = trunc nuw nsw i64 %.026 to i32
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.38, i32 noundef %19, ptr noundef %15)
  %21 = add i64 %.01924, 1
  br label %34

22:                                               ; preds = %.preheader
  %23 = getelementptr inbounds i8, ptr %16, i64 8
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %14, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !14
  %27 = icmp eq i32 %24, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %22
  %29 = add i32 %.01825, 1
  br label %34

30:                                               ; preds = %22
  %31 = trunc nuw nsw i64 %.026 to i32
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.39, i32 noundef %31, ptr noundef %15)
  %33 = add i64 %.01924, 1
  br label %34

34:                                               ; preds = %28, %30, %18
  %.120 = phi i64 [ %21, %18 ], [ %.01924, %28 ], [ %33, %30 ]
  %.1 = phi i32 [ %.01825, %18 ], [ %29, %28 ], [ %.01825, %30 ]
  %35 = add nuw nsw i64 %.026, 1
  %exitcond.not = icmp eq i64 %35, 34
  br i1 %exitcond.not, label %9, label %.preheader, !llvm.loop !15

36:                                               ; preds = %9, %7, %3
  %.017 = phi i32 [ -1, %3 ], [ -1, %7 ], [ %13, %9 ]
  ret i32 %.017
}

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

declare i32 @lwjson_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @lwjson_parse(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @lwjson_find(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @lwjson_free(ptr noundef) local_unnamed_addr #2

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 = { 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 #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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"lwjson_token", !7, i64 0, !10, i64 8, !7, i64 16, !13, i64 24, !8, i64 32}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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