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

declare void @mbedtls_cipher_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_cipher_abort(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %4, i32 0, i32 0
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 0, ptr %2, align 4
  br label %40

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = and i32 %12, 2130706432
  %14 = icmp eq i32 %13, 67108864
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  store i32 -137, ptr %2, align 4
  br label %40

16:                                               ; preds = %9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %17, i32 0, i32 4
  call void @mbedtls_cipher_free(ptr noundef %18)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %19, i32 0, i32 0
  store i32 0, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %21, i32 0, i32 1
  %23 = load i8, ptr %22, align 4
  %24 = and i8 %23, -2
  %25 = or i8 %24, 0
  store i8 %25, ptr %22, align 4
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %26, i32 0, i32 1
  %28 = load i8, ptr %27, align 4
  %29 = and i8 %28, -5
  %30 = or i8 %29, 0
  store i8 %30, ptr %27, align 4
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %31, i32 0, i32 2
  store i8 0, ptr %32, align 1, !tbaa !12
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %33, i32 0, i32 3
  store i8 0, ptr %34, align 2, !tbaa !13
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %35, i32 0, i32 1
  %37 = load i8, ptr %36, align 4
  %38 = and i8 %37, -3
  %39 = or i8 %38, 0
  store i8 %39, ptr %36, align 4
  store i32 0, ptr %2, align 4
  br label %40

40:                                               ; preds = %16, %15, %8
  %41 = load i32, ptr %2, align 4
  ret i32 %41
}

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

!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 0}
!10 = !{!"psa_cipher_operation_s", !11, i64 0, !11, i64 4, !11, i64 4, !11, i64 4, !7, i64 5, !7, i64 6, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !7, i64 5}
!13 = !{!10, !7, i64 6}


; 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 void @mbedtls_cipher_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -137, 1) i32 @psa_cipher_abort(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %14, label %4

4:                                                ; preds = %1
  %5 = and i32 %2, 2130706432
  %6 = icmp eq i32 %5, 67108864
  br i1 %6, label %7, label %14

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @mbedtls_cipher_free(ptr noundef nonnull %8) #2
  store i32 0, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i8, ptr %9, align 4
  %11 = getelementptr inbounds i8, ptr %0, i64 5
  store i8 0, ptr %11, align 1, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %0, i64 6
  store i8 0, ptr %12, align 2, !tbaa !11
  %13 = and i8 %10, -8
  store i8 %13, ptr %9, align 4
  br label %14

14:                                               ; preds = %4, %1, %7
  %.0 = phi i32 [ 0, %7 ], [ 0, %1 ], [ -137, %4 ]
  ret i32 %.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 = { 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 = !{!"psa_cipher_operation_s", !7, i64 0, !7, i64 4, !7, i64 4, !7, i64 4, !8, i64 5, !8, i64 6, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !8, i64 5}
!11 = !{!6, !8, i64 6}


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