; LLVM IR from shanet/Crypto-Example :: Crypto.ll (ZN6Crypto10rsaDecryptEPhmS0_mS0_mPS0_)

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

%class.Crypto = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64 }

declare ptr @EVP_aes_256_cbc() #0

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6Crypto10rsaDecryptEPhmS0_mS0_mPS0_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7) #3 align 2 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store i64 %2, ptr %12, align 8, !tbaa !9
  store ptr %3, ptr %13, align 8, !tbaa !5
  store i64 %4, ptr %14, align 8, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !5
  store i64 %6, ptr %16, align 8, !tbaa !9
  store ptr %7, ptr %17, align 8, !tbaa !5
  %22 = load ptr, ptr %10, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  store i64 0, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  store i64 0, ptr %19, align 8, !tbaa !9
  %23 = load i64, ptr %12, align 8, !tbaa !9
  %24 = load i64, ptr %16, align 8, !tbaa !9
  %25 = add i64 %23, %24
  %26 = call noalias ptr @malloc(i64 noundef %25) #5
  %27 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %26, ptr %27, align 8, !tbaa !5
  %28 = load ptr, ptr %17, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %8
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %79

32:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %33 = getelementptr inbounds %class.Crypto, ptr %22, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  store ptr %34, ptr %21, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.Crypto, ptr %22, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = call ptr @EVP_aes_256_cbc()
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = load i64, ptr %14, align 8, !tbaa !9
  %40 = trunc i64 %39 to i32
  %41 = load ptr, ptr %15, align 8, !tbaa !5
  %42 = load ptr, ptr %21, align 8, !tbaa !5
  %43 = call i32 @EVP_OpenInit(ptr noundef %36, ptr noundef %37, ptr noundef %38, i32 noundef %40, ptr noundef %41, ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %32
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %78

46:                                               ; preds = %32
  %47 = getelementptr inbounds %class.Crypto, ptr %22, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %17, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load i64, ptr %18, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %12, align 8, !tbaa !9
  %55 = trunc i64 %54 to i32
  %56 = call i32 @EVP_DecryptUpdate(ptr noundef %48, ptr noundef %52, ptr noundef %19, ptr noundef %53, i32 noundef %55)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %59, label %58

58:                                               ; preds = %46
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %78

59:                                               ; preds = %46
  %60 = load i64, ptr %19, align 8, !tbaa !9
  %61 = load i64, ptr %18, align 8, !tbaa !9
  %62 = add i64 %61, %60
  store i64 %62, ptr %18, align 8, !tbaa !9
  %63 = getelementptr inbounds %class.Crypto, ptr %22, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !13
  %65 = load ptr, ptr %17, align 8, !tbaa !5
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = load i64, ptr %18, align 8, !tbaa !9
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  %69 = call i32 @EVP_OpenFinal(ptr noundef %64, ptr noundef %68, ptr noundef %19)
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %72, label %71

71:                                               ; preds = %59
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %78

72:                                               ; preds = %59
  %73 = load i64, ptr %19, align 8, !tbaa !9
  %74 = load i64, ptr %18, align 8, !tbaa !9
  %75 = add i64 %74, %73
  store i64 %75, ptr %18, align 8, !tbaa !9
  %76 = load i64, ptr %18, align 8, !tbaa !9
  %77 = trunc i64 %76 to i32
  store i32 %77, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %78

78:                                               ; preds = %72, %71, %58, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  br label %79

79:                                               ; preds = %78, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  %80 = load i32, ptr %9, align 4
  ret i32 %80
}

declare i32 @EVP_OpenInit(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #0

declare i32 @EVP_DecryptUpdate(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #0

declare i32 @EVP_OpenFinal(ptr noundef, ptr noundef, ptr noundef) #0

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS6Crypto", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 64}
!13 = !{!12, !6, i64 24}


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

declare ptr @EVP_aes_256_cbc() 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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6Crypto10rsaDecryptEPhmS0_mS0_mPS0_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr nocapture noundef %7) local_unnamed_addr #3 align 2 {
  %9 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  %10 = add i64 %6, %2
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #5
  store ptr %11, ptr %7, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %35, label %13

13:                                               ; preds = %8
  %14 = load ptr, ptr %0, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = tail call ptr @EVP_aes_256_cbc()
  %18 = trunc i64 %4 to i32
  %19 = tail call i32 @EVP_OpenInit(ptr noundef %16, ptr noundef %17, ptr noundef %3, i32 noundef %18, ptr noundef %5, ptr noundef %14)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %35, label %20

20:                                               ; preds = %13
  %21 = load ptr, ptr %15, align 8, !tbaa !13
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  %23 = trunc i64 %2 to i32
  %24 = call i32 @EVP_DecryptUpdate(ptr noundef %21, ptr noundef %22, ptr noundef nonnull %9, ptr noundef %1, i32 noundef %23)
  %.not18 = icmp eq i32 %24, 0
  br i1 %.not18, label %35, label %25

25:                                               ; preds = %20
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %15, align 8, !tbaa !13
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %28, i64 %26
  %30 = call i32 @EVP_OpenFinal(ptr noundef %27, ptr noundef %29, ptr noundef nonnull %9)
  %.not19 = icmp eq i32 %30, 0
  br i1 %.not19, label %35, label %31

31:                                               ; preds = %25
  %32 = load i64, ptr %9, align 8, !tbaa !5
  %33 = add i64 %32, %26
  %34 = trunc i64 %33 to i32
  br label %35

35:                                               ; preds = %31, %13, %20, %25, %8
  %.1 = phi i32 [ -1, %8 ], [ %34, %31 ], [ -1, %13 ], [ -1, %20 ], [ -1, %25 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  ret i32 %.1
}

declare i32 @EVP_OpenInit(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @EVP_DecryptUpdate(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @EVP_OpenFinal(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress 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 }
attributes #5 = { nounwind allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS6Crypto", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!12, !10, i64 24}


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