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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_cipher_update(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i64 %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 -110, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %6
  store i32 -137, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %71

23:                                               ; preds = %6
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %27 = and i32 %26, 2139095040
  %28 = icmp eq i32 %27, 75497472
  br i1 %28, label %46, label %29

29:                                               ; preds = %23
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %30, i32 0, i32 4
  %32 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %31, i32 0, i32 6
  %33 = load i64, ptr %32, align 8, !tbaa !15
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = add i64 %33, %34
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %36, i32 0, i32 3
  %38 = load i8, ptr %37, align 2, !tbaa !16
  %39 = zext i8 %38 to i64
  %40 = udiv i64 %35, %39
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %41, i32 0, i32 3
  %43 = load i8, ptr %42, align 2, !tbaa !16
  %44 = zext i8 %43 to i64
  %45 = mul i64 %40, %44
  store i64 %45, ptr %16, align 8, !tbaa !9
  br label %48

46:                                               ; preds = %23
  %47 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %47, ptr %16, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %46, %29
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = load i64, ptr %16, align 8, !tbaa !9
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %48
  store i32 -138, ptr %14, align 4, !tbaa !11
  br label %63

53:                                               ; preds = %48
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.psa_cipher_operation_s, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = load i64, ptr %10, align 8, !tbaa !9
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = call i32 @mbedtls_cipher_update(ptr noundef %55, ptr noundef %56, i64 noundef %57, ptr noundef %58, ptr noundef %59)
  store i32 %60, ptr %15, align 4, !tbaa !11
  %61 = load i32, ptr %15, align 4, !tbaa !11
  %62 = call i32 @mbedtls_to_psa_error(i32 noundef %61)
  store i32 %62, ptr %14, align 4, !tbaa !11
  br label %63

63:                                               ; preds = %53, %52
  %64 = load i32, ptr %14, align 4, !tbaa !11
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %69

66:                                               ; preds = %63
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = call i32 @psa_cipher_abort(ptr noundef %67)
  br label %69

69:                                               ; preds = %66, %63
  %70 = load i32, ptr %14, align 4, !tbaa !11
  store i32 %70, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %71

71:                                               ; preds = %69, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %72 = load i32, ptr %7, align 4
  ret i32 %72
}

declare i32 @mbedtls_cipher_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 = !{!14, !12, i64 0}
!14 = !{!"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}
!15 = !{!7, !7, i64 0}
!16 = !{!14, !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"

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_cipher_update(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %28, label %9

9:                                                ; preds = %6
  %10 = and i32 %7, 2139095040
  %11 = icmp eq i32 %10, 75497472
  br i1 %11, label %21, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  %14 = load i64, ptr %13, align 8, !tbaa !10
  %.fr21 = freeze i64 %14
  %15 = add i64 %.fr21, %2
  %16 = getelementptr inbounds i8, ptr %0, i64 6
  %17 = load i8, ptr %16, align 2, !tbaa !11
  %18 = zext i8 %17 to i64
  %19 = urem i64 %15, %18
  %20 = sub nuw i64 %15, %19
  br label %21

21:                                               ; preds = %9, %12
  %.0 = phi i64 [ %20, %12 ], [ %2, %9 ]
  %22 = icmp ugt i64 %.0, %4
  br i1 %22, label %.thread, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = tail call i32 @mbedtls_cipher_update(ptr noundef nonnull %24, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %5) #2
  %26 = tail call i32 @mbedtls_to_psa_error(i32 noundef %25)
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %28, label %.thread

.thread:                                          ; preds = %21, %23
  %.01824 = phi i32 [ %26, %23 ], [ -138, %21 ]
  %27 = tail call i32 @psa_cipher_abort(ptr noundef nonnull %0)
  br label %28

28:                                               ; preds = %23, %.thread, %6
  %.019 = phi i32 [ -137, %6 ], [ %.01824, %.thread ], [ 0, %23 ]
  ret i32 %.019
}

declare i32 @mbedtls_cipher_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 = !{!8, !8, i64 0}
!11 = !{!6, !8, i64 6}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass