; LLVM IR from machinefi/psa-crypto-esp32 :: psa_layer (psa_crypto_porting)

; 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.iotex_cipher_context_t = type { ptr, i32, i32, ptr, ptr, [16 x i8], i64, [16 x i8], i64, ptr, ptr }
%struct.iotex_cipher_info_t = type { i32, i32, i32, ptr, i32, i32, i32, 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: 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: inlinehint nounwind uwtable
define dso_local i32 @iotex_cipher_set_iv(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

13:                                               ; preds = %3
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %20

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

20:                                               ; preds = %16, %13
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

26:                                               ; preds = %20
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = icmp ugt i64 %27, 16
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 -24704, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

30:                                               ; preds = %26
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %33, i32 0, i32 5
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = and i32 %35, 1
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %30
  %39 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %39, ptr %8, align 8, !tbaa !9
  br label %52

40:                                               ; preds = %30
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %43, i32 0, i32 4
  %45 = load i32, ptr %44, align 8, !tbaa !16
  %46 = zext i32 %45 to i64
  store i64 %46, ptr %8, align 8, !tbaa !9
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = icmp ugt i64 %47, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %40
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

51:                                               ; preds = %40
  br label %52

52:                                               ; preds = %51, %38
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %64

55:                                               ; preds = %52
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %56, i32 0, i32 7
  %58 = getelementptr inbounds [16 x i8], ptr %57, i64 0, i64 0
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %58, ptr align 1 %59, i64 %60, i1 false)
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %62, i32 0, i32 8
  store i64 %61, ptr %63, align 8, !tbaa !17
  br label %64

64:                                               ; preds = %55, %52
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

65:                                               ; preds = %64, %50, %29, %25, %19, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { 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, !6, i64 0}
!12 = !{!"iotex_cipher_context_t", !6, i64 0, !13, i64 8, !13, i64 12, !6, i64 16, !6, i64 24, !7, i64 32, !10, i64 48, !7, i64 56, !10, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 28}
!15 = !{!"iotex_cipher_info_t", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !6, i64 40}
!16 = !{!15, !13, i64 24}
!17 = !{!12, !10, i64 72}


; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: inlinehint mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -24832, 1) i32 @iotex_cipher_set_iv(ptr noundef %0, ptr noundef readonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %26, label %5

5:                                                ; preds = %3
  %6 = icmp ne i64 %2, 0
  %7 = icmp eq ptr %1, null
  %or.cond = and i1 %7, %6
  br i1 %or.cond, label %26, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %26, label %11

11:                                               ; preds = %8
  %12 = icmp ugt i64 %2, 16
  br i1 %12, label %26, label %13

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %9, i64 28
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = and i32 %15, 1
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %17, label %22

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %9, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = zext i32 %19 to i64
  %21 = icmp ugt i64 %20, %2
  br i1 %21, label %26, label %22

22:                                               ; preds = %13, %17
  %.0 = phi i64 [ %20, %17 ], [ %2, %13 ]
  %.not22 = icmp eq i64 %.0, 0
  br i1 %.not22, label %26, label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %24, ptr align 1 %1, i64 %.0, i1 false)
  %25 = getelementptr inbounds i8, ptr %0, i64 72
  store i64 %.0, ptr %25, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %22, %23, %17, %11, %8, %5, %3
  %.017 = phi i32 [ -24832, %3 ], [ -24832, %5 ], [ -24832, %8 ], [ -24704, %11 ], [ -24832, %17 ], [ 0, %23 ], [ 0, %22 ]
  ret i32 %.017
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"iotex_cipher_context_t", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !8, i64 32, !11, i64 48, !8, i64 56, !11, i64 72, !7, i64 80, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !10, i64 28}
!13 = !{!"iotex_cipher_info_t", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40}
!14 = !{!13, !10, i64 24}
!15 = !{!6, !11, i64 72}


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