; LLVM IR from hit9/bitproto :: lib/c (bitproto)

; 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.BpArrayDescriptor = type { i8, i32, %struct.BpType }
%struct.BpType = type { i32, i32, i32, ptr, ptr, i32 }

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

; Function Attrs: nounwind uwtable
declare dso_local void @BpJsonFormatString(ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @BpJsonFormatArray(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %13, ptr noundef @.str.12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.BpArrayDescriptor, ptr %14, i32 0, i32 2
  %16 = getelementptr inbounds %struct.BpType, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !9
  store i32 %17, ptr %7, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.BpArrayDescriptor, ptr %18, i32 0, i32 2
  %20 = getelementptr inbounds %struct.BpType, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !15
  store i32 %21, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.BpArrayDescriptor, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds %struct.BpType, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !16
  store i32 %25, ptr %9, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %26, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !14
  br label %27

27:                                               ; preds = %64, %3
  %28 = load i32, ptr %11, align 4, !tbaa !14
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.BpArrayDescriptor, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %67

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !14
  %37 = load i32, ptr %7, align 4, !tbaa !14
  %38 = mul nsw i32 %36, %37
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %35, i64 %39
  store ptr %40, ptr %12, align 8, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !14
  switch i32 %41, label %54 [
    i32 1, label %42
    i32 2, label %42
    i32 3, label %42
    i32 4, label %42
    i32 5, label %42
    i32 6, label %47
    i32 8, label %47
  ]

42:                                               ; preds = %34, %34, %34, %34, %34
  %43 = load i32, ptr %8, align 4, !tbaa !14
  %44 = load i32, ptr %9, align 4, !tbaa !14
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  call void @BpJsonFormatBaseType(i32 noundef %43, i32 noundef %44, ptr noundef %45, ptr noundef %46)
  br label %54

47:                                               ; preds = %34, %34
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.BpArrayDescriptor, ptr %48, i32 0, i32 2
  %50 = getelementptr inbounds %struct.BpType, ptr %49, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  call void %51(ptr noundef %52, ptr noundef %53)
  br label %54

54:                                               ; preds = %47, %42, %34
  %55 = load i32, ptr %11, align 4, !tbaa !14
  %56 = add nsw i32 %55, 1
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.BpArrayDescriptor, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !17
  %60 = icmp slt i32 %56, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %54
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %62, ptr noundef @.str.1)
  br label %63

63:                                               ; preds = %61, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %11, align 4, !tbaa !14
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %11, align 4, !tbaa !14
  br label %27, !llvm.loop !19

67:                                               ; preds = %33
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %68, ptr noundef @.str.13)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !12, i64 16}
!10 = !{!"BpArrayDescriptor", !11, i64 0, !12, i64 4, !13, i64 8}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"BpType", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 8}
!16 = !{!10, !12, i64 12}
!17 = !{!10, !12, i64 4}
!18 = !{!10, !6, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"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.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @BpJsonFormatArray(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  tail call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %1, ptr noundef nonnull @.str.12)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = load i32, ptr %4, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  switch i32 %7, label %.lr.ph.split [
    i32 1, label %.lr.ph.split.us
    i32 2, label %.lr.ph.split.us
    i32 3, label %.lr.ph.split.us
    i32 4, label %.lr.ph.split.us
    i32 5, label %.lr.ph.split.us
    i32 6, label %.lr.ph.split.us23
    i32 8, label %.lr.ph.split.us23
  ]

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph
  %14 = sext i32 %6 to i64
  br label %15

15:                                               ; preds = %22, %.lr.ph.split.us
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %22 ], [ 0, %.lr.ph.split.us ]
  %16 = mul nsw i64 %indvars.iv28, %14
  %17 = getelementptr inbounds i8, ptr %2, i64 %16
  tail call void @BpJsonFormatBaseType(i32 noundef %7, i32 noundef %9, ptr noundef %1, ptr noundef %17)
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %18 = load i32, ptr %10, align 4, !tbaa !15
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next29, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  tail call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %1, ptr noundef nonnull @.str.1)
  %.pre31 = load i32, ptr %10, align 4, !tbaa !15
  %.pre33 = sext i32 %.pre31 to i64
  br label %22

22:                                               ; preds = %21, %15
  %.pre-phi = phi i64 [ %.pre33, %21 ], [ %19, %15 ]
  %23 = icmp slt i64 %indvars.iv.next29, %.pre-phi
  br i1 %23, label %15, label %._crit_edge, !llvm.loop !16

.lr.ph.split.us23:                                ; preds = %.lr.ph, %.lr.ph
  %24 = sext i32 %6 to i64
  br label %25

25:                                               ; preds = %33, %.lr.ph.split.us23
  %indvars.iv = phi i64 [ %indvars.iv.next, %33 ], [ 0, %.lr.ph.split.us23 ]
  %26 = mul nsw i64 %indvars.iv, %24
  %27 = getelementptr inbounds i8, ptr %2, i64 %26
  %28 = load ptr, ptr %13, align 8, !tbaa !18
  tail call void %28(ptr noundef %27, ptr noundef %1) #1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = load i32, ptr %10, align 4, !tbaa !15
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  tail call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %1, ptr noundef nonnull @.str.1)
  %.pre = load i32, ptr %10, align 4, !tbaa !15
  %.pre34 = sext i32 %.pre to i64
  br label %33

33:                                               ; preds = %32, %25
  %.pre-phi35 = phi i64 [ %.pre34, %32 ], [ %30, %25 ]
  %34 = icmp slt i64 %indvars.iv.next, %.pre-phi35
  br i1 %34, label %25, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %33, %22, %39, %3
  tail call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %1, ptr noundef nonnull @.str.13)
  ret void

.lr.ph.split:                                     ; preds = %.lr.ph, %39
  %35 = phi i32 [ %40, %39 ], [ %11, %.lr.ph ]
  %.022 = phi i32 [ %36, %39 ], [ 0, %.lr.ph ]
  %36 = add nuw nsw i32 %.022, 1
  %37 = icmp slt i32 %36, %35
  br i1 %37, label %38, label %39

38:                                               ; preds = %.lr.ph.split
  tail call void (ptr, ptr, ...) @BpJsonFormatString(ptr noundef %1, ptr noundef nonnull @.str.1)
  %.pre32 = load i32, ptr %10, align 4, !tbaa !15
  br label %39

39:                                               ; preds = %38, %.lr.ph.split
  %40 = phi i32 [ %.pre32, %38 ], [ %35, %.lr.ph.split ]
  %41 = icmp slt i32 %36, %40
  br i1 %41, label %.lr.ph.split, label %._crit_edge, !llvm.loop !16
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass