; LLVM IR from ARMmbed/mbed-crypto :: library (psa_crypto)

; 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.psa_cipher_operation_s = type { i32, i8, i8, i8, %union.anon.2 }
%union.anon.2 = type { %struct.mbedtls_cipher_context_t }
%struct.mbedtls_cipher_context_t = type { ptr, i32, i32, ptr, ptr, [16 x i8], i64, [16 x i8], i64, ptr, ptr }

; 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mbedtls_to_psa_error(i32 noundef) #2

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @psa_cipher_abort(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_cipher_finish(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #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 i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca [16 x i8], align 16
  %13 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 -132, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 -24704, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %14, i32 0, i32 1
  %16 = load i8, ptr %15, align 4
  %17 = and i8 %16, 1
  %18 = zext i8 %17 to i32
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %4
  store i32 -137, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

21:                                               ; preds = %4
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %22, i32 0, i32 1
  %24 = load i8, ptr %23, align 4
  %25 = lshr i8 %24, 1
  %26 = and i8 %25, 1
  %27 = zext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %38

29:                                               ; preds = %21
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %30, i32 0, i32 1
  %32 = load i8, ptr %31, align 4
  %33 = lshr i8 %32, 2
  %34 = and i8 %33, 1
  %35 = zext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %29
  store i32 -137, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

38:                                               ; preds = %29, %21
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %39, i32 0, i32 4
  %41 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %56

44:                                               ; preds = %38
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !14
  %48 = icmp eq i32 %47, 73400576
  br i1 %48, label %49, label %56

49:                                               ; preds = %44
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %50, i32 0, i32 4
  %52 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %51, i32 0, i32 6
  %53 = load i64, ptr %52, align 8, !tbaa !13
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %49
  store i32 -135, ptr %10, align 4, !tbaa !11
  br label %89

56:                                               ; preds = %49, %44, %38
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %57, i32 0, i32 4
  %59 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = call i32 @mbedtls_cipher_finish(ptr noundef %58, ptr noundef %59, ptr noundef %60)
  store i32 %61, ptr %11, align 4, !tbaa !11
  %62 = load i32, ptr %11, align 4, !tbaa !11
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %56
  %65 = load i32, ptr %11, align 4, !tbaa !11
  %66 = call i32 @mbedtls_to_psa_error(i32 noundef %65)
  store i32 %66, ptr %10, align 4, !tbaa !11
  br label %89

67:                                               ; preds = %56
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i64, ptr %68, align 8, !tbaa !9
  %70 = icmp eq i64 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %67
  br label %84

72:                                               ; preds = %67
  %73 = load i64, ptr %8, align 8, !tbaa !9
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = icmp uge i64 %73, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %72
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load i64, ptr %80, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %78, ptr align 16 %79, i64 %81, i1 false)
  br label %83

82:                                               ; preds = %72
  store i32 -138, ptr %10, align 4, !tbaa !11
  br label %89

83:                                               ; preds = %77
  br label %84

84:                                               ; preds = %83, %71
  %85 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %85, i64 noundef 16)
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = call i32 @psa_cipher_abort(ptr noundef %86)
  store i32 %87, ptr %10, align 4, !tbaa !11
  %88 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %88, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

89:                                               ; preds = %82, %64, %55
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %90, align 8, !tbaa !9
  %91 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %91, i64 noundef 16)
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = call i32 @psa_cipher_abort(ptr noundef %92)
  %94 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %94, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

95:                                               ; preds = %89, %84, %37, %20
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %96 = load i32, ptr %5, align 4
  ret i32 %96
}

declare i32 @mbedtls_cipher_finish(ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 0}
!15 = !{!"psa_cipher_operation_s", !12, i64 0, !12, i64 4, !12, i64 4, !12, i64 4, !7, i64 5, !7, i64 6, !7, i64 8}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mbedtls_to_psa_error(i32 noundef) local_unnamed_addr #2

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_cipher_finish(ptr noundef %0, ptr nocapture noundef writeonly %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i8, ptr %6, align 4
  %8 = and i8 %7, 1
  %.not = icmp eq i8 %8, 0
  %9 = and i8 %7, 6
  %or.cond = icmp eq i8 %9, 2
  %or.cond28 = or i1 %.not, %or.cond
  br i1 %or.cond28, label %34, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = getelementptr inbounds i8, ptr %0, i64 20
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %21

15:                                               ; preds = %10
  %16 = load i32, ptr %0, align 8, !tbaa !8
  %17 = icmp eq i32 %16, 73400576
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %.not25 = icmp eq i64 %20, 0
  br i1 %.not25, label %21, label %32

21:                                               ; preds = %18, %15, %10
  %22 = call i32 @mbedtls_cipher_finish(ptr noundef nonnull %11, ptr noundef nonnull %5, ptr noundef %3) #4
  %.not26 = icmp eq i32 %22, 0
  br i1 %.not26, label %25, label %23

23:                                               ; preds = %21
  %24 = call i32 @mbedtls_to_psa_error(i32 noundef %22)
  br label %32

25:                                               ; preds = %21
  %26 = load i64, ptr %3, align 8, !tbaa !11
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %30, label %28

28:                                               ; preds = %25
  %.not27 = icmp ugt i64 %26, %2
  br i1 %.not27, label %32, label %29

29:                                               ; preds = %28
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr nonnull align 16 %5, i64 %26, i1 false)
  br label %30

30:                                               ; preds = %25, %29
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %5, i64 noundef 16) #4
  %31 = call i32 @psa_cipher_abort(ptr noundef nonnull %0)
  br label %34

32:                                               ; preds = %28, %18, %23
  %.0 = phi i32 [ %24, %23 ], [ -135, %18 ], [ -138, %28 ]
  store i64 0, ptr %3, align 8, !tbaa !11
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %5, i64 noundef 16) #4
  %33 = call i32 @psa_cipher_abort(ptr noundef nonnull %0)
  br label %34

34:                                               ; preds = %4, %32, %30
  %.020 = phi i32 [ %.0, %32 ], [ %31, %30 ], [ -137, %4 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  ret i32 %.020
}

declare i32 @mbedtls_cipher_finish(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"psa_cipher_operation_s", !10, i64 0, !10, i64 4, !10, i64 4, !10, i64 4, !6, i64 5, !6, i64 6, !6, i64 8}
!10 = !{!"int", !6, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !6, i64 0}


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