; LLVM IR from kala13x/libxutils :: src/data (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"

%struct.xjson_obj_ = type { i32, i8, i8, i8, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @XJSON_FreeObject(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
define dso_local i32 @XJSON_AddObject(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %19, label %16

16:                                               ; preds = %2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %2
  store i32 2, ptr %3, align 4
  br label %86

20:                                               ; preds = %16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.xjson_obj_, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %67

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.xjson_obj_, ptr %26, i32 0, i32 5
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  store ptr %28, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.xjson_obj_, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = call ptr @XMap_GetIndex(ptr noundef %29, ptr noundef %32, ptr noundef %7)
  store ptr %33, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %55

36:                                               ; preds = %25
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.xjson_obj_, ptr %37, i32 0, i32 1
  %39 = load i8, ptr %38, align 4, !tbaa !15
  %40 = icmp ne i8 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  store i32 4, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %66

42:                                               ; preds = %36
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  call void @XJSON_FreeObject(ptr noundef %43)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !13
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.xjson_obj_, ptr %46, i32 0, i32 6
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call i32 @XMap_Update(ptr noundef %44, i32 noundef %45, ptr noundef %48, ptr noundef %49)
  store i32 %50, ptr %10, align 4, !tbaa !13
  %51 = load i32, ptr %10, align 4, !tbaa !13
  %52 = icmp slt i32 %51, 0
  %53 = zext i1 %52 to i64
  %54 = select i1 %52, i32 3, i32 0
  store i32 %54, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %66

55:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.xjson_obj_, ptr %57, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call i32 @XMap_Put(ptr noundef %56, ptr noundef %59, ptr noundef %60)
  store i32 %61, ptr %11, align 4, !tbaa !13
  %62 = load i32, ptr %11, align 4, !tbaa !13
  %63 = icmp slt i32 %62, 0
  %64 = zext i1 %63 to i64
  %65 = select i1 %63, i32 5, i32 0
  store i32 %65, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %66

66:                                               ; preds = %55, %42, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %86

67:                                               ; preds = %20
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.xjson_obj_, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !9
  %71 = icmp eq i32 %70, 2
  br i1 %71, label %72, label %83

72:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.xjson_obj_, ptr %73, i32 0, i32 5
  %75 = load ptr, ptr %74, align 8, !tbaa !12
  store ptr %75, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = call i32 @XArray_AddData(ptr noundef %76, ptr noundef %77, i64 noundef 0)
  store i32 %78, ptr %13, align 4, !tbaa !13
  %79 = load i32, ptr %13, align 4, !tbaa !13
  %80 = icmp slt i32 %79, 0
  %81 = zext i1 %80 to i64
  %82 = select i1 %80, i32 5, i32 0
  store i32 %82, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %86

83:                                               ; preds = %67
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  store i32 2, ptr %3, align 4
  br label %86

86:                                               ; preds = %85, %72, %66, %19
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

declare ptr @XMap_GetIndex(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @XMap_Update(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #2

declare i32 @XMap_Put(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @XArray_AddData(ptr noundef, ptr noundef, i64 noundef) #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 = { 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, !11, i64 0}
!10 = !{!"xjson_obj_", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !7, i64 4}


; 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: nounwind uwtable
declare dso_local void @XJSON_FreeObject(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
define dso_local range(i32 0, 6) i32 @XJSON_AddObject(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %35, label %6

6:                                                ; preds = %2
  %7 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %7, label %35 [
    i32 1, label %8
    i32 2, label %29
  ]

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 0, ptr %3, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %1, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = call ptr @XMap_GetIndex(ptr noundef %10, ptr noundef %12, ptr noundef nonnull %3) #3
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %23, label %14

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load i8, ptr %15, align 4, !tbaa !14
  %.not27 = icmp eq i8 %16, 0
  br i1 %.not27, label %28, label %17

17:                                               ; preds = %14
  call void @XJSON_FreeObject(ptr noundef nonnull %13)
  %18 = load i32, ptr %3, align 4, !tbaa !12
  %19 = load ptr, ptr %11, align 8, !tbaa !13
  %20 = call i32 @XMap_Update(ptr noundef %10, i32 noundef %18, ptr noundef %19, ptr noundef nonnull %1) #3
  %21 = icmp slt i32 %20, 0
  %22 = select i1 %21, i32 3, i32 0
  br label %28

23:                                               ; preds = %8
  %24 = load ptr, ptr %11, align 8, !tbaa !13
  %25 = call i32 @XMap_Put(ptr noundef %10, ptr noundef %24, ptr noundef nonnull %1) #3
  %26 = icmp slt i32 %25, 0
  %27 = select i1 %26, i32 5, i32 0
  br label %28

28:                                               ; preds = %14, %23, %17
  %.0 = phi i32 [ %22, %17 ], [ %27, %23 ], [ 4, %14 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %35

29:                                               ; preds = %6
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = tail call i32 @XArray_AddData(ptr noundef %31, ptr noundef nonnull %1, i64 noundef 0) #3
  %33 = icmp slt i32 %32, 0
  %34 = select i1 %33, i32 5, i32 0
  br label %35

35:                                               ; preds = %6, %2, %29, %28
  %.1 = phi i32 [ %.0, %28 ], [ %34, %29 ], [ 2, %2 ], [ 2, %6 ]
  ret i32 %.1
}

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

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

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

declare i32 @XArray_AddData(ptr noundef, ptr noundef, i64 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 = { mustprogress 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, !7, i64 0}
!6 = !{!"xjson_obj_", !7, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !8, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass