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

; 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_ecp_keypair = type { %struct.mbedtls_ecp_group, %struct.mbedtls_mpi, %struct.mbedtls_ecp_point }
%struct.mbedtls_ecp_group = type { i32, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_ecp_point, %struct.mbedtls_mpi, i64, i64, i32, ptr, ptr, ptr, ptr, ptr, i64 }
%struct.mbedtls_mpi = type { i32, i64, ptr }
%struct.mbedtls_ecp_point = type { %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi }

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_ecdh_setup(ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecdh_get_params(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 -110, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %3
  br label %11

11:                                               ; preds = %10
  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
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @mbedtls_ecdh_grp_id(ptr noundef %19)
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %33

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = call i32 @mbedtls_ecdh_setup(ptr noundef %23, i32 noundef %27)
  store i32 %28, ptr %8, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %22
  %31 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %31, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %48

32:                                               ; preds = %22
  br label %43

33:                                               ; preds = %18
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call i32 @mbedtls_ecdh_grp_id(ptr noundef %34)
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = icmp ne i32 %35, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %33
  store i32 -20352, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %48

42:                                               ; preds = %33
  br label %43

43:                                               ; preds = %42, %32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = call i32 @ecdh_get_params_internal(ptr noundef %44, ptr noundef %45, i32 noundef %46)
  store i32 %47, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %48

48:                                               ; preds = %43, %41, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %49 = load i32, ptr %4, align 4
  ret i32 %49
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ecdh_get_params_internal(ptr noundef, ptr noundef, i32 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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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, !10, i64 0}
!12 = !{!"mbedtls_ecp_keypair", !13, i64 0, !14, i64 248, !16, i64 272}
!13 = !{!"mbedtls_ecp_group", !10, i64 0, !14, i64 8, !14, i64 32, !14, i64 56, !16, i64 80, !14, i64 152, !15, i64 176, !15, i64 184, !10, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !15, i64 240}
!14 = !{!"mbedtls_mpi", !10, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"mbedtls_ecp_point", !14, i64 0, !14, i64 24, !14, i64 48}


; 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
declare dso_local i32 @mbedtls_ecdh_setup(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecdh_get_params(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @mbedtls_ecdh_grp_id(ptr noundef %0)
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = load i32, ptr %1, align 8, !tbaa !5
  %8 = tail call i32 @mbedtls_ecdh_setup(ptr noundef %0, i32 noundef %7)
  %.not10 = icmp eq i32 %8, 0
  br i1 %.not10, label %12, label %14

9:                                                ; preds = %3
  %10 = tail call i32 @mbedtls_ecdh_grp_id(ptr noundef %0)
  %11 = load i32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i32 %10, %11
  br i1 %.not, label %12, label %14

12:                                               ; preds = %9, %6
  %13 = tail call i32 @ecdh_get_params_internal(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %2)
  br label %14

14:                                               ; preds = %9, %6, %12
  %.0 = phi i32 [ %13, %12 ], [ %8, %6 ], [ -20352, %9 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @mbedtls_ecdh_grp_id(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @ecdh_get_params_internal(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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, !8, i64 0}
!6 = !{!"mbedtls_ecp_keypair", !7, i64 0, !11, i64 248, !14, i64 272}
!7 = !{!"mbedtls_ecp_group", !8, i64 0, !11, i64 8, !11, i64 32, !11, i64 56, !14, i64 80, !11, i64 152, !12, i64 176, !12, i64 184, !8, i64 192, !13, i64 200, !13, i64 208, !13, i64 216, !13, i64 224, !13, i64 232, !12, i64 240}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"mbedtls_mpi", !8, i64 0, !12, i64 8, !13, i64 16}
!12 = !{!"long", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"mbedtls_ecp_point", !11, i64 0, !11, i64 24, !11, i64 48}


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