; LLVM IR from peacemakr-io/peacemakr-core-crypto :: src/core/src (Sign)

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

%struct.crypto_config_t = type { i32, i32, i32, i32 }
%struct.plaintext_t = type { ptr, i64, ptr, i64 }

@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@__FUNCTION__.peacemakr_verify = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1

declare void @log_printf(ptr noundef, i32 noundef, ptr noundef, ...) #0

declare { i64, i64 } @peacemakr_key_get_config(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @peacemakr_verify(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca %struct.crypto_config_t, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_verify, i32 noundef 257, ptr noundef @.str)
  store i1 false, ptr %4, align 1
  br label %77

14:                                               ; preds = %3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_verify, i32 noundef 259, ptr noundef @.str.1)
  store i1 false, ptr %4, align 1
  br label %77

18:                                               ; preds = %14
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_verify, i32 noundef 260, ptr noundef @.str.2)
  store i1 false, ptr %4, align 1
  br label %77

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 0, ptr %8, align 1, !tbaa !9
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call ptr @ciphertext_blob_signature(ptr noundef %23)
  %25 = call i64 @buffer_get_size(ptr noundef %24)
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_verify, i32 noundef 265, ptr noundef @.str.4)
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ciphertext_blob_free(ptr noundef %28)
  store ptr null, ptr %7, align 8, !tbaa !5
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %76

29:                                               ; preds = %22
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call { i64, i64 } @peacemakr_key_get_config(ptr noundef %30)
  %32 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %33 = extractvalue { i64, i64 } %31, 0
  store i64 %33, ptr %32, align 4
  %34 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %35 = extractvalue { i64, i64 } %31, 1
  store i64 %35, ptr %34, align 4
  %36 = getelementptr inbounds %struct.crypto_config_t, ptr %10, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !11
  switch i32 %37, label %72 [
    i32 0, label %38
    i32 1, label %55
  ]

38:                                               ; preds = %29
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.plaintext_t, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.plaintext_t, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !17
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.plaintext_t, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.plaintext_t, ptr %49, i32 0, i32 3
  %51 = load i64, ptr %50, align 8, !tbaa !19
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call zeroext i1 @symmetric_verify(ptr noundef %39, ptr noundef %42, i64 noundef %45, ptr noundef %48, i64 noundef %51, ptr noundef %52)
  %54 = zext i1 %53 to i8
  store i8 %54, ptr %8, align 1, !tbaa !9
  br label %72

55:                                               ; preds = %29
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.plaintext_t, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.plaintext_t, ptr %60, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !17
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.plaintext_t, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !18
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.plaintext_t, ptr %66, i32 0, i32 3
  %68 = load i64, ptr %67, align 8, !tbaa !19
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = call zeroext i1 @asymmetric_verify(ptr noundef %56, ptr noundef %59, i64 noundef %62, ptr noundef %65, i64 noundef %68, ptr noundef %69)
  %71 = zext i1 %70 to i8
  store i8 %71, ptr %8, align 1, !tbaa !9
  br label %72

72:                                               ; preds = %55, %38, %29
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ciphertext_blob_free(ptr noundef %73)
  store ptr null, ptr %7, align 8, !tbaa !5
  %74 = load i8, ptr %8, align 1, !tbaa !9, !range !20, !noundef !21
  %75 = trunc i8 %74 to i1
  store i1 %75, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %76

76:                                               ; preds = %72, %27
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  br label %77

77:                                               ; preds = %76, %21, %17, %13
  %78 = load i1, ptr %4, align 1
  ret i1 %78
}

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

declare i64 @buffer_get_size(ptr noundef) #0

declare ptr @ciphertext_blob_signature(ptr noundef) #0

declare void @ciphertext_blob_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @symmetric_verify(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @asymmetric_verify(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #1

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

attributes #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 = { 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 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !6, i64 0, !16, i64 8, !6, i64 16, !16, i64 24}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !16, i64 8}
!18 = !{!15, !6, i64 16}
!19 = !{!15, !16, i64 24}
!20 = !{i8 0, i8 2}
!21 = !{}


; 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 [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@__FUNCTION__.peacemakr_verify = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1

declare void @log_printf(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

declare { i64, i64 } @peacemakr_key_get_config(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @peacemakr_verify(ptr noundef %0, ptr noundef readonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %3
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_verify, i32 noundef 257, ptr noundef nonnull @.str) #2
  br label %39

6:                                                ; preds = %3
  %7 = icmp eq ptr %2, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %6
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_verify, i32 noundef 259, ptr noundef nonnull @.str.1) #2
  br label %39

9:                                                ; preds = %6
  %10 = icmp eq ptr %1, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %9
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_verify, i32 noundef 260, ptr noundef nonnull @.str.2) #2
  br label %39

12:                                               ; preds = %9
  %13 = tail call ptr @ciphertext_blob_signature(ptr noundef nonnull %2) #2
  %14 = tail call i64 @buffer_get_size(ptr noundef %13) #2
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_verify, i32 noundef 265, ptr noundef nonnull @.str.4) #2
  tail call void @ciphertext_blob_free(ptr noundef nonnull %2) #2
  br label %39

17:                                               ; preds = %12
  %18 = tail call { i64, i64 } @peacemakr_key_get_config(ptr noundef nonnull %0) #2
  %19 = extractvalue { i64, i64 } %18, 0
  %.sroa.0.0.extract.trunc = trunc i64 %19 to i32
  switch i32 %.sroa.0.0.extract.trunc, label %38 [
    i32 0, label %20
    i32 1, label %29
  ]

20:                                               ; preds = %17
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %1, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %1, i64 24
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = tail call zeroext i1 @symmetric_verify(ptr noundef nonnull %0, ptr noundef %21, i64 noundef %23, ptr noundef %25, i64 noundef %27, ptr noundef nonnull %2)
  br label %38

29:                                               ; preds = %17
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %1, i64 8
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %1, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = getelementptr inbounds i8, ptr %1, i64 24
  %36 = load i64, ptr %35, align 8, !tbaa !13
  %37 = tail call zeroext i1 @asymmetric_verify(ptr noundef nonnull %0, ptr noundef %30, i64 noundef %32, ptr noundef %34, i64 noundef %36, ptr noundef nonnull %2)
  br label %38

38:                                               ; preds = %29, %20, %17
  %.020.shrunk = phi i1 [ false, %17 ], [ %37, %29 ], [ %28, %20 ]
  tail call void @ciphertext_blob_free(ptr noundef nonnull %2) #2
  br label %39

39:                                               ; preds = %16, %38, %11, %8, %5
  %.1 = phi i1 [ false, %5 ], [ false, %8 ], [ false, %11 ], [ true, %16 ], [ %.020.shrunk, %38 ]
  ret i1 %.1
}

declare i64 @buffer_get_size(ptr noundef) local_unnamed_addr #0

declare ptr @ciphertext_blob_signature(ptr noundef) local_unnamed_addr #0

declare void @ciphertext_blob_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @symmetric_verify(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @asymmetric_verify(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

attributes #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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 24}


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