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

; 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.mbedtls_cipher_context_t = type { ptr, i32, i32, ptr, ptr, [16 x i8], i64, [16 x i8], i64, ptr, ptr }
%struct.mbedtls_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: nounwind uwtable
define dso_local i32 @mbedtls_cipher_auth_decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, i64 noundef %10) #1 {
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca i64, align 8
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  store ptr %0, ptr %13, align 8, !tbaa !5
  store ptr %1, ptr %14, align 8, !tbaa !5
  store i64 %2, ptr %15, align 8, !tbaa !9
  store ptr %3, ptr %16, align 8, !tbaa !5
  store i64 %4, ptr %17, align 8, !tbaa !9
  store ptr %5, ptr %18, align 8, !tbaa !5
  store i64 %6, ptr %19, align 8, !tbaa !9
  store ptr %7, ptr %20, align 8, !tbaa !5
  store ptr %8, ptr %21, align 8, !tbaa !5
  store ptr %9, ptr %22, align 8, !tbaa !5
  store i64 %10, ptr %23, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %11
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %13, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = icmp eq i32 6, %46
  br i1 %47, label %48, label %69

48:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #3
  store i32 -110, ptr %24, align 4, !tbaa !16
  %49 = load i64, ptr %19, align 8, !tbaa !9
  %50 = load ptr, ptr %21, align 8, !tbaa !5
  store i64 %49, ptr %50, align 8, !tbaa !9
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %51, i32 0, i32 9
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = load i64, ptr %19, align 8, !tbaa !9
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = load i64, ptr %15, align 8, !tbaa !9
  %57 = load ptr, ptr %16, align 8, !tbaa !5
  %58 = load i64, ptr %17, align 8, !tbaa !9
  %59 = load ptr, ptr %22, align 8, !tbaa !5
  %60 = load i64, ptr %23, align 8, !tbaa !9
  %61 = load ptr, ptr %18, align 8, !tbaa !5
  %62 = load ptr, ptr %20, align 8, !tbaa !5
  %63 = call i32 @mbedtls_gcm_auth_decrypt(ptr noundef %53, i64 noundef %54, ptr noundef %55, i64 noundef %56, ptr noundef %57, i64 noundef %58, ptr noundef %59, i64 noundef %60, ptr noundef %61, ptr noundef %62)
  store i32 %63, ptr %24, align 4, !tbaa !16
  %64 = load i32, ptr %24, align 4, !tbaa !16
  %65 = icmp eq i32 %64, -18
  br i1 %65, label %66, label %67

66:                                               ; preds = %48
  store i32 -25344, ptr %24, align 4, !tbaa !16
  br label %67

67:                                               ; preds = %66, %48
  %68 = load i32, ptr %24, align 4, !tbaa !16
  store i32 %68, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #3
  br label %138

69:                                               ; preds = %41
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !14
  %75 = icmp eq i32 8, %74
  br i1 %75, label %76, label %97

76:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #3
  store i32 -110, ptr %25, align 4, !tbaa !16
  %77 = load i64, ptr %19, align 8, !tbaa !9
  %78 = load ptr, ptr %21, align 8, !tbaa !5
  store i64 %77, ptr %78, align 8, !tbaa !9
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %79, i32 0, i32 9
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = load i64, ptr %19, align 8, !tbaa !9
  %83 = load ptr, ptr %14, align 8, !tbaa !5
  %84 = load i64, ptr %15, align 8, !tbaa !9
  %85 = load ptr, ptr %16, align 8, !tbaa !5
  %86 = load i64, ptr %17, align 8, !tbaa !9
  %87 = load ptr, ptr %18, align 8, !tbaa !5
  %88 = load ptr, ptr %20, align 8, !tbaa !5
  %89 = load ptr, ptr %22, align 8, !tbaa !5
  %90 = load i64, ptr %23, align 8, !tbaa !9
  %91 = call i32 @mbedtls_ccm_auth_decrypt(ptr noundef %81, i64 noundef %82, ptr noundef %83, i64 noundef %84, ptr noundef %85, i64 noundef %86, ptr noundef %87, ptr noundef %88, ptr noundef %89, i64 noundef %90)
  store i32 %91, ptr %25, align 4, !tbaa !16
  %92 = load i32, ptr %25, align 4, !tbaa !16
  %93 = icmp eq i32 %92, -15
  br i1 %93, label %94, label %95

94:                                               ; preds = %76
  store i32 -25344, ptr %25, align 4, !tbaa !16
  br label %95

95:                                               ; preds = %94, %76
  %96 = load i32, ptr %25, align 4, !tbaa !16
  store i32 %96, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #3
  br label %138

97:                                               ; preds = %69
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !11
  %101 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %100, i32 0, i32 0
  %102 = load i32, ptr %101, align 8, !tbaa !18
  %103 = icmp eq i32 73, %102
  br i1 %103, label %104, label %137

104:                                              ; preds = %97
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #3
  store i32 -110, ptr %26, align 4, !tbaa !16
  %105 = load i64, ptr %15, align 8, !tbaa !9
  %106 = load ptr, ptr %13, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %106, i32 0, i32 0
  %108 = load ptr, ptr %107, align 8, !tbaa !11
  %109 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %108, i32 0, i32 4
  %110 = load i32, ptr %109, align 8, !tbaa !19
  %111 = zext i32 %110 to i64
  %112 = icmp ne i64 %105, %111
  br i1 %112, label %116, label %113

