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

; 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

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

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

20:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %62

21:                                               ; preds = %4
  %22 = getelementptr inbounds %class.Crypto, ptr %13, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = call ptr @EVP_aes_256_cbc()
  %25 = getelementptr inbounds %class.Crypto, ptr %13, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds %class.Crypto, ptr %13, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = call i32 @EVP_DecryptInit_ex(ptr noundef %23, ptr noundef %24, ptr noundef null, ptr noundef %26, ptr noundef %28)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %21
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %62

32:                                               ; preds = %21
  %33 = getelementptr inbounds %class.Crypto, ptr %13, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = trunc i64 %38 to i32
  %40 = call i32 @EVP_DecryptUpdate(ptr noundef %34, ptr noundef %36, ptr noundef %11, ptr noundef %37, i32 noundef %39)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %32
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %62

43:                                               ; preds = %32
  %44 = load i64, ptr %11, align 8, !tbaa !9
  %45 = load i64, ptr %10, align 8, !tbaa !9
  %46 = add i64 %45, %44
  store i64 %46, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds %class.Crypto, ptr %13, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = call i32 @EVP_DecryptFinal_ex(ptr noundef %48, ptr noundef %52, ptr noundef %11)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %56, label %55

55:                                               ; preds = %43
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %62

56:                                               ; preds = %43
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = add i64 %58, %57
  store i64 %59, ptr %10, align 8, !tbaa !9
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = trunc i64 %60 to i32
  store i32 %61, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %62

62:                                               ; preds = %56, %55, %42, %31, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %63 = load i32, ptr %5, align 4
  ret i32 %63
}

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

declare i32 @EVP_DecryptFinal_ex(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 32}
!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 40}
!14 = !{!12, !6, i64 48}


; 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

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

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

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = tail call ptr @EVP_aes_256_cbc()
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = tail call i32 @EVP_DecryptInit_ex(ptr noundef %10, ptr noundef %11, ptr noundef null, ptr noundef %13, ptr noundef %15)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %32, label %17

17:                                               ; preds = %8
  %18 = load ptr, ptr %9, align 8, !tbaa !11
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  %20 = trunc i64 %2 to i32
  %21 = call i32 @EVP_DecryptUpdate(ptr noundef %18, ptr noundef %19, ptr noundef nonnull %5, ptr noundef %1, i32 noundef %20)
  %.not12 = icmp eq i32 %21, 0
  br i1 %.not12, label %32, label %22

22:                                               ; preds = %17
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !11
  %25 = load ptr, ptr %3, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %25, i64 %23
  %27 = call i32 @EVP_DecryptFinal_ex(ptr noundef %24, ptr noundef %26, ptr noundef nonnull %5)
  %.not13 = icmp eq i32 %27, 0
  br i1 %.not13, label %32, label %28

28:                                               ; preds = %22
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = add i64 %29, %23
  %31 = trunc i64 %30 to i32
  br label %32

32:                                               ; preds = %22, %17, %8, %4, %28
  %.0 = phi i32 [ %31, %28 ], [ -1, %4 ], [ -1, %8 ], [ -1, %17 ], [ -1, %22 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.0
}

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

declare i32 @EVP_DecryptFinal_ex(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 32}
!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 40}
!14 = !{!12, !10, i64 48}


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