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

; 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.plaintext_t = type { ptr, i64, ptr, i64 }

@peacemakr_global_calloc = external global ptr, align 8

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

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

declare i64 @buffer_get_size(ptr noundef) #1

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @peacemakr_extract_plaintext_blob(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call ptr @ciphertext_blob_ciphertext(ptr noundef %7)
  store ptr %8, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %31

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call i64 @buffer_get_size(ptr noundef %12)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.plaintext_t, ptr %14, i32 0, i32 1
  store i64 %13, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.plaintext_t, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = call ptr %16(i64 noundef %19, i64 noundef 1)
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.plaintext_t, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !12
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.plaintext_t, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call ptr @buffer_get_bytes(ptr noundef %26, ptr noundef null)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.plaintext_t, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 1 %27, i64 %30, i1 false)
  br label %36

31:                                               ; preds = %2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.plaintext_t, ptr %32, i32 0, i32 1
  store i64 0, ptr %33, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.plaintext_t, ptr %34, i32 0, i32 0
  store ptr null, ptr %35, align 8, !tbaa !12
  br label %36

36:                                               ; preds = %31, %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = call ptr @ciphertext_blob_aad(ptr noundef %37)
  store ptr %38, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %61

41:                                               ; preds = %36
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i64 @buffer_get_size(ptr noundef %42)
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.plaintext_t, ptr %44, i32 0, i32 3
  store i64 %43, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.plaintext_t, ptr %47, i32 0, i32 3
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = call ptr %46(i64 noundef %49, i64 noundef 1)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.plaintext_t, ptr %51, i32 0, i32 2
  store ptr %50, ptr %52, align 8, !tbaa !14
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.plaintext_t, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = call ptr @buffer_get_bytes(ptr noundef %56, ptr noundef null)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.plaintext_t, ptr %58, i32 0, i32 3
  %60 = load i64, ptr %59, align 8, !tbaa !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %55, ptr align 1 %57, i64 %60, i1 false)
  br label %66

61:                                               ; preds = %36
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.plaintext_t, ptr %62, i32 0, i32 3
  store i64 0, ptr %63, align 8, !tbaa !13
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.plaintext_t, ptr %64, i32 0, i32 2
  store ptr null, ptr %65, align 8, !tbaa !14
  br label %66

66:                                               ; preds = %61, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i1 true
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @ciphertext_blob_ciphertext(ptr noundef) #3

declare ptr @buffer_get_bytes(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ciphertext_blob_aad(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !11, i64 24}
!14 = !{!10, !6, i64 16}


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

@peacemakr_global_calloc = external local_unnamed_addr global ptr, align 8

declare i64 @buffer_get_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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) #1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @peacemakr_extract_plaintext_blob(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #2 {
  %3 = tail call ptr @ciphertext_blob_ciphertext(ptr noundef %0)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %11, label %4

4:                                                ; preds = %2
  %5 = tail call i64 @buffer_get_size(ptr noundef nonnull %3) #4
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %5, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !11
  %8 = tail call ptr %7(i64 noundef %5, i64 noundef 1) #4
  store ptr %8, ptr %1, align 8, !tbaa !12
  %9 = tail call ptr @buffer_get_bytes(ptr noundef nonnull %3, ptr noundef null) #4
  %10 = load i64, ptr %6, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 %9, i64 %10, i1 false)
  br label %12

11:                                               ; preds = %2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %1, i8 0, i64 16, i1 false)
  br label %12

12:                                               ; preds = %11, %4
  %13 = tail call ptr @ciphertext_blob_aad(ptr noundef %0)
  %.not23 = icmp eq ptr %13, null
  br i1 %.not23, label %22, label %14

14:                                               ; preds = %12
  %15 = tail call i64 @buffer_get_size(ptr noundef nonnull %13) #4
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 %15, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !11
  %18 = tail call ptr %17(i64 noundef %15, i64 noundef 1) #4
  %19 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %18, ptr %19, align 8, !tbaa !14
  %20 = tail call ptr @buffer_get_bytes(ptr noundef nonnull %13, ptr noundef null) #4
  %21 = load i64, ptr %16, align 8, !tbaa !13
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %18, ptr align 1 %20, i64 %21, i1 false)
  br label %24

22:                                               ; preds = %12
  %23 = getelementptr inbounds i8, ptr %1, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %23, i8 0, i64 16, i1 false)
  br label %24

24:                                               ; preds = %22, %14
  ret i1 true
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @ciphertext_blob_ciphertext(ptr noundef) local_unnamed_addr #2

declare ptr @buffer_get_bytes(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @ciphertext_blob_aad(ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 8}
!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 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !7, i64 16}


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