; LLVM IR from guanzhi/GmSSL :: src (asn1)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@__FUNCTION__.asn1_bit_string_to_der_ex = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @asn1_bit_string_to_der_ex(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !11
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %15 = load i64, ptr %9, align 8, !tbaa !11
  %16 = add i64 %15, 7
  %17 = udiv i64 %16, 8
  store i64 %17, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %18 = load i64, ptr %12, align 8, !tbaa !11
  %19 = mul i64 %18, 8
  %20 = load i64, ptr %9, align 8, !tbaa !11
  %21 = sub i64 %19, %20
  store i64 %21, ptr %13, align 8, !tbaa !11
  %22 = load ptr, ptr %11, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %30, label %24

24:                                               ; preds = %5
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 695, ptr noundef @__FUNCTION__.asn1_bit_string_to_der_ex) #4
  br label %28

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

30:                                               ; preds = %5
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = icmp ne ptr %31, null
  br i1 %32, label %43, label %33

33:                                               ; preds = %30
  %34 = load i64, ptr %9, align 8, !tbaa !11
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %42

36:                                               ; preds = %33
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr @stderr, align 8, !tbaa !9
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 701, ptr noundef @__FUNCTION__.asn1_bit_string_to_der_ex) #4
  br label %40

40:                                               ; preds = %37
  br label %41

41:                                               ; preds = %40
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

42:                                               ; preds = %33
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

43:                                               ; preds = %30
  %44 = load ptr, ptr %10, align 8, !tbaa !9
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %56

46:                                               ; preds = %43
  %47 = load ptr, ptr %10, align 8, !tbaa !9
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %56

50:                                               ; preds = %46
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = trunc i32 %51 to i8
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %53, align 8, !tbaa !9
  store i8 %52, ptr %54, align 1, !tbaa !13
  br label %56

56:                                               ; preds = %50, %46, %43
  %57 = load ptr, ptr %11, align 8, !tbaa !9
  %58 = load i64, ptr %57, align 8, !tbaa !11
  %59 = add i64 %58, 1
  store i64 %59, ptr %57, align 8, !tbaa !11
  %60 = load i64, ptr %12, align 8, !tbaa !11
  %61 = add i64 %60, 1
  %62 = load ptr, ptr %10, align 8, !tbaa !9
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = call i32 @asn1_length_to_der(i64 noundef %61, ptr noundef %62, ptr noundef %63)
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %77

67:                                               ; preds = %56
  %68 = load ptr, ptr %10, align 8, !tbaa !9
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %77

71:                                               ; preds = %67
  %72 = load i64, ptr %13, align 8, !tbaa !11
  %73 = trunc i64 %72 to i8
  %74 = load ptr, ptr %10, align 8, !tbaa !9
  %75 = load ptr, ptr %74, align 8, !tbaa !9
  %76 = getelementptr inbounds i8, ptr %75, i32 1
  store ptr %76, ptr %74, align 8, !tbaa !9
  store i8 %73, ptr %75, align 1, !tbaa !13
  br label %77

77:                                               ; preds = %71, %67, %56
  %78 = load ptr, ptr %11, align 8, !tbaa !9
  %79 = load i64, ptr %78, align 8, !tbaa !11
  %80 = add i64 %79, 1
  store i64 %80, ptr %78, align 8, !tbaa !11
  %81 = load ptr, ptr %10, align 8, !tbaa !9
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %96

83:                                               ; preds = %77
  %84 = load ptr, ptr %10, align 8, !tbaa !9
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %96

87:                                               ; preds = %83
  %88 = load ptr, ptr %10, align 8, !tbaa !9
  %89 = load ptr, ptr %88, align 8, !tbaa !9
  %90 = load ptr, ptr %8, align 8, !tbaa !9
  %91 = load i64, ptr %12, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %89, ptr align 1 %90, i64 %91, i1 false)
  %92 = load i64, ptr %12, align 8, !tbaa !11
  %93 = load ptr, ptr %10, align 8, !tbaa !9
  %94 = load ptr, ptr %93, align 8, !tbaa !9
  %95 = getelementptr inbounds i8, ptr %94, i64 %92
  store ptr %95, ptr %93, align 8, !tbaa !9
  br label %96

