; 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_type_from_der = external hidden unnamed_addr constant [19 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_from_der(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @asn1_type_from_der(i32 noundef %0, ptr noundef %1, ptr 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 ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  %12 = load ptr, ptr %8, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %27

14:                                               ; preds = %5
  %15 = load ptr, ptr %9, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %27

17:                                               ; preds = %14
  %18 = load ptr, ptr %10, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = load ptr, ptr %10, align 8, !tbaa !9
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %20
  %25 = load ptr, ptr %11, align 8, !tbaa !9
  %26 = icmp ne ptr %25, null
  br i1 %26, label %32, label %27

27:                                               ; preds = %24, %20, %17, %14, %5
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr @stderr, align 8, !tbaa !9
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 321, ptr noundef @__FUNCTION__.asn1_type_from_der) #2
  br label %31

31:                                               ; preds = %28
  store i32 -1, ptr %6, align 4
  br label %77

32:                                               ; preds = %24
  %33 = load ptr, ptr %11, align 8, !tbaa !9
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = icmp eq i64 %34, 0
  br i1 %35, label %43, label %36

36:                                               ; preds = %32
  %37 = load ptr, ptr %10, align 8, !tbaa !9
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = zext i8 %39 to i32
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = icmp ne i32 %40, %41
  br i1 %42, label %43, label %46

43:                                               ; preds = %36, %32
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr null, ptr %44, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %45, align 8, !tbaa !11
  store i32 0, ptr %6, align 4
  br label %77

46:                                               ; preds = %36
  %47 = load ptr, ptr %10, align 8, !tbaa !9
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %47, align 8, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  %51 = load i64, ptr %50, align 8, !tbaa !11
  %52 = add i64 %51, -1
  store i64 %52, ptr %50, align 8, !tbaa !11
  %53 = load ptr, ptr %9, align 8, !tbaa !9
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  %55 = load ptr, ptr %11, align 8, !tbaa !9
  %56 = call i32 @asn1_length_from_der(ptr noundef %53, ptr noundef %54, ptr noundef %55)
  %57 = icmp ne i32 %56, 1
  br i1 %57, label %58, label %63

58:                                               ; preds = %46
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr @stderr, align 8, !tbaa !9
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 336, ptr noundef @__FUNCTION__.asn1_type_from_der) #2
  br label %62

62:                                               ; preds = %59
  store i32 -1, ptr %6, align 4
  br label %77

63:                                               ; preds = %46
  %64 = load ptr, ptr %10, align 8, !tbaa !9
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %65, ptr %66, align 8, !tbaa !9
  %67 = load ptr, ptr %9, align 8, !tbaa !9
  %68 = load i64, ptr %67, align 8, !tbaa !11
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = getelementptr inbounds i8, ptr %70, i64 %68
  store ptr %71, ptr %69, align 8, !tbaa !9
  %72 = load ptr, ptr %9, align 8, !tbaa !9
  %73 = load i64, ptr %72, align 8, !tbaa !11
  %74 = load ptr, ptr %11, align 8, !tbaa !9
  %75 = load i64, ptr %74, align 8, !tbaa !11
  %76 = sub i64 %75, %73
  store i64 %76, ptr %74, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  br label %77

77:                                               ; preds = %63, %62, %43, %31
  %78 = load i32, ptr %6, align 4
  ret i32 %78
}

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 = { 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_type_from_der = external hidden unnamed_addr constant [19 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_from_der(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @asn1_type_from_der(i32 noundef %0, ptr noundef writeonly %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = icmp ne ptr %1, null
  %7 = icmp ne ptr %2, null
  %or.cond = and i1 %6, %7
  %8 = icmp ne ptr %3, null
  %or.cond3 = and i1 %or.cond, %8
  br i1 %or.cond3, label %9, label %13

9:                                                ; preds = %5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  %12 = icmp ne ptr %4, null
  %or.cond5 = and i1 %12, %11
  br i1 %or.cond5, label %16, label %13

13:                                               ; preds = %5, %9
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 321, ptr noundef nonnull @__FUNCTION__.asn1_type_from_der) #2
  br label %36

16:                                               ; preds = %9
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load i8, ptr %10, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %.not = icmp eq i32 %21, %0
  br i1 %.not, label %23, label %22

22:                                               ; preds = %19, %16
  store ptr null, ptr %1, align 8, !tbaa !5
  store i64 0, ptr %2, align 8, !tbaa !9
  br label %36

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %10, i64 1
  store ptr %24, ptr %3, align 8, !tbaa !5
  %25 = add i64 %17, -1
  store i64 %25, ptr %4, align 8, !tbaa !9
  %26 = tail call i32 @asn1_length_from_der(ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %.not31 = icmp eq i32 %26, 1
  br i1 %.not31, label %30, label %27

27:                                               ; preds = %23
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 336, ptr noundef nonnull @__FUNCTION__.asn1_type_from_der) #2
  br label %36

30:                                               ; preds = %23
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %31, ptr %1, align 8, !tbaa !5
  %32 = load i64, ptr %2, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  store ptr %33, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = sub i64 %34, %32
  store i64 %35, ptr %4, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %30, %27, %22, %13
  %.0 = phi i32 [ 0, %22 ], [ -1, %27 ], [ 1, %30 ], [ -1, %13 ]
  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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}


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