; LLVM IR from caryll/otfcc :: lib/table/meta (parse)

; 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_value = type { ptr, i32, %union.anon, %union.anon.2 }
%union.anon = type { %struct.anon }
%struct.anon = type { i32, ptr }
%union.anon.2 = type { ptr }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @parseMetaData(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._json_value, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp eq i32 %12, 5
  br i1 %13, label %14, label %25

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._json_value, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds %struct.anon, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._json_value, ptr %19, i32 0, i32 2
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %23 = zext i32 %22 to i64
  %24 = call ptr @sdsnewlen(ptr noundef %18, i64 noundef %23)
  store ptr %24, ptr %2, align 8
  br label %74

25:                                               ; preds = %1
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._json_value, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !9
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %72

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = call ptr @json_obj_get_type(ptr noundef %31, ptr noundef @.str, i32 noundef 5)
  store ptr %32, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %46

35:                                               ; preds = %30
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._json_value, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds %struct.anon, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._json_value, ptr %40, i32 0, i32 2
  %42 = getelementptr inbounds %struct.anon, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !12
  %44 = zext i32 %43 to i64
  %45 = call ptr @sdsnewlen(ptr noundef %39, i64 noundef %44)
  store ptr %45, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %69

46:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = call ptr @json_obj_get_type(ptr noundef %47, ptr noundef @.str.1, i32 noundef 5)
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %67

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._json_value, ptr %52, i32 0, i32 2
  %54 = getelementptr inbounds %struct.anon, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._json_value, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds %struct.anon, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !12
  %60 = zext i32 %59 to i64
  %61 = call ptr @base64_decode(ptr noundef %55, i64 noundef %60, ptr noundef %7)
  store ptr %61, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i64, ptr %7, align 8, !tbaa !13
  %64 = call ptr @sdsnewlen(ptr noundef %62, i64 noundef %63)
  store ptr %64, ptr %9, align 8, !tbaa !5
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %65) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %66, ptr %2, align 8
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %68

67:                                               ; preds = %46
  store i32 0, ptr %5, align 4
  br label %68

68:                                               ; preds = %67, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %69

69:                                               ; preds = %68, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %70 = load i32, ptr %5, align 4
  switch i32 %70, label %76 [
    i32 0, label %71
    i32 1, label %74
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71, %25
  br label %73

73:                                               ; preds = %72
  store ptr null, ptr %2, align 8
  br label %74

74:                                               ; preds = %73, %69, %14
  %75 = load ptr, ptr %2, align 8
  ret ptr %75

76:                                               ; preds = %69
  unreachable
}

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @json_obj_get_type(ptr noundef, ptr noundef, i32 noundef) #3

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 = { 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 #5 = { 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 8}
!10 = !{!"_json_value", !6, i64 0, !11, i64 8, !7, i64 16, !7, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}


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

; Function Attrs: nounwind uwtable
define dso_local ptr @parseMetaData(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  switch i32 %4, label %.thread [
    i32 5, label %5
    i32 1, label %12
  ]

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = load i32, ptr %6, align 8, !tbaa !11
  %10 = zext i32 %9 to i64
  %11 = tail call ptr @sdsnewlen(ptr noundef %8, i64 noundef %10) #5
  br label %.thread

12:                                               ; preds = %1
  %13 = tail call ptr @json_obj_get_type(ptr noundef nonnull %0, ptr noundef nonnull @.str, i32 noundef 5)
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %21, label %14

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %13, i64 16
  %16 = getelementptr inbounds i8, ptr %13, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = load i32, ptr %15, align 8, !tbaa !11
  %19 = zext i32 %18 to i64
  %20 = tail call ptr @sdsnewlen(ptr noundef %17, i64 noundef %19) #5
  br label %.thread

21:                                               ; preds = %12
  %22 = tail call ptr @json_obj_get_type(ptr noundef nonnull %0, ptr noundef nonnull @.str.1, i32 noundef 5)
  %.not21 = icmp eq ptr %22, null
  br i1 %.not21, label %.thread, label %23

23:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store i64 0, ptr %2, align 8, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %22, i64 16
  %25 = getelementptr inbounds i8, ptr %22, i64 24
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load i32, ptr %24, align 8, !tbaa !11
  %28 = zext i32 %27 to i64
  %29 = call ptr @base64_decode(ptr noundef %26, i64 noundef %28, ptr noundef nonnull %2) #5
  %30 = load i64, ptr %2, align 8, !tbaa !12
  %31 = call ptr @sdsnewlen(ptr noundef %29, i64 noundef %30) #5
  call void @free(ptr noundef %29) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br label %.thread

.thread:                                          ; preds = %23, %14, %1, %21, %5
  %.2 = phi ptr [ %11, %5 ], [ null, %21 ], [ null, %1 ], [ %31, %23 ], [ %20, %14 ]
  ret ptr %.2
}

declare ptr @sdsnewlen(ptr noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @json_obj_get_type(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare ptr @base64_decode(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }

!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_value", !7, i64 0, !10, i64 8, !8, i64 16, !8, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}


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