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

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

@odd_parity_table = external hidden constant [128 x i8], align 16

; 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

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

6:                                                ; preds = %30, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 8
  br i1 %8, label %9, label %33

9:                                                ; preds = %6
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = zext i8 %14 to i32
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %16, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = sdiv i32 %21, 2
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %15, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %9
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %34

29:                                               ; preds = %9
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !12

33:                                               ; preds = %6
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %34

34:                                               ; preds = %33, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %35 = load i32, ptr %2, align 4
  ret i32 %35
}

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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@odd_parity_table = external hidden local_unnamed_addr constant [128 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local range(i32 0, 2) i32 @mbedtls_des_key_check_key_parity(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = lshr i8 %2, 1
  %4 = zext nneg i8 %3 to i64
  %5 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %4
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i8 %2, %6
  br i1 %.not, label %7, label %56

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 1
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = lshr i8 %9, 1
  %11 = zext nneg i8 %10 to i64
  %12 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %.not.1 = icmp eq i8 %9, %13
  br i1 %.not.1, label %14, label %56

14:                                               ; preds = %7
  %15 = getelementptr inbounds i8, ptr %0, i64 2
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = lshr i8 %16, 1
  %18 = zext nneg i8 %17 to i64
  %19 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %.not.2 = icmp eq i8 %16, %20
  br i1 %.not.2, label %21, label %56

21:                                               ; preds = %14
  %22 = getelementptr inbounds i8, ptr %0, i64 3
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = lshr i8 %23, 1
  %25 = zext nneg i8 %24 to i64
  %26 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %.not.3 = icmp eq i8 %23, %27
  br i1 %.not.3, label %28, label %56

28:                                               ; preds = %21
  %29 = getelementptr inbounds i8, ptr %0, i64 4
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = lshr i8 %30, 1
  %32 = zext nneg i8 %31 to i64
  %33 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %.not.4 = icmp eq i8 %30, %34
  br i1 %.not.4, label %35, label %56

35:                                               ; preds = %28
  %36 = getelementptr inbounds i8, ptr %0, i64 5
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %38 = lshr i8 %37, 1
  %39 = zext nneg i8 %38 to i64
  %40 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %.not.5 = icmp eq i8 %37, %41
  br i1 %.not.5, label %42, label %56

42:                                               ; preds = %35
  %43 = getelementptr inbounds i8, ptr %0, i64 6
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = lshr i8 %44, 1
  %46 = zext nneg i8 %45 to i64
  %47 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !5
  %.not.6 = icmp eq i8 %44, %48
  br i1 %.not.6, label %49, label %56

49:                                               ; preds = %42
  %50 = getelementptr inbounds i8, ptr %0, i64 7
  %51 = load i8, ptr %50, align 1, !tbaa !5
  %52 = lshr i8 %51, 1
  %53 = zext nneg i8 %52 to i64
  %54 = getelementptr inbounds [128 x i8], ptr @odd_parity_table, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !5
  %.not.7 = icmp ne i8 %51, %55
  %spec.select = zext i1 %.not.7 to i32
  br label %56

56:                                               ; preds = %49, %42, %35, %28, %21, %14, %7, %1
  %.06 = phi i32 [ 1, %1 ], [ 1, %7 ], [ 1, %14 ], [ 1, %21 ], [ 1, %28 ], [ 1, %35 ], [ 1, %42 ], [ %spec.select, %49 ]
  ret i32 %.06
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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