; LLVM IR from xtruan/FlipBIP :: lib/crypto (segwit_addr)

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

; 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 i32 @bech32_decode(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @convert_bits(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @segwit_addr_decode(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [84 x i8], align 16
  %13 = alloca [84 x i8], align 16
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 84, ptr %12) #4
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 84, i1 false)
  call void @llvm.lifetime.start.p0(i64 84, ptr %13) #4
  call void @llvm.memset.p0.i64(ptr align 16 %13, i8 0, i64 84, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !9
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #5
  %19 = icmp ugt i64 %18, 90
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %106

21:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %22 = getelementptr inbounds [84 x i8], ptr %13, i64 0, i64 0
  %23 = getelementptr inbounds [84 x i8], ptr %12, i64 0, i64 0
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = call i32 @bech32_decode(ptr noundef %22, ptr noundef %23, ptr noundef %14, ptr noundef %24)
  store i32 %25, ptr %16, align 4, !tbaa !11
  %26 = load i32, ptr %16, align 4, !tbaa !11
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %21
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

29:                                               ; preds = %21
  %30 = load i64, ptr %14, align 8, !tbaa !9
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = load i64, ptr %14, align 8, !tbaa !9
  %34 = icmp ugt i64 %33, 65
  br i1 %34, label %35, label %36

35:                                               ; preds = %32, %29
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

36:                                               ; preds = %32
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds [84 x i8], ptr %13, i64 0, i64 0
  %39 = call i32 @strncmp(ptr noundef %37, ptr noundef %38, i64 noundef 84) #5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

42:                                               ; preds = %36
  %43 = getelementptr inbounds [84 x i8], ptr %12, i64 0, i64 0
  %44 = load i8, ptr %43, align 16, !tbaa !13
  %45 = zext i8 %44 to i32
  %46 = icmp sgt i32 %45, 16
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

48:                                               ; preds = %42
  %49 = getelementptr inbounds [84 x i8], ptr %12, i64 0, i64 0
  %50 = load i8, ptr %49, align 16, !tbaa !13
  %51 = zext i8 %50 to i32
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %57

53:                                               ; preds = %48
  %54 = load i32, ptr %16, align 4, !tbaa !11
  %55 = icmp ne i32 %54, 1
  br i1 %55, label %56, label %57

56:                                               ; preds = %53
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

57:                                               ; preds = %53, %48
  %58 = getelementptr inbounds [84 x i8], ptr %12, i64 0, i64 0
  %59 = load i8, ptr %58, align 16, !tbaa !13
  %60 = zext i8 %59 to i32
  %61 = icmp sgt i32 %60, 0
  br i1 %61, label %62, label %66

62:                                               ; preds = %57
  %63 = load i32, ptr %16, align 4, !tbaa !11
  %64 = icmp ne i32 %63, 2
  br i1 %64, label %65, label %66

65:                                               ; preds = %62
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

66:                                               ; preds = %62, %57
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %67, align 8, !tbaa !9
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds [84 x i8], ptr %12, i64 0, i64 0
  %71 = getelementptr inbounds i8, ptr %70, i64 1
  %72 = load i64, ptr %14, align 8, !tbaa !9
  %73 = sub i64 %72, 1
  %74 = call i32 @convert_bits(ptr noundef %68, ptr noundef %69, i32 noundef 8, ptr noundef %71, i64 noundef %73, i32 noundef 5, i32 noundef 0)
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %77, label %76

76:                                               ; preds = %66
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

77:                                               ; preds = %66
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = load i64, ptr %78, align 8, !tbaa !9
  %80 = icmp ult i64 %79, 2
  br i1 %80, label %85, label %81

81:                                               ; preds = %77
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = load i64, ptr %82, align 8, !tbaa !9
  %84 = icmp ugt i64 %83, 40
  br i1 %84, label %85, label %86

85:                                               ; preds = %81, %77
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

86:                                               ; preds = %81
  %87 = getelementptr inbounds [84 x i8], ptr %12, i64 0, i64 0
  %88 = load i8, ptr %87, align 16, !tbaa !13
  %89 = zext i8 %88 to i32
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %100

91:                                               ; preds = %86
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = load i64, ptr %92, align 8, !tbaa !9
  %94 = icmp ne i64 %93, 20
  br i1 %94, label %95, label %100

95:                                               ; preds = %91
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = load i64, ptr %96, align 8, !tbaa !9
  %98 = icmp ne i64 %97, 32
  br i1 %98, label %99, label %100

99:                                               ; preds = %95
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

100:                                              ; preds = %95, %91, %86
  %101 = getelementptr inbounds [84 x i8], ptr %12, i64 0, i64 0
  %102 = load i8, ptr %101, align 16, !tbaa !13
  %103 = zext i8 %102 to i32
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %103, ptr %104, align 4, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %105

105:                                              ; preds = %100, %99, %85, %76, %65, %56, %47, %41, %35, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %106

106:                                              ; preds = %105, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 84, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 84, ptr %12) #4
  %107 = load i32, ptr %6, align 4
  ret i32 %107
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #2

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 willreturn memory(read) "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !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"

; 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 i32 @bech32_decode(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @convert_bits(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @segwit_addr_decode(ptr nocapture noundef writeonly %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca [84 x i8], align 16
  %7 = alloca [84 x i8], align 16
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 84, ptr nonnull %6) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(84) %6, i8 0, i64 84, i1 false)
  call void @llvm.lifetime.start.p0(i64 84, ptr nonnull %7) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(84) %7, i8 0, i64 84, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #5
  %10 = icmp ugt i64 %9, 90
  br i1 %10, label %39, label %11

11:                                               ; preds = %5
  %12 = call i32 @bech32_decode(ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull %8, ptr noundef %4)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %39, label %14

14:                                               ; preds = %11
  %15 = load i64, ptr %8, align 8
  %16 = add i64 %15, -66
  %or.cond = icmp ult i64 %16, -65
  br i1 %or.cond, label %39, label %17

17:                                               ; preds = %14
  %18 = call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %7, i64 noundef 84) #5
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %39

19:                                               ; preds = %17
  %20 = load i8, ptr %6, align 16, !tbaa !9
  %21 = icmp ugt i8 %20, 16
  br i1 %21, label %39, label %22

22:                                               ; preds = %19
  %23 = icmp eq i8 %20, 0
  %24 = icmp ne i32 %12, 1
  %or.cond3 = and i1 %24, %23
  br i1 %or.cond3, label %39, label %25

25:                                               ; preds = %22
  %26 = icmp ne i8 %20, 0
  %27 = icmp ne i32 %12, 2
  %or.cond5 = and i1 %27, %26
  br i1 %or.cond5, label %39, label %28

28:                                               ; preds = %25
  store i64 0, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %6, i64 1
  %30 = add nsw i64 %15, -1
  %31 = call i32 @convert_bits(ptr noundef %1, ptr noundef nonnull %2, i32 noundef 8, ptr noundef nonnull %29, i64 noundef %30, i32 noundef 5, i32 noundef 0)
  %.not22 = icmp eq i32 %31, 0
  br i1 %.not22, label %39, label %32

32:                                               ; preds = %28
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = add i64 %33, -41
  %or.cond25 = icmp ult i64 %34, -39
  br i1 %or.cond25, label %39, label %35

35:                                               ; preds = %32
  %36 = load i8, ptr %6, align 16, !tbaa !9
  %.fr = freeze i8 %36
  %.not28 = icmp eq i8 %.fr, 0
  br i1 %.not28, label %switch.early.test, label %37

switch.early.test:                                ; preds = %35
  switch i64 %33, label %39 [
    i64 32, label %37
    i64 20, label %37
  ]

37:                                               ; preds = %switch.early.test, %switch.early.test, %35
  %38 = zext i8 %.fr to i32
  store i32 %38, ptr %0, align 4, !tbaa !10
  br label %39

39:                                               ; preds = %switch.early.test, %37, %11, %14, %17, %19, %22, %25, %28, %32, %5
  %.1 = phi i32 [ 0, %5 ], [ 1, %37 ], [ 0, %11 ], [ 0, %14 ], [ 0, %17 ], [ 0, %19 ], [ 0, %22 ], [ 0, %25 ], [ 0, %28 ], [ 0, %32 ], [ 0, %switch.early.test ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 84, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 84, ptr nonnull %6) #4
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

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


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