96:                                               ; preds = %87, %83, %77
  %97 = load i64, ptr %12, align 8, !tbaa !11
  %98 = load ptr, ptr %11, align 8, !tbaa !9
  %99 = load i64, ptr %98, align 8, !tbaa !11
  %100 = add i64 %99, %97
  store i64 %100, ptr %98, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

101:                                              ; preds = %96, %42, %41, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %102 = load i32, ptr %6, align 4
  ret i32 %102
}

attributes #0 = { nounwind "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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@__FUNCTION__.asn1_bit_string_to_der_ex = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @asn1_bit_string_to_der_ex(i32 noundef %0, ptr noundef readonly %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = add i64 %2, 7
  %7 = lshr i64 %6, 3
  %8 = and i64 %6, 248
  %9 = sub i64 %8, %2
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %10, label %13

10:                                               ; preds = %5
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 695, ptr noundef nonnull @__FUNCTION__.asn1_bit_string_to_der_ex) #3
  br label %50

13:                                               ; preds = %5
  %.not34 = icmp eq ptr %1, null
  br i1 %.not34, label %14, label %18

14:                                               ; preds = %13
  %.not35 = icmp eq i64 %2, 0
  br i1 %.not35, label %50, label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 701, ptr noundef nonnull @__FUNCTION__.asn1_bit_string_to_der_ex) #3
  br label %50

18:                                               ; preds = %13
  %.not36 = icmp eq ptr %3, null
  br i1 %.not36, label %32, label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %.not37 = icmp eq ptr %20, null
  br i1 %.not37, label %24, label %21

21:                                               ; preds = %19
  %22 = trunc i32 %0 to i8
  %23 = getelementptr inbounds i8, ptr %20, i64 1
  store ptr %23, ptr %3, align 8, !tbaa !5
  store i8 %22, ptr %20, align 1, !tbaa !9
  br label %24

24:                                               ; preds = %19, %21
  %25 = load i64, ptr %4, align 8, !tbaa !10
  %26 = add i64 %25, 1
  store i64 %26, ptr %4, align 8, !tbaa !10
  %27 = add nuw nsw i64 %7, 1
  %28 = tail call i32 @asn1_length_to_der(i64 noundef %27, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %.not38 = icmp eq ptr %29, null
  br i1 %.not38, label %.thread42, label %39

.thread42:                                        ; preds = %24
  %30 = load i64, ptr %4, align 8, !tbaa !10
  %31 = add i64 %30, 1
  br label %47

32:                                               ; preds = %18
  %33 = load i64, ptr %4, align 8, !tbaa !10
  %34 = add i64 %33, 1
  store i64 %34, ptr %4, align 8, !tbaa !10
  %35 = add nuw nsw i64 %7, 1
  %36 = tail call i32 @asn1_length_to_der(i64 noundef %35, ptr noundef null, ptr noundef nonnull %4)
  %37 = load i64, ptr %4, align 8, !tbaa !10
  %38 = add i64 %37, 1
  br label %47

39:                                               ; preds = %24
  %40 = trunc i64 %9 to i8
  %41 = getelementptr inbounds i8, ptr %29, i64 1
  store ptr %41, ptr %3, align 8, !tbaa !5
  store i8 %40, ptr %29, align 1, !tbaa !9
  %.pr = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i64, ptr %4, align 8, !tbaa !10
  %43 = add i64 %42, 1
  store i64 %43, ptr %4, align 8, !tbaa !10
  %.not39 = icmp eq ptr %.pr, null
  br i1 %.not39, label %47, label %44

44:                                               ; preds = %39
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %.pr, ptr nonnull align 1 %1, i64 %7, i1 false)
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 %7
  store ptr %46, ptr %3, align 8, !tbaa !5
  %.pre = load i64, ptr %4, align 8, !tbaa !10
  br label %47

47:                                               ; preds = %.thread42, %32, %44, %39
  %48 = phi i64 [ %31, %.thread42 ], [ %38, %32 ], [ %.pre, %44 ], [ %43, %39 ]
  %49 = add i64 %48, %7
  store i64 %49, ptr %4, align 8, !tbaa !10
  br label %50

50:                                               ; preds = %14, %47, %15, %10
  %.0 = phi i32 [ 1, %47 ], [ -1, %15 ], [ -1, %10 ], [ 0, %14 ]
  ret i32 %.0
}

attributes #0 = { nofree nounwind "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 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { cold 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


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