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

; 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: nounwind uwtable
declare hidden i32 @pkcs12_pbe_derive_key_iv(ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) #2

; 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_pkcs12_pbe(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8) #1 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca [32 x i8], align 16
  %23 = alloca [16 x i8], align 16
  %24 = alloca ptr, align 8
  %25 = alloca %struct.mbedtls_cipher_context_t, align 8
  %26 = alloca i64, align 8
  %27 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i32 %1, ptr %12, align 4, !tbaa !9
  store i32 %2, ptr %13, align 4, !tbaa !9
  store i32 %3, ptr %14, align 4, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !11
  store ptr %6, ptr %17, align 8, !tbaa !5
  store i64 %7, ptr %18, align 8, !tbaa !11
  store ptr %8, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  store i32 0, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.start.p0(i64 96, ptr %25) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #3
  store i64 0, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = call ptr @mbedtls_cipher_info_from_type(i32 noundef %28)
  store ptr %29, ptr %24, align 8, !tbaa !5
  %30 = load ptr, ptr %24, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %9
  store i32 -7936, ptr %10, align 4
  store i32 1, ptr %27, align 4
  br label %99

33:                                               ; preds = %9
  %34 = load ptr, ptr %24, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = udiv i32 %36, 8
  store i32 %37, ptr %21, align 4, !tbaa !9
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = load ptr, ptr %15, align 8, !tbaa !5
  %41 = load i64, ptr %16, align 8, !tbaa !11
  %42 = getelementptr inbounds [32 x i8], ptr %22, i64 0, i64 0
  %43 = load i32, ptr %21, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %46 = load ptr, ptr %24, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !15
  %49 = zext i32 %48 to i64
  %50 = call i32 @pkcs12_pbe_derive_key_iv(ptr noundef %38, i32 noundef %39, ptr noundef %40, i64 noundef %41, ptr noundef %42, i64 noundef %44, ptr noundef %45, i64 noundef %49)
  store i32 %50, ptr %20, align 4, !tbaa !9
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %33
  %53 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %53, ptr %10, align 4
  store i32 1, ptr %27, align 4
  br label %99

54:                                               ; preds = %33
  call void @mbedtls_cipher_init(ptr noundef %25)
  %55 = load ptr, ptr %24, align 8, !tbaa !5
  %56 = call i32 @mbedtls_cipher_setup(ptr noundef %25, ptr noundef %55)
  store i32 %56, ptr %20, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %54
  br label %95

59:                                               ; preds = %54
  %60 = getelementptr inbounds [32 x i8], ptr %22, i64 0, i64 0
  %61 = load i32, ptr %21, align 4, !tbaa !9
  %62 = mul nsw i32 8, %61
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = call i32 @mbedtls_cipher_setkey(ptr noundef %25, ptr noundef %60, i32 noundef %62, i32 noundef %63)
  store i32 %64, ptr %20, align 4, !tbaa !9
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %59
  br label %95

67:                                               ; preds = %59
  %68 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %69 = load ptr, ptr %24, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %69, i32 0, i32 4
  %71 = load i32, ptr %70, align 8, !tbaa !15
  %72 = zext i32 %71 to i64
  %73 = call i32 @mbedtls_cipher_set_iv(ptr noundef %25, ptr noundef %68, i64 noundef %72)
  store i32 %73, ptr %20, align 4, !tbaa !9
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %76

75:                                               ; preds = %67
  br label %95

76:                                               ; preds = %67
  %77 = call i32 @mbedtls_cipher_reset(ptr noundef %25)
  store i32 %77, ptr %20, align 4, !tbaa !9
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %76
  br label %95

80:                                               ; preds = %76
  %81 = load ptr, ptr %17, align 8, !tbaa !5
  %82 = load i64, ptr %18, align 8, !tbaa !11
  %83 = load ptr, ptr %19, align 8, !tbaa !5
  %84 = call i32 @mbedtls_cipher_update(ptr noundef %25, ptr noundef %81, i64 noundef %82, ptr noundef %83, ptr noundef %26)
  store i32 %84, ptr %20, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %80
  br label %95

87:                                               ; preds = %80
  %88 = load ptr, ptr %19, align 8, !tbaa !5
  %89 = load i64, ptr %26, align 8, !tbaa !11
  %90 = getelementptr inbounds i8, ptr %88, i64 %89
  %91 = call i32 @mbedtls_cipher_finish(ptr noundef %25, ptr noundef %90, ptr noundef %26)
  store i32 %91, ptr %20, align 4, !tbaa !9
  %92 = icmp ne i32 %91, 0
  br i1 %92, label %93, label %94

93:                                               ; preds = %87
  store i32 -7680, ptr %20, align 4, !tbaa !9
  br label %94

94:                                               ; preds = %93, %87
  br label %95

95:                                               ; preds = %94, %86, %79, %75, %66, %58
  %96 = getelementptr inbounds [32 x i8], ptr %22, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %96, i64 noundef 32)
  %97 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %97, i64 noundef 16)
  call void @mbedtls_cipher_free(ptr noundef %25)
  %98 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %98, ptr %10, align 4
  store i32 1, ptr %27, align 4
  br label %99

