; 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

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

declare i32 @mbedtls_chachapoly_finish(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_cipher_check_tag(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 [16 x i8], align 16
  %9 = alloca i32, align 4
  %10 = 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 16, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 -110, ptr %9, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %3
  br label %12

12:                                               ; preds = %11
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = icmp ne i32 0, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

28:                                               ; preds = %22
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !16
  %34 = icmp eq i32 6, %33
  br i1 %34, label %35, label %57

35:                                               ; preds = %28
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = icmp ugt i64 %36, 16
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

39:                                               ; preds = %35
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %40, i32 0, i32 9
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = call i32 @mbedtls_gcm_finish(ptr noundef %42, ptr noundef %43, i64 noundef %44)
  store i32 %45, ptr %9, align 4, !tbaa !11
  %46 = icmp ne i32 0, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %39
  %48 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %48, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

49:                                               ; preds = %39
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = call i32 @mbedtls_constant_time_memcmp(ptr noundef %50, ptr noundef %51, i64 noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %49
  store i32 -25344, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

56:                                               ; preds = %49
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

57:                                               ; preds = %28
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !19
  %63 = icmp eq i32 73, %62
  br i1 %63, label %64, label %86

64:                                               ; preds = %57
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = icmp ne i64 %65, 16
  br i1 %66, label %67, label %68

67:                                               ; preds = %64
  store i32 -24832, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

68:                                               ; preds = %64
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %69, i32 0, i32 9
  %71 = load ptr, ptr %70, align 8, !tbaa !18
  %72 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %73 = call i32 @mbedtls_chachapoly_finish(ptr noundef %71, ptr noundef %72)
  store i32 %73, ptr %9, align 4, !tbaa !11
  %74 = load i32, ptr %9, align 4, !tbaa !11
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %78

76:                                               ; preds = %68
  %77 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %77, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

78:                                               ; preds = %68
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = call i32 @mbedtls_constant_time_memcmp(ptr noundef %79, ptr noundef %80, i64 noundef %81)
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %85

84:                                               ; preds = %78
  store i32 -25344, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

85:                                               ; preds = %78
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

86:                                               ; preds = %57
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %87

87:                                               ; preds = %86, %85, %84, %76, %67, %56, %55, %47, %38, %27, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  %88 = load i32, ptr %4, align 4
  ret i32 %88
}

; Function Attrs: nounwind uwtable
declare hidden i32 @mbedtls_constant_time_memcmp(ptr noundef, ptr noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"mbedtls_cipher_context_t", !6, i64 0, !12, i64 8, !12, 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}
!15 = !{!14, !12, i64 12}
!16 = !{!17, !12, i64 4}
!17 = !{!"mbedtls_cipher_info_t", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !6, i64 40}
!18 = !{!14, !6, i64 80}
!19 = !{!17, !12, i64 0}


; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

declare i32 @mbedtls_chachapoly_finish(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_cipher_check_tag(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %29, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %29

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %5, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = icmp eq i32 %12, 6
  br i1 %13, label %14, label %20

14:                                               ; preds = %10
  %15 = icmp ugt i64 %2, 16
  br i1 %15, label %29, label %16

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %0, i64 80
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = call i32 @mbedtls_gcm_finish(ptr noundef %18, ptr noundef nonnull %4, i64 noundef %2) #3
  %.not23 = icmp eq i32 %19, 0
  br i1 %.not23, label %.sink.split, label %29

20:                                               ; preds = %10
  %21 = load i32, ptr %5, align 8, !tbaa !16
  %22 = icmp eq i32 %21, 73
  br i1 %22, label %23, label %29

23:                                               ; preds = %20
  %.not20 = icmp eq i64 %2, 16
  br i1 %.not20, label %24, label %29

24:                                               ; preds = %23
  %25 = getelementptr inbounds i8, ptr %0, i64 80
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = call i32 @mbedtls_chachapoly_finish(ptr noundef %26, ptr noundef nonnull %4) #3
  %.not21 = icmp eq i32 %27, 0
  br i1 %.not21, label %.sink.split, label %29

.sink.split:                                      ; preds = %24, %16
  %.sink26 = phi i64 [ %2, %16 ], [ 16, %24 ]
  %28 = call i32 @mbedtls_constant_time_memcmp(ptr noundef %1, ptr noundef nonnull %4, i64 noundef %.sink26)
  %.not22 = icmp eq i32 %28, 0
  %.25 = select i1 %.not22, i32 0, i32 -25344
  br label %29

29:                                               ; preds = %.sink.split, %20, %24, %23, %16, %14, %7, %3
  %.0 = phi i32 [ -24832, %3 ], [ -24832, %7 ], [ -24832, %14 ], [ %19, %16 ], [ -24832, %23 ], [ %27, %24 ], [ 0, %20 ], [ %.25, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @mbedtls_constant_time_memcmp(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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


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