; 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 }
%struct.iotex_cipher_base_t = type { i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: inlinehint nounwind uwtable
define dso_local i32 @iotex_cipher_setkey(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %15, label %12

12:                                               ; preds = %4
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %4
  store i32 -24832, ptr %5, align 4
  br label %112

16:                                               ; preds = %12
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 1
  br i1 %18, label %19, label %23

19:                                               ; preds = %16
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 -24832, ptr %5, align 4
  br label %112

23:                                               ; preds = %19, %16
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 -24832, ptr %5, align 4
  br label %112

29:                                               ; preds = %23
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %32, i32 0, i32 5
  %34 = load i32, ptr %33, align 4, !tbaa !14
  %35 = and i32 %34, 2
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %46

37:                                               ; preds = %29
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = icmp ne i32 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i32 -24832, ptr %5, align 4
  br label %112

46:                                               ; preds = %37, %29
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %48, i32 0, i32 1
  store i32 %47, ptr %49, align 8, !tbaa !17
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %51, i32 0, i32 2
  store i32 %50, ptr %52, align 4, !tbaa !18
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = icmp eq i32 1, %53
  br i1 %54, label %76, label %55

55:                                               ; preds = %46
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !19
  %61 = icmp eq i32 3, %60
  br i1 %61, label %76, label %62

62:                                               ; preds = %55
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !19
  %68 = icmp eq i32 4, %67
  br i1 %68, label %76, label %69

69:                                               ; preds = %62
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !19
  %75 = icmp eq i32 5, %74
  br i1 %75, label %76, label %92

76:                                               ; preds = %69, %62, %55, %46
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !11
  %80 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %79, i32 0, i32 7
  %81 = load ptr, ptr %80, align 8, !tbaa !20
  %82 = getelementptr inbounds %struct.iotex_cipher_base_t, ptr %81, i32 0, i32 4
  %83 = load ptr, ptr %82, align 8, !tbaa !21
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %84, i32 0, i32 9
  %86 = load ptr, ptr %85, align 8, !tbaa !23
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %88, i32 0, i32 1
  %90 = load i32, ptr %89, align 8, !tbaa !17
  %91 = call i32 %83(ptr noundef %86, ptr noundef %87, i32 noundef %90)
  store i32 %91, ptr %5, align 4
  br label %112

92:                                               ; preds = %69
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = icmp eq i32 0, %93
  br i1 %94, label %95, label %111

95:                                               ; preds = %92
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %96, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !11
  %99 = getelementptr inbounds %struct.iotex_cipher_info_t, ptr %98, i32 0, i32 7
  %100 = load ptr, ptr %99, align 8, !tbaa !20
  %101 = getelementptr inbounds %struct.iotex_cipher_base_t, ptr %100, i32 0, i32 5
  %102 = load ptr, ptr %101, align 8, !tbaa !24
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %103, i32 0, i32 9
  %105 = load ptr, ptr %104, align 8, !tbaa !23
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.iotex_cipher_context_t, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 8, !tbaa !17
  %110 = call i32 %102(ptr noundef %105, ptr noundef %106, i32 noundef %109)
  store i32 %110, ptr %5, align 4
  br label %112

111:                                              ; preds = %92
  store i32 -24832, ptr %5, align 4
  br label %112

112:                                              ; preds = %111, %95, %76, %45, %28, %22, %15
  %113 = load i32, ptr %5, align 4
  ret i32 %113
}

attributes #0 = { 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" }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"iotex_cipher_context_t", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !7, i64 32, !13, i64 48, !7, i64 56, !13, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !10, i64 28}
!15 = !{!"iotex_cipher_info_t", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40}
!16 = !{!15, !10, i64 8}
!17 = !{!12, !10, i64 8}
!18 = !{!12, !10, i64 12}
!19 = !{!15, !10, i64 4}
!20 = !{!15, !6, i64 40}
!21 = !{!22, !6, i64 32}
!22 = !{!"iotex_cipher_base_t", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!23 = !{!12, !6, i64 80}
!24 = !{!22, !6, i64 40}


; 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: inlinehint nounwind uwtable
define dso_local i32 @iotex_cipher_setkey(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  %or.cond3 = icmp ugt i32 %3, 1
  %or.cond33 = or i1 %or.cond, %or.cond3
  br i1 %or.cond33, label %32, label %7

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

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %8, i64 28
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = and i32 %12, 2
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %8, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %.not = icmp eq i32 %17, %2
  br i1 %.not, label %18, label %32

18:                                               ; preds = %15, %10
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %2, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %3, ptr %20, align 4, !tbaa !16
  %21 = icmp eq i32 %3, 1
  br i1 %21, label %.sink.split, label %22

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %8, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %.off = add i32 %24, -3
  %switch = icmp ult i32 %.off, 3
  %spec.select = select i1 %switch, i64 32, i64 40
  br label %.sink.split

.sink.split:                                      ; preds = %22, %18
  %.sink37 = phi i64 [ 32, %18 ], [ %spec.select, %22 ]
  %25 = getelementptr inbounds i8, ptr %8, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %26, i64 %.sink37
  %28 = load ptr, ptr %27, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %0, i64 80
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %31 = tail call i32 %28(ptr noundef %30, ptr noundef nonnull %1, i32 noundef %2) #1
  br label %32

32:                                               ; preds = %.sink.split, %15, %7, %4
  %.0 = phi i32 [ -24832, %4 ], [ -24832, %7 ], [ -24832, %15 ], [ %31, %.sink.split ]
  ret i32 %.0
}

attributes #0 = { 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 #1 = { 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 = !{!"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 8}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !10, i64 12}
!17 = !{!13, !10, i64 4}
!18 = !{!13, !7, i64 40}
!19 = !{!7, !7, i64 0}
!20 = !{!6, !7, i64 80}


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