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

; Function Attrs: nounwind uwtable
define dso_local void @BpEndecodeMessage(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.BpProcessorContext, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %14, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  store i16 0, ptr %8, align 2, !tbaa !14
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.BpMessageDescriptor, ptr %15, i32 0, i32 0
  %17 = load i8, ptr %16, align 8, !tbaa !16, !range !18, !noundef !19
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %32

19:                                               ; preds = %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.BpProcessorContext, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 8, !tbaa !20, !range !18, !noundef !19
  %23 = trunc i8 %22 to i1
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  call void @BpEncodeMessageExtensibleAhead(ptr noundef %25, ptr noundef %26)
  br label %31

27:                                               ; preds = %19
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call zeroext i16 @BpDecodeMessageExtensibleAhead(ptr noundef %28, ptr noundef %29)
  store i16 %30, ptr %8, align 2, !tbaa !14
  br label %31

31:                                               ; preds = %27, %24
  br label %32

32:                                               ; preds = %31, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %49, %32
  %34 = load i32, ptr %9, align 4, !tbaa !13
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.BpMessageDescriptor, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !21
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.BpMessageDescriptor, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  %44 = load i32, ptr %9, align 4, !tbaa !13
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.BpMessageFieldDescriptor, ptr %43, i64 %45
  store ptr %46, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  call void @BpEndecodeMessageField(ptr noundef %47, ptr noundef %48, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %49

49:                                               ; preds = %40
  %50 = load i32, ptr %9, align 4, !tbaa !13
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !13
  br label %33, !llvm.loop !23

52:                                               ; preds = %39
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.BpMessageDescriptor, ptr %53, i32 0, i32 0
  %55 = load i8, ptr %54, align 8, !tbaa !16, !range !18, !noundef !19
  %56 = trunc i8 %55 to i1
  br i1 %56, label %57, label %77

57:                                               ; preds = %52
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.BpProcessorContext, ptr %58, i32 0, i32 0
  %60 = load i8, ptr %59, align 8, !tbaa !20, !range !18, !noundef !19
  %61 = trunc i8 %60 to i1
  br i1 %61, label %77, label %62

62:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %63 = load i32, ptr %7, align 4, !tbaa !13
  %64 = load i16, ptr %8, align 2, !tbaa !14
  %65 = zext i16 %64 to i32
  %66 = add nsw i32 %63, %65
  store i32 %66, ptr %11, align 4, !tbaa !13
  %67 = load i32, ptr %11, align 4, !tbaa !13
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.BpProcessorContext, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = icmp sge i32 %67, %70
  br i1 %71, label %72, label %76

72:                                               ; preds = %62
  %73 = load i32, ptr %11, align 4, !tbaa !13
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.BpProcessorContext, ptr %74, i32 0, i32 1
  store i32 %73, ptr %75, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %72, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %77

77:                                               ; preds = %76, %57, %52
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @BpDecodeMessageExtensibleAhead(ptr noundef, ptr noundef) #0

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

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

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 = { 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 4}
!10 = !{!"BpProcessorContext", !11, i64 0, !12, i64 4, !6, i64 8}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"BpMessageDescriptor", !11, i64 0, !12, i64 4, !12, i64 8, !6, i64 16}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!10, !11, i64 0}
!21 = !{!17, !12, i64 4}
!22 = !{!17, !6, i64 16}
!23 = distinct !{!23, !24}
!24 = !{!"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.BpMessageFieldDescriptor = type { ptr, %struct.BpType, ptr }
%struct.BpType = type { i32, i32, i32, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @BpEndecodeMessage(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = load i8, ptr %0, align 8, !tbaa !12, !range !14, !noundef !15
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %15

8:                                                ; preds = %3
  %9 = load i8, ptr %1, align 8, !tbaa !16, !range !14, !noundef !15
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  tail call void @BpEncodeMessageExtensibleAhead(ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %15

12:                                               ; preds = %8
  %13 = tail call zeroext i16 @BpDecodeMessageExtensibleAhead(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %14 = zext i16 %13 to i32
  br label %15

15:                                               ; preds = %11, %12, %3
  %.0 = phi i32 [ 0, %11 ], [ %14, %12 ], [ 0, %3 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !17
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  br label %22

._crit_edge:                                      ; preds = %22, %15
  %20 = load i8, ptr %0, align 8, !tbaa !12, !range !14, !noundef !15
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %28, label %35

22:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %23 = load ptr, ptr %19, align 8, !tbaa !18
  %24 = getelementptr inbounds %struct.BpMessageFieldDescriptor, ptr %23, i64 %indvars.iv
  tail call void @BpEndecodeMessageField(ptr noundef %24, ptr noundef %1, ptr noundef null)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr %16, align 4, !tbaa !17
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %22, label %._crit_edge, !llvm.loop !19

28:                                               ; preds = %._crit_edge
  %29 = load i8, ptr %1, align 8, !tbaa !16, !range !14, !noundef !15
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %35, label %31

31:                                               ; preds = %28
  %32 = add nsw i32 %.0, %5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp slt i32 %32, %33
  br i1 %.not, label %35, label %34

34:                                               ; preds = %31
  store i32 %32, ptr %4, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %31, %34, %28, %._crit_edge
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @BpDecodeMessageExtensibleAhead(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

!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 4}
!6 = !{!"BpProcessorContext", !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 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"BpMessageDescriptor", !7, i64 0, !10, i64 4, !10, i64 8, !11, i64 16}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!6, !7, i64 0}
!17 = !{!13, !10, i64 4}
!18 = !{!13, !11, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass