; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (iso15946)

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

@.str = external hidden unnamed_addr constant [23 x i8], align 1
@__const.iso15946_generate_secretc.COUNTER = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @iso15946_encode_sharedinfo(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #2

declare void @ba_free(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @iso15946_generate_secretc(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %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 i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca [4 x i8], align 1
  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
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store ptr null, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store ptr null, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store ptr null, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %15, ptr align 1 @__const.iso15946_generate_secretc.COUNTER, i64 4, i1 false)
  br label %16

16:                                               ; preds = %5
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = call i32 @iso15946_encode_sharedinfo(ptr noundef %17, ptr noundef %18, i32 noundef 256, ptr noundef %13)
  store i32 %19, ptr %11, align 4, !tbaa !5
  %20 = load i32, ptr %11, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %16
  %23 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 142, i32 noundef %23)
  br label %99

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = call ptr @iso15946_get_not_zero(ptr noundef %28)
  store ptr %29, ptr %14, align 8, !tbaa !9
  %30 = icmp eq ptr null, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %27
  store i32 2, ptr %11, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 145, i32 noundef %32)
  br label %99

33:                                               ; preds = %27
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = call ptr @hash_alloc(i32 noundef %37)
  store ptr %38, ptr %12, align 8, !tbaa !9
  %39 = icmp eq ptr null, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %36
  store i32 2, ptr %11, align 4, !tbaa !5
  %41 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 149, i32 noundef %41)
  br label %99

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %12, align 8, !tbaa !9
  %47 = load ptr, ptr %14, align 8, !tbaa !9
  %48 = call i32 @hash_update(ptr noundef %46, ptr noundef %47)
  store i32 %48, ptr %11, align 4, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %45
  %52 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 150, i32 noundef %52)
  br label %99

53:                                               ; preds = %45
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %14, align 8, !tbaa !9
  call void @ba_free(ptr noundef %56)
  br label %57

57:                                               ; preds = %55
  %58 = getelementptr inbounds [4 x i8], ptr %15, i64 0, i64 0
  %59 = call ptr @ba_alloc_from_uint8(ptr noundef %58, i64 noundef 4)
  store ptr %59, ptr %14, align 8, !tbaa !9
  %60 = icmp eq ptr null, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %57
  store i32 2, ptr %11, align 4, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 161, i32 noundef %62)
  br label %99

63:                                               ; preds = %57
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %12, align 8, !tbaa !9
  %68 = load ptr, ptr %14, align 8, !tbaa !9
  %69 = call i32 @hash_update(ptr noundef %67, ptr noundef %68)
  store i32 %69, ptr %11, align 4, !tbaa !5
  %70 = load i32, ptr %11, align 4, !tbaa !5
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %74

72:                                               ; preds = %66
  %73 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 163, i32 noundef %73)
  br label %99

74:                                               ; preds = %66
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %12, align 8, !tbaa !9
  %79 = load ptr, ptr %13, align 8, !tbaa !9
  %80 = call i32 @hash_update(ptr noundef %78, ptr noundef %79)
  store i32 %80, ptr %11, align 4, !tbaa !5
  %81 = load i32, ptr %11, align 4, !tbaa !5
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %85

83:                                               ; preds = %77
  %84 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 164, i32 noundef %84)
  br label %99

85:                                               ; preds = %77
  br label %86

86:                                               ; preds = %85
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %12, align 8, !tbaa !9
  %90 = load ptr, ptr %10, align 8, !tbaa !9
  %91 = call i32 @hash_final(ptr noundef %89, ptr noundef %90)
  store i32 %91, ptr %11, align 4, !tbaa !5
  %92 = load i32, ptr %11, align 4, !tbaa !5
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %96

94:                                               ; preds = %88
  %95 = load i32, ptr %11, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 165, i32 noundef %95)
  br label %99

96:                                               ; preds = %88
  br label %97

97:                                               ; preds = %96
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98, %94, %83, %72, %61, %51, %40, %31, %22
  %100 = load ptr, ptr %12, align 8, !tbaa !9
  call void @hash_free(ptr noundef %100)
  %101 = load ptr, ptr %14, align 8, !tbaa !9
  call void @ba_free(ptr noundef %101)
  %102 = load ptr, ptr %13, align 8, !tbaa !9
  call void @ba_free(ptr noundef %102)
  %103 = load i32, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret i32 %103
}

