; 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: nounwind uwtable
define dso_local i32 @mbedtls_cipher_auth_encrypt(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) #0 {
  %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
  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 %24

24:                                               ; preds = %11
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  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
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = icmp eq i32 6, %42
  br i1 %43, label %44, label %60

44:                                               ; preds = %37
  %45 = load i64, ptr %19, align 8, !tbaa !9
  %46 = load ptr, ptr %21, align 8, !tbaa !5
  store i64 %45, ptr %46, align 8, !tbaa !9
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %47, i32 0, i32 9
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = load i64, ptr %19, align 8, !tbaa !9
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = load i64, ptr %15, align 8, !tbaa !9
  %53 = load ptr, ptr %16, align 8, !tbaa !5
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = load ptr, ptr %18, align 8, !tbaa !5
  %56 = load ptr, ptr %20, align 8, !tbaa !5
  %57 = load i64, ptr %23, align 8, !tbaa !9
  %58 = load ptr, ptr %22, align 8, !tbaa !5
  %59 = call i32 @mbedtls_gcm_crypt_and_tag(ptr noundef %49, i32 noundef 1, i64 noundef %50, ptr noundef %51, i64 noundef %52, ptr noundef %53, i64 noundef %54, ptr noundef %55, ptr noundef %56, i64 noundef %57, ptr noundef %58)
  store i32 %59, ptr %12, align 4
  br label %118

60:                                               ; preds = %37
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !14
  %66 = icmp eq i32 8, %65
  br i1 %66, label %67, label %83

67:                                               ; preds = %60
  %68 = load i64, ptr %19, align 8, !tbaa !9
  %69 = load ptr, ptr %21, align 8, !tbaa !5
  store i64 %68, ptr %69, align 8, !tbaa !9
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %70, i32 0, i32 9
  %72 = load ptr, ptr %71, align 8, !tbaa !16
  %73 = load i64, ptr %19, align 8, !tbaa !9
  %74 = load ptr, ptr %14, align 8, !tbaa !5
  %75 = load i64, ptr %15, align 8, !tbaa !9
  %76 = load ptr, ptr %16, align 8, !tbaa !5
  %77 = load i64, ptr %17, align 8, !tbaa !9
  %78 = load ptr, ptr %18, align 8, !tbaa !5
  %79 = load ptr, ptr %20, align 8, !tbaa !5
  %80 = load ptr, ptr %22, align 8, !tbaa !5
  %81 = load i64, ptr %23, align 8, !tbaa !9
  %82 = call i32 @mbedtls_ccm_encrypt_and_tag(ptr noundef %72, i64 noundef %73, ptr noundef %74, i64 noundef %75, ptr noundef %76, i64 noundef %77, ptr noundef %78, ptr noundef %79, ptr noundef %80, i64 noundef %81)
  store i32 %82, ptr %12, align 4
  br label %118

83:                                               ; preds = %60
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  %87 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 8, !tbaa !17
  %89 = icmp eq i32 73, %88
  br i1 %89, label %90, label %117

90:                                               ; preds = %83
  %91 = load i64, ptr %15, align 8, !tbaa !9
  %92 = load ptr, ptr %13, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !11
  %95 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %94, i32 0, i32 4
  %96 = load i32, ptr %95, align 8, !tbaa !18
  %97 = zext i32 %96 to i64
  %98 = icmp ne i64 %91, %97
  br i1 %98, label %102, label %99

99:                                               ; preds = %90
  %100 = load i64, ptr %23, align 8, !tbaa !9
  %101 = icmp ne i64 %100, 16
  br i1 %101, label %102, label %103

102:                                              ; preds = %99, %90
  store i32 -24832, ptr %12, align 4
  br label %118

103:                                              ; preds = %99
  %104 = load i64, ptr %19, align 8, !tbaa !9
  %105 = load ptr, ptr %21, align 8, !tbaa !5
  store i64 %104, ptr %105, 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 9
  %108 = load ptr, ptr %107, align 8, !tbaa !16
  %109 = load i64, ptr %19, align 8, !tbaa !9
  %110 = load ptr, ptr %14, align 8, !tbaa !5
  %111 = load ptr, ptr %16, align 8, !tbaa !5
  %112 = load i64, ptr %17, align 8, !tbaa !9
  %113 = load ptr, ptr %18, align 8, !tbaa !5
  %114 = load ptr, ptr %20, align 8, !tbaa !5
  %115 = load ptr, ptr %22, align 8, !tbaa !5
  %116 = call i32 @mbedtls_chachapoly_encrypt_and_tag(ptr noundef %108, i64 noundef %109, ptr noundef %110, ptr noundef %111, i64 noundef %112, ptr noundef %113, ptr noundef %114, ptr noundef %115)
  store i32 %116, ptr %12, align 4
  br label %118

117:                                              ; preds = %83
  store i32 -24704, ptr %12, align 4
  br label %118

118:                                              ; preds = %117, %103, %102, %67, %44
  %119 = load i32, ptr %12, align 4
  ret i32 %119
}

declare i32 @mbedtls_gcm_crypt_and_tag(ptr noundef, i32 noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

declare i32 @mbedtls_ccm_encrypt_and_tag(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) #1

declare i32 @mbedtls_chachapoly_encrypt_and_tag(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #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" }

!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 = !{!12, !6, i64 80}
!17 = !{!15, !13, i64 0}
!18 = !{!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_encrypt(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 %23 [
    i32 6, label %15
    i32 8, label %19
  ]

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_crypt_and_tag(ptr noundef %17, i32 noundef 1, i64 noundef %6, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %7, i64 noundef %10, ptr noundef %9) #2
  br label %36

19:                                               ; preds = %11
  store i64 %6, ptr %8, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = tail call i32 @mbedtls_ccm_encrypt_and_tag(ptr noundef %21, 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
  br label %36

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

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

32:                                               ; preds = %26
  store i64 %6, ptr %8, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %0, i64 80
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = tail call i32 @mbedtls_chachapoly_encrypt_and_tag(ptr noundef %34, i64 noundef %6, ptr noundef %1, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %7, ptr noundef %9) #2
  br label %36

36:                                               ; preds = %23, %26, %32, %19, %15
  %.0 = phi i32 [ %18, %15 ], [ %22, %19 ], [ %35, %32 ], [ -24832, %26 ], [ -24704, %23 ]
  ret i32 %.0
}

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

declare i32 @mbedtls_ccm_encrypt_and_tag(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_encrypt_and_tag(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,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass