; 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_boolean_from_der_ex = external hidden unnamed_addr constant [25 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @asn1_boolean_from_der_ex(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr %7, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %22

12:                                               ; preds = %4
  %13 = load ptr, ptr %8, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %22

15:                                               ; preds = %12
  %16 = load ptr, ptr %8, align 8, !tbaa !9
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load ptr, ptr %9, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %27, label %22

22:                                               ; preds = %19, %15, %12, %4
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr @stderr, align 8, !tbaa !9
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 498, ptr noundef @__FUNCTION__.asn1_boolean_from_der_ex) #2
  br label %26

26:                                               ; preds = %23
  store i32 -1, ptr %5, align 4
  br label %97

27:                                               ; preds = %19
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %39, label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %33, i64 0
  %35 = load i8, ptr %34, align 1, !tbaa !13
  %36 = zext i8 %35 to i32
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = icmp ne i32 %36, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %31, %27
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 -1, ptr %40, align 4, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %97

41:                                               ; preds = %31
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = icmp ult i64 %43, 3
  br i1 %44, label %45, label %50

45:                                               ; preds = %41
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr @stderr, align 8, !tbaa !9
  %48 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 507, ptr noundef @__FUNCTION__.asn1_boolean_from_der_ex) #2
  br label %49

49:                                               ; preds = %46
  store i32 -1, ptr %5, align 4
  br label %97

50:                                               ; preds = %41
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %52, i64 1
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = icmp ne i32 %55, 1
  br i1 %56, label %57, label %62

57:                                               ; preds = %50
  br label %58

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

61:                                               ; preds = %58
  store i32 -1, ptr %5, align 4
  br label %97

62:                                               ; preds = %50
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = getelementptr inbounds i8, ptr %64, i64 2
  %66 = load i8, ptr %65, align 1, !tbaa !13
  %67 = zext i8 %66 to i32
  %68 = icmp ne i32 %67, 255
  br i1 %68, label %69, label %81

69:                                               ; preds = %62
  %70 = load ptr, ptr %8, align 8, !tbaa !9
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = getelementptr inbounds i8, ptr %71, i64 2
  %73 = load i8, ptr %72, align 1, !tbaa !13
  %74 = zext i8 %73 to i32
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %81

76:                                               ; preds = %69
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr @stderr, align 8, !tbaa !9
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %78, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 516, ptr noundef @__FUNCTION__.asn1_boolean_from_der_ex) #2
  br label %80

80:                                               ; preds = %77
  store i32 -1, ptr %5, align 4
  br label %97

81:                                               ; preds = %69, %62
  %82 = load ptr, ptr %8, align 8, !tbaa !9
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  %84 = getelementptr inbounds i8, ptr %83, i64 2
  %85 = load i8, ptr %84, align 1, !tbaa !13
  %86 = zext i8 %85 to i32
  %87 = icmp eq i32 %86, 255
  %88 = zext i1 %87 to i64
  %89 = select i1 %87, i32 1, i32 0
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %89, ptr %90, align 4, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !9
  %92 = load ptr, ptr %91, align 8, !tbaa !9
  %93 = getelementptr inbounds i8, ptr %92, i64 3
  store ptr %93, ptr %91, align 8, !tbaa !9
  %94 = load ptr, ptr %9, align 8, !tbaa !9
  %95 = load i64, ptr %94, align 8, !tbaa !11
  %96 = sub i64 %95, 3
  store i64 %96, ptr %94, align 8, !tbaa !11
  store i32 1, ptr %5, align 4
  br label %97

97:                                               ; preds = %81, %80, %61, %49, %39, %26
  %98 = load i32, ptr %5, align 4
  ret i32 %98
}

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_boolean_from_der_ex = external hidden unnamed_addr constant [25 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: nofree nounwind uwtable
define dso_local range(i32 -1, 2) i32 @asn1_boolean_from_der_ex(i32 noundef %0, ptr noundef writeonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = icmp ne ptr %1, null
  %6 = icmp ne ptr %2, null
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %11

7:                                                ; preds = %4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  %10 = icmp ne ptr %3, null
  %or.cond3 = and i1 %10, %9
  br i1 %or.cond3, label %14, label %11

11:                                               ; preds = %4, %7
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 498, ptr noundef nonnull @__FUNCTION__.asn1_boolean_from_der_ex) #2
  br label %43

14:                                               ; preds = %7
  %15 = load i64, ptr %3, align 8, !tbaa !9
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load i8, ptr %8, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %.not = icmp eq i32 %19, %0
  br i1 %.not, label %21, label %20

20:                                               ; preds = %17, %14
  store i32 -1, ptr %1, align 4, !tbaa !12
  br label %43

21:                                               ; preds = %17
  %22 = icmp ult i64 %15, 3
  br i1 %22, label %23, label %26

23:                                               ; preds = %21
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 507, ptr noundef nonnull @__FUNCTION__.asn1_boolean_from_der_ex) #2
  br label %43

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %8, i64 1
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %.not25 = icmp eq i8 %28, 1
  br i1 %.not25, label %32, label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 511, ptr noundef nonnull @__FUNCTION__.asn1_boolean_from_der_ex) #2
  br label %43

32:                                               ; preds = %26
  %33 = getelementptr inbounds i8, ptr %8, i64 2
  %34 = load i8, ptr %33, align 1, !tbaa !11
  switch i8 %34, label %35 [
    i8 -1, label %38
    i8 0, label %38
  ]

35:                                               ; preds = %32
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 516, ptr noundef nonnull @__FUNCTION__.asn1_boolean_from_der_ex) #2
  br label %43

38:                                               ; preds = %32, %32
  %39 = icmp eq i8 %34, -1
  %40 = zext i1 %39 to i32
  store i32 %40, ptr %1, align 4, !tbaa !12
  %41 = getelementptr inbounds i8, ptr %8, i64 3
  store ptr %41, ptr %2, align 8, !tbaa !5
  %42 = add i64 %15, -3
  store i64 %42, ptr %3, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %38, %35, %29, %23, %20, %11
  %.0 = phi i32 [ 0, %20 ], [ -1, %23 ], [ -1, %29 ], [ -1, %35 ], [ 1, %38 ], [ -1, %11 ]
  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 = { nofree 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}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


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