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

; 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_istream_s = type { ptr, ptr, i64, ptr }

; 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 zeroext i1 @pb_make_string_substream(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @pb_close_string_substream(ptr noundef, ptr noundef) #1

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

16:                                               ; preds = %4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = call zeroext i1 @pb_decode_inner(ptr noundef %17, ptr noundef %18, ptr noundef %19, i32 noundef %20)
  %22 = zext i1 %21 to i8
  store i8 %22, ptr %10, align 1, !tbaa !11
  br label %40

23:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #2
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call zeroext i1 @pb_make_string_substream(ptr noundef %24, ptr noundef %11)
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %37

27:                                               ; preds = %23
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = call zeroext i1 @pb_decode_inner(ptr noundef %11, ptr noundef %28, ptr noundef %29, i32 noundef %30)
  %32 = zext i1 %31 to i8
  store i8 %32, ptr %10, align 1, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call zeroext i1 @pb_close_string_substream(ptr noundef %33, ptr noundef %11)
  br i1 %34, label %36, label %35

35:                                               ; preds = %27
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %37

36:                                               ; preds = %27
  store i32 0, ptr %12, align 4
  br label %37

37:                                               ; preds = %36, %35, %26
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #2
  %38 = load i32, ptr %12, align 4
  switch i32 %38, label %49 [
    i32 0, label %39
  ]

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39, %16
  %41 = load i8, ptr %10, align 1, !tbaa !11, !range !13, !noundef !14
  %42 = trunc i8 %41 to i1
  br i1 %42, label %46, label %43

43:                                               ; preds = %40
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  call void @pb_release(ptr noundef %44, ptr noundef %45)
  br label %46

46:                                               ; preds = %43, %40
  %47 = load i8, ptr %10, align 1, !tbaa !11, !range !13, !noundef !14
  %48 = trunc i8 %47 to i1
  store i1 %48, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %49

49:                                               ; preds = %46, %37
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  %50 = load i1, ptr %5, align 1
  ret i1 %50
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @pb_decode_inner(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

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

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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_istream_s = type { ptr, ptr, i64, ptr }

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

; Function Attrs: mustprogress 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 zeroext i1 @pb_make_string_substream(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @pb_close_string_substream(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @pb_decode_ex(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca %struct.pb_istream_s, align 8
  %6 = and i32 %3, 2
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = tail call zeroext i1 @pb_decode_inner(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3)
  br i1 %9, label %16, label %15

10:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #2
  %11 = call zeroext i1 @pb_make_string_substream(ptr noundef %0, ptr noundef nonnull %5)
  br i1 %11, label %12, label %.thread

.thread:                                          ; preds = %10
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #2
  br label %16

12:                                               ; preds = %10
  %13 = call zeroext i1 @pb_decode_inner(ptr noundef nonnull %5, ptr noundef %1, ptr noundef %2, i32 noundef %3)
  %14 = call zeroext i1 @pb_close_string_substream(ptr noundef %0, ptr noundef nonnull %5)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #2
  %.not = xor i1 %14, true
  %brmerge = select i1 %.not, i1 true, i1 %13
  br i1 %brmerge, label %16, label %15

15:                                               ; preds = %12, %8
  call void @pb_release(ptr noundef %1, ptr noundef %2)
  br label %16

16:                                               ; preds = %12, %8, %.thread, %15
  %.117 = phi i1 [ %14, %12 ], [ false, %15 ], [ false, %.thread ], [ true, %8 ]
  ret i1 %.117
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @pb_decode_inner(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress 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)"}


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