; LLVM IR from lich0821/WeChatFerry :: WeChatFerry/rpc/nanopb (pb_encode)

; 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.pb_field_iter_s = type { ptr, ptr, i16, i16, i16, i16, i16, i16, i16, i8, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @pb_encode(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.pb_field_iter_s, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %8) #3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = call zeroext i1 @pb_field_iter_begin_const(ptr noundef %8, ptr noundef %10, ptr noundef %11)
  br i1 %12, label %14, label %13

13:                                               ; preds = %3
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %35

14:                                               ; preds = %3
  br label %15

15:                                               ; preds = %32, %14
  %16 = getelementptr inbounds %struct.pb_field_iter_s, ptr %8, i32 0, i32 9
  %17 = load i8, ptr %16, align 2, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = and i32 %18, 15
  %20 = icmp eq i32 %19, 10
  br i1 %20, label %21, label %26

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call zeroext i1 @encode_extension_field(ptr noundef %22, ptr noundef %8)
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %35

25:                                               ; preds = %21
  br label %31

26:                                               ; preds = %15
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call zeroext i1 @encode_field(ptr noundef %27, ptr noundef %8)
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %35

30:                                               ; preds = %26
  br label %31

31:                                               ; preds = %30, %25
  br label %32

32:                                               ; preds = %31
  %33 = call zeroext i1 @pb_field_iter_next(ptr noundef %8)
  br i1 %33, label %15, label %34, !llvm.loop !12

34:                                               ; preds = %32
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %35

35:                                               ; preds = %34, %29, %24, %13
  call void @llvm.lifetime.end.p0(i64 64, ptr %8) #3
  %36 = load i1, ptr %4, align 1
  ret i1 %36
}

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

declare zeroext i1 @pb_field_iter_begin_const(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @encode_extension_field(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @encode_field(ptr noundef, ptr noundef) #0

declare zeroext i1 @pb_field_iter_next(ptr noundef) #2

; 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 = { "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, !7, i64 30}
!10 = !{!"pb_field_iter_s", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 18, !11, i64 20, !11, i64 22, !11, i64 24, !11, i64 26, !11, i64 28, !7, i64 30, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.pb_field_iter_s = type { ptr, ptr, i16, i16, i16, i16, i16, i16, i16, i8, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @pb_encode(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.pb_field_iter_s, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #3
  %5 = call zeroext i1 @pb_field_iter_begin_const(ptr noundef nonnull %4, ptr noundef %1, ptr noundef %2) #3
  br i1 %5, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 30
  br label %7

7:                                                ; preds = %.preheader, %15
  %8 = load i8, ptr %6, align 2, !tbaa !5
  %9 = and i8 %8, 15
  %10 = icmp eq i8 %9, 10
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = call zeroext i1 @encode_extension_field(ptr noundef %0, ptr noundef nonnull %4)
  br i1 %12, label %15, label %.loopexit

13:                                               ; preds = %7
  %14 = call zeroext i1 @encode_field(ptr noundef %0, ptr noundef nonnull %4)
  br i1 %14, label %15, label %.loopexit

15:                                               ; preds = %11, %13
  %16 = call zeroext i1 @pb_field_iter_next(ptr noundef nonnull %4) #3
  br i1 %16, label %7, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %15, %13, %11, %3
  %.0 = phi i1 [ true, %3 ], [ true, %15 ], [ false, %13 ], [ false, %11 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #3
  ret i1 %.0
}

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

declare zeroext i1 @pb_field_iter_begin_const(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @encode_extension_field(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @encode_field(ptr noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i1 @pb_field_iter_next(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { 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, !8, i64 30}
!6 = !{!"pb_field_iter_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !8, i64 30, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass