; 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_set_padding_mode(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %2
  br label %7

7:                                                ; preds = %6
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp eq ptr null, %10
  br i1 %11, label %19, label %12

12:                                               ; preds = %7
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = icmp ne i32 2, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %12, %7
  store i32 -24832, ptr %3, align 4
  br label %49

20:                                               ; preds = %12
  %21 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %21, label %47 [
    i32 0, label %22
    i32 1, label %27
    i32 2, label %32
    i32 3, label %37
    i32 4, label %42
  ]

22:                                               ; preds = %20
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %23, i32 0, i32 3
  store ptr @add_pkcs_padding, ptr %24, align 8, !tbaa !16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %25, i32 0, i32 4
  store ptr @get_pkcs_padding, ptr %26, align 8, !tbaa !17
  br label %48

27:                                               ; preds = %20
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %28, i32 0, i32 3
  store ptr @add_one_and_zeros_padding, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %30, i32 0, i32 4
  store ptr @get_one_and_zeros_padding, ptr %31, align 8, !tbaa !17
  br label %48

32:                                               ; preds = %20
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %33, i32 0, i32 3
  store ptr @add_zeros_and_len_padding, ptr %34, align 8, !tbaa !16
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %35, i32 0, i32 4
  store ptr @get_zeros_and_len_padding, ptr %36, align 8, !tbaa !17
  br label %48

37:                                               ; preds = %20
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %38, i32 0, i32 3
  store ptr @add_zeros_padding, ptr %39, align 8, !tbaa !16
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %40, i32 0, i32 4
  store ptr @get_zeros_padding, ptr %41, align 8, !tbaa !17
  br label %48

42:                                               ; preds = %20
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %43, i32 0, i32 3
  store ptr null, ptr %44, align 8, !tbaa !16
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %45, i32 0, i32 4
  store ptr @get_no_padding, ptr %46, align 8, !tbaa !17
  br label %48

47:                                               ; preds = %20
  store i32 -24704, ptr %3, align 4
  br label %49

48:                                               ; preds = %42, %37, %32, %27, %22
  store i32 0, ptr %3, align 4
  br label %49

49:                                               ; preds = %48, %47, %19
  %50 = load i32, ptr %3, align 4
  ret i32 %50
}

; Function Attrs: nounwind uwtable
declare hidden void @add_pkcs_padding(ptr noundef, i64 noundef, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @add_one_and_zeros_padding(ptr noundef, i64 noundef, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @add_zeros_and_len_padding(ptr noundef, i64 noundef, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @add_zeros_padding(ptr noundef, i64 noundef, i64 noundef) #0

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

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

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" }

!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 = !{!"mbedtls_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 4}
!15 = !{!"mbedtls_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 = !{!12, !6, i64 16}
!17 = !{!12, !6, 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"

@switch.table.mbedtls_cipher_set_padding_mode = private unnamed_addr constant [5 x ptr] [ptr @add_pkcs_padding, ptr @add_one_and_zeros_padding, ptr @add_zeros_and_len_padding, ptr @add_zeros_padding, ptr null], align 8
@switch.table.mbedtls_cipher_set_padding_mode.1 = private unnamed_addr constant [5 x ptr] [ptr @get_pkcs_padding, ptr @get_one_and_zeros_padding, ptr @get_zeros_and_len_padding, ptr @get_zeros_padding, ptr @get_no_padding], align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -24832, 1) i32 @mbedtls_cipher_set_padding_mode(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %14, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %.not = icmp eq i32 %7, 2
  br i1 %.not, label %8, label %14

8:                                                ; preds = %5
  %9 = icmp ult i32 %1, 5
  br i1 %9, label %switch.lookup, label %14

switch.lookup:                                    ; preds = %8
  %10 = zext nneg i32 %1 to i64
  %switch.gep = getelementptr inbounds [5 x ptr], ptr @switch.table.mbedtls_cipher_set_padding_mode, i64 0, i64 %10
  %switch.load = load ptr, ptr %switch.gep, align 8
  %11 = zext nneg i32 %1 to i64
  %switch.gep14 = getelementptr inbounds [5 x ptr], ptr @switch.table.mbedtls_cipher_set_padding_mode.1, i64 0, i64 %11
  %switch.load15 = load ptr, ptr %switch.gep14, align 8
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %switch.load, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %switch.load15, ptr %13, align 8, !tbaa !15
  br label %14

14:                                               ; preds = %8, %switch.lookup, %2, %5
  %.0 = phi i32 [ -24832, %5 ], [ -24832, %2 ], [ -24704, %8 ], [ 0, %switch.lookup ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @add_pkcs_padding(ptr noundef, i64 noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @add_one_and_zeros_padding(ptr noundef, i64 noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @add_zeros_and_len_padding(ptr noundef, i64 noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @add_zeros_padding(ptr noundef, i64 noundef, i64 noundef) #1

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

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

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

!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 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 24}


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