; 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: nounwind uwtable
declare hidden ptr @iso15946_get_not_zero(ptr noundef) #0

declare ptr @hash_alloc(i32 noundef) #2

declare i32 @hash_update(ptr noundef, ptr noundef) #2

declare ptr @ba_alloc_from_uint8(ptr noundef, i64 noundef) #2

declare i32 @hash_final(ptr noundef, ptr noundef) #2

declare void @hash_free(ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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}


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

@.str = external hidden unnamed_addr constant [23 x i8], align 1
@__const.iso15946_generate_secretc.COUNTER = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @iso15946_encode_sharedinfo(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

declare void @ba_free(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @iso15946_generate_secretc(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca ptr, align 8
  %7 = alloca [4 x i8], align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %8 = load i32, ptr @__const.iso15946_generate_secretc.COUNTER, align 1
  store i32 %8, ptr %7, align 4
  %9 = call i32 @iso15946_encode_sharedinfo(ptr noundef %1, ptr noundef %2, i32 noundef 256, ptr noundef nonnull %6)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %11, label %10

10:                                               ; preds = %5
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 142, i32 noundef %9) #3
  br label %36

11:                                               ; preds = %5
  %12 = call ptr @iso15946_get_not_zero(ptr noundef %3)
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 145, i32 noundef 2) #3
  br label %36

15:                                               ; preds = %11
  %16 = call ptr @hash_alloc(i32 noundef %0) #3
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 149, i32 noundef 2) #3
  br label %36

19:                                               ; preds = %15
  %20 = call i32 @hash_update(ptr noundef nonnull %16, ptr noundef nonnull %12) #3
  %.not40 = icmp eq i32 %20, 0
  br i1 %.not40, label %22, label %21

21:                                               ; preds = %19
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 150, i32 noundef %20) #3
  br label %36

22:                                               ; preds = %19
  call void @ba_free(ptr noundef nonnull %12) #3
  %23 = call ptr @ba_alloc_from_uint8(ptr noundef nonnull %7, i64 noundef 4) #3
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 161, i32 noundef 2) #3
  br label %36

26:                                               ; preds = %22
  %27 = call i32 @hash_update(ptr noundef nonnull %16, ptr noundef nonnull %23) #3
  %.not41 = icmp eq i32 %27, 0
  br i1 %.not41, label %29, label %28

28:                                               ; preds = %26
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 163, i32 noundef %27) #3
  br label %36

29:                                               ; preds = %26
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i32 @hash_update(ptr noundef nonnull %16, ptr noundef %30) #3
  %.not42 = icmp eq i32 %31, 0
  br i1 %.not42, label %33, label %32

32:                                               ; preds = %29
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 164, i32 noundef %31) #3
  br label %36

33:                                               ; preds = %29
  %34 = call i32 @hash_final(ptr noundef nonnull %16, ptr noundef %4) #3
  %.not43 = icmp eq i32 %34, 0
  br i1 %.not43, label %36, label %35

35:                                               ; preds = %33
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 165, i32 noundef %34) #3
  br label %36

36:                                               ; preds = %33, %35, %32, %28, %25, %21, %18, %14, %10
  %.028 = phi i32 [ %9, %10 ], [ 2, %14 ], [ 2, %18 ], [ %20, %21 ], [ 2, %25 ], [ %27, %28 ], [ %31, %32 ], [ %34, %35 ], [ 0, %33 ]
  %.027 = phi ptr [ null, %10 ], [ null, %14 ], [ null, %18 ], [ %16, %21 ], [ %16, %25 ], [ %16, %28 ], [ %16, %32 ], [ %16, %35 ], [ %16, %33 ]
  %.0 = phi ptr [ null, %10 ], [ null, %14 ], [ %12, %18 ], [ %12, %21 ], [ null, %25 ], [ %23, %28 ], [ %23, %32 ], [ %23, %35 ], [ %23, %33 ]
  call void @hash_free(ptr noundef %.027) #3
  call void @ba_free(ptr noundef %.0) #3
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ba_free(ptr noundef %37) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i32 %.028
}

; Function Attrs: nounwind uwtable
declare hidden ptr @iso15946_get_not_zero(ptr noundef) local_unnamed_addr #0

declare ptr @hash_alloc(i32 noundef) local_unnamed_addr #2

declare i32 @hash_update(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @ba_alloc_from_uint8(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @hash_final(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @hash_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass