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

; 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.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [62 x i8], align 1
@__FUNCTION__.x509_time_to_der = external hidden unnamed_addr constant [17 x i8], align 1

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

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

10:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  br label %50

11:                                               ; preds = %3
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = icmp slt i64 %12, -1
  br i1 %13, label %17, label %14

14:                                               ; preds = %11
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = icmp sgt i64 %15, 253402300799
  br i1 %16, label %17, label %22

17:                                               ; preds = %14, %11
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 89, ptr noundef @__FUNCTION__.x509_time_to_der) #3
  br label %21

21:                                               ; preds = %18
  store i32 -1, ptr %4, align 4
  br label %50

22:                                               ; preds = %14
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = icmp sle i64 %23, 2524607999
  br i1 %24, label %25, label %37

25:                                               ; preds = %22
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = call i32 @asn1_utc_time_to_der_ex(i32 noundef 23, i64 noundef %26, ptr noundef %27, ptr noundef %28)
  %30 = icmp ne i32 %29, 1
  br i1 %30, label %31, label %36

31:                                               ; preds = %25
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr @stderr, align 8, !tbaa !9
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 94, ptr noundef @__FUNCTION__.x509_time_to_der) #3
  br label %35

35:                                               ; preds = %32
  store i32 -1, ptr %4, align 4
  br label %50

36:                                               ; preds = %25
  br label %49

37:                                               ; preds = %22
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = call i32 @asn1_generalized_time_to_der_ex(i32 noundef 24, i64 noundef %38, ptr noundef %39, ptr noundef %40)
  %42 = icmp ne i32 %41, 1
  br i1 %42, label %43, label %48

43:                                               ; preds = %37
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr @stderr, align 8, !tbaa !9
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 99, ptr noundef @__FUNCTION__.x509_time_to_der) #3
  br label %47

47:                                               ; preds = %44
  store i32 -1, ptr %4, align 4
  br label %50

48:                                               ; preds = %37
  br label %49

49:                                               ; preds = %48, %36
  store i32 1, ptr %4, align 4
  br label %50

50:                                               ; preds = %49, %47, %35, %21, %10
  %51 = load i32, ptr %4, align 4
  ret i32 %51
}

declare i32 @asn1_utc_time_to_der_ex(i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare i32 @asn1_generalized_time_to_der_ex(i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

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 = { "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 = { 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 = !{!"long", !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}


; 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.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [62 x i8], align 1
@__FUNCTION__.x509_time_to_der = external hidden unnamed_addr constant [17 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
define dso_local range(i32 -1, 2) i32 @x509_time_to_der(i64 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i64 %0, -1
  br i1 %4, label %15, label %5

5:                                                ; preds = %3
  %6 = add i64 %0, -253402300800
  %or.cond = icmp ult i64 %6, -253402300801
  br i1 %or.cond, label %.sink.split, label %7

7:                                                ; preds = %5
  %8 = icmp ult i64 %0, 2524608000
  br i1 %8, label %9, label %11

9:                                                ; preds = %7
  %10 = tail call i32 @asn1_utc_time_to_der_ex(i32 noundef 23, i64 noundef %0, ptr noundef %1, ptr noundef %2) #3
  %.not12 = icmp eq i32 %10, 1
  br i1 %.not12, label %15, label %.sink.split

11:                                               ; preds = %7
  %12 = tail call i32 @asn1_generalized_time_to_der_ex(i32 noundef 24, i64 noundef %0, ptr noundef %1, ptr noundef %2) #3
  %.not = icmp eq i32 %12, 1
  br i1 %.not, label %15, label %.sink.split

.sink.split:                                      ; preds = %11, %9, %5
  %.sink13 = phi i32 [ 89, %5 ], [ 94, %9 ], [ 99, %11 ]
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef %.sink13, ptr noundef nonnull @__FUNCTION__.x509_time_to_der) #4
  br label %15

15:                                               ; preds = %.sink.split, %9, %11, %3
  %.0 = phi i32 [ 0, %3 ], [ 1, %11 ], [ 1, %9 ], [ -1, %.sink.split ]
  ret i32 %.0
}

declare i32 @asn1_utc_time_to_der_ex(i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @asn1_generalized_time_to_der_ex(i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { "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 = { nounwind }
attributes #4 = { 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"}


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