113:                                              ; preds = %104
  %114 = load i64, ptr %23, align 8, !tbaa !9
  %115 = icmp ne i64 %114, 16
  br i1 %115, label %116, label %117

116:                                              ; preds = %113, %104
  store i32 -24832, ptr %12, align 4
  store i32 1, ptr %27, align 4
  br label %136

117:                                              ; preds = %113
  %118 = load i64, ptr %19, align 8, !tbaa !9
  %119 = load ptr, ptr %21, align 8, !tbaa !5
  store i64 %118, ptr %119, align 8, !tbaa !9
  %120 = load ptr, ptr %13, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %120, i32 0, i32 9
  %122 = load ptr, ptr %121, align 8, !tbaa !17
  %123 = load i64, ptr %19, align 8, !tbaa !9
  %124 = load ptr, ptr %14, align 8, !tbaa !5
  %125 = load ptr, ptr %16, align 8, !tbaa !5
  %126 = load i64, ptr %17, align 8, !tbaa !9
  %127 = load ptr, ptr %22, align 8, !tbaa !5
  %128 = load ptr, ptr %18, align 8, !tbaa !5
  %129 = load ptr, ptr %20, align 8, !tbaa !5
  %130 = call i32 @mbedtls_chachapoly_auth_decrypt(ptr noundef %122, i64 noundef %123, ptr noundef %124, ptr noundef %125, i64 noundef %126, ptr noundef %127, ptr noundef %128, ptr noundef %129)
  store i32 %130, ptr %26, align 4, !tbaa !16
  %131 = load i32, ptr %26, align 4, !tbaa !16
  %132 = icmp eq i32 %131, -86
  br i1 %132, label %133, label %134

133:                                              ; preds = %117
  store i32 -25344, ptr %26, align 4, !tbaa !16
  br label %134

134:                                              ; preds = %133, %117
  %135 = load i32, ptr %26, align 4, !tbaa !16
  store i32 %135, ptr %12, align 4
  store i32 1, ptr %27, align 4
  br label %136

136:                                              ; preds = %134, %116
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #3
  br label %138

137:                                              ; preds = %97
  store i32 -24704, ptr %12, align 4
  br label %138

138:                                              ; preds = %137, %136, %95, %67
  %139 = load i32, ptr %12, align 4
  ret i32 %139
}

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

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

declare i32 @mbedtls_chachapoly_auth_decrypt(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr 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, !6, i64 0}
!12 = !{!"mbedtls_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 4}
!15 = !{!"mbedtls_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 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 80}
!18 = !{!15, !13, i64 0}
!19 = !{!15, !13, i64 24}


; 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
define dso_local i32 @mbedtls_cipher_auth_decrypt(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, ptr nocapture noundef writeonly %8, ptr noundef %9, i64 noundef %10) local_unnamed_addr #0 {
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !12
  switch i32 %14, label %25 [
    i32 6, label %15
    i32 8, label %20
  ]

15:                                               ; preds = %11
  store i64 %6, ptr %8, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 80
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = tail call i32 @mbedtls_gcm_auth_decrypt(ptr noundef %17, i64 noundef %6, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %9, i64 noundef %10, ptr noundef %5, ptr noundef %7) #2
  %19 = icmp eq i32 %18, -18
  %spec.store.select = select i1 %19, i32 -25344, i32 %18
  br label %39

20:                                               ; preds = %11
  store i64 %6, ptr %8, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = tail call i32 @mbedtls_ccm_auth_decrypt(ptr noundef %22, i64 noundef %6, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %7, ptr noundef %9, i64 noundef %10) #2
  %24 = icmp eq i32 %23, -15
  %spec.store.select1 = select i1 %24, i32 -25344, i32 %23
  br label %39

25:                                               ; preds = %11
  %26 = load i32, ptr %12, align 8, !tbaa !16
  %27 = icmp eq i32 %26, 73
  br i1 %27, label %28, label %39

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %12, i64 24
  %30 = load i32, ptr %29, align 8, !tbaa !17
  %31 = zext i32 %30 to i64
  %32 = icmp ne i64 %31, %2
  %33 = icmp ne i64 %10, 16
  %or.cond = or i1 %33, %32
  br i1 %or.cond, label %39, label %34

34:                                               ; preds = %28
  store i64 %6, ptr %8, align 8, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %0, i64 80
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = tail call i32 @mbedtls_chachapoly_auth_decrypt(ptr noundef %36, i64 noundef %6, ptr noundef %1, ptr noundef %3, i64 noundef %4, ptr noundef %9, ptr noundef %5, ptr noundef %7) #2
  %38 = icmp eq i32 %37, -86
  %spec.store.select3 = select i1 %38, i32 -25344, i32 %37
  br label %39

39:                                               ; preds = %25, %34, %28, %20, %15
  %.1 = phi i32 [ %spec.store.select, %15 ], [ %spec.store.select1, %20 ], [ %spec.store.select3, %34 ], [ -24832, %28 ], [ -24704, %25 ]
  ret i32 %.1
}

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

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

declare i32 @mbedtls_chachapoly_auth_decrypt(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr 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 = !{!"mbedtls_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 4}
!13 = !{!"mbedtls_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 = !{!11, !11, i64 0}
!15 = !{!6, !7, i64 80}
!16 = !{!13, !10, i64 0}
!17 = !{!13, !10, i64 24}


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