99:                                               ; preds = %95, %52, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #3
  call void @llvm.lifetime.end.p0(i64 96, ptr %25) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  %100 = load i32, ptr %10, align 4
  ret i32 %100
}

declare ptr @mbedtls_cipher_info_from_type(i32 noundef) #2

declare void @mbedtls_cipher_init(ptr noundef) #2

declare i32 @mbedtls_cipher_setup(ptr noundef, ptr noundef) #2

declare i32 @mbedtls_cipher_setkey(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

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

declare i32 @mbedtls_cipher_reset(ptr noundef) #2

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

declare i32 @mbedtls_cipher_finish(ptr noundef, ptr noundef, ptr noundef) #2

declare void @mbedtls_cipher_free(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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"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}
!15 = !{!14, !10, 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"

%struct.mbedtls_cipher_context_t = type { ptr, i32, i32, ptr, ptr, [16 x i8], i64, [16 x i8], i64, ptr, ptr }

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

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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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_pkcs12_pbe(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8) local_unnamed_addr #1 {
  %10 = alloca [32 x i8], align 16
  %11 = alloca [16 x i8], align 16
  %12 = alloca %struct.mbedtls_cipher_context_t, align 8
  %13 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %11) #3
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %13) #3
  store i64 0, ptr %13, align 8, !tbaa !5
  %14 = tail call ptr @mbedtls_cipher_info_from_type(i32 noundef %2) #3
  %15 = icmp eq ptr %14, null
  br i1 %15, label %43, label %16

16:                                               ; preds = %9
  %17 = getelementptr inbounds i8, ptr %14, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = lshr i32 %18, 3
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %14, i64 24
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = zext i32 %22 to i64
  %24 = call i32 @pkcs12_pbe_derive_key_iv(ptr noundef %0, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef nonnull %10, i64 noundef %20, ptr noundef nonnull %11, i64 noundef %23)
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %25, label %43

25:                                               ; preds = %16
  call void @mbedtls_cipher_init(ptr noundef nonnull %12) #3
  %26 = call i32 @mbedtls_cipher_setup(ptr noundef nonnull %12, ptr noundef nonnull %14) #3
  %.not27 = icmp eq i32 %26, 0
  br i1 %.not27, label %27, label %42

27:                                               ; preds = %25
  %28 = and i32 %18, -8
  %29 = call i32 @mbedtls_cipher_setkey(ptr noundef nonnull %12, ptr noundef nonnull %10, i32 noundef %28, i32 noundef %1) #3
  %.not28 = icmp eq i32 %29, 0
  br i1 %.not28, label %30, label %42

30:                                               ; preds = %27
  %31 = load i32, ptr %21, align 8, !tbaa !13
  %32 = zext i32 %31 to i64
  %33 = call i32 @mbedtls_cipher_set_iv(ptr noundef nonnull %12, ptr noundef nonnull %11, i64 noundef %32) #3
  %.not29 = icmp eq i32 %33, 0
  br i1 %.not29, label %34, label %42

34:                                               ; preds = %30
  %35 = call i32 @mbedtls_cipher_reset(ptr noundef nonnull %12) #3
  %.not30 = icmp eq i32 %35, 0
  br i1 %.not30, label %36, label %42

36:                                               ; preds = %34
  %37 = call i32 @mbedtls_cipher_update(ptr noundef nonnull %12, ptr noundef %6, i64 noundef %7, ptr noundef %8, ptr noundef nonnull %13) #3
  %.not31 = icmp eq i32 %37, 0
  br i1 %.not31, label %38, label %42

38:                                               ; preds = %36
  %39 = load i64, ptr %13, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %8, i64 %39
  %41 = call i32 @mbedtls_cipher_finish(ptr noundef nonnull %12, ptr noundef %40, ptr noundef nonnull %13) #3
  %.not32 = icmp eq i32 %41, 0
  %spec.store.select = select i1 %.not32, i32 0, i32 -7680
  br label %42

42:                                               ; preds = %36, %34, %30, %27, %25, %38
  %.019 = phi i32 [ %26, %25 ], [ %29, %27 ], [ %33, %30 ], [ %35, %34 ], [ %37, %36 ], [ %spec.store.select, %38 ]
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %10, i64 noundef 32) #3
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %11, i64 noundef 16) #3
  call void @mbedtls_cipher_free(ptr noundef nonnull %12) #3
  br label %43

43:                                               ; preds = %16, %9, %42
  %.0 = phi i32 [ %.019, %42 ], [ -7936, %9 ], [ %24, %16 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %13) #3
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %12) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %10) #3
  ret i32 %.0
}

declare ptr @mbedtls_cipher_info_from_type(i32 noundef) local_unnamed_addr #2

declare void @mbedtls_cipher_init(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_cipher_setup(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_cipher_setkey(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare i32 @mbedtls_cipher_set_iv(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @mbedtls_cipher_reset(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_cipher_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_cipher_finish(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @mbedtls_cipher_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"mbedtls_cipher_info_t", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !12, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !11, i64 24}


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