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

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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@test_keys = external hidden constant [2 x [32 x i8]], align 16
@test_data_len = external hidden constant [2 x i64], align 16
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@test_mac = external hidden constant [2 x [16 x i8]], align 16
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@test_data = external hidden constant <{ <{ [34 x i8], [93 x i8] }>, [127 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
declare dso_local i32 @mbedtls_poly1305_mac(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

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

8:                                                ; preds = %67, %1
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp ult i32 %9, 2
  br i1 %10, label %11, label %70

11:                                               ; preds = %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %15)
  br label %17

17:                                               ; preds = %14, %11
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [2 x [32 x i8]], ptr @test_keys, i64 0, i64 %19
  %21 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds [2 x [127 x i8]], ptr @test_data, i64 0, i64 %23
  %25 = getelementptr inbounds [127 x i8], ptr %24, i64 0, i64 0
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [2 x i64], ptr @test_data_len, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  %31 = call i32 @mbedtls_poly1305_mac(ptr noundef %21, ptr noundef %25, i64 noundef %29, ptr noundef %30)
  store i32 %31, ptr %6, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %17
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = icmp eq i32 0, %33
  br i1 %34, label %42, label %35

35:                                               ; preds = %32
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %39)
  br label %41

41:                                               ; preds = %38, %35
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %76

42:                                               ; preds = %32
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [2 x [16 x i8]], ptr @test_mac, i64 0, i64 %48
  %50 = getelementptr inbounds [16 x i8], ptr %49, i64 0, i64 0
  %51 = call i32 @memcmp(ptr noundef %46, ptr noundef %50, i64 noundef 16) #5
  %52 = icmp eq i32 0, %51
  br i1 %52, label %59, label %53

53:                                               ; preds = %45
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %58

58:                                               ; preds = %56, %53
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %76

59:                                               ; preds = %45
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %66

64:                                               ; preds = %61
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %66

66:                                               ; preds = %64, %61
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = add i32 %68, 1
  store i32 %69, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !11

70:                                               ; preds = %8
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %70
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %75

75:                                               ; preds = %73, %70
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %76

76:                                               ; preds = %75, %58, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  %77 = load i32, ptr %2, align 4
  ret i32 %77
}

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

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 willreturn memory(read) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"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"

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@test_keys = external hidden constant [2 x [32 x i8]], align 16
@test_data_len = external hidden local_unnamed_addr constant [2 x i64], align 16
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@test_mac = external hidden constant [2 x [16 x i8]], align 16
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@test_data = external hidden constant <{ <{ [34 x i8], [93 x i8] }>, [127 x i8] }>, align 16

; 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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @mbedtls_poly1305_self_test(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  %.not17 = icmp eq i32 %0, 0
  br i1 %.not17, label %.split.us.preheader, label %.split.preheader

.split.preheader:                                 ; preds = %1
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 0)
  %4 = load i64, ptr @test_data_len, align 16, !tbaa !5
  %5 = call i32 @mbedtls_poly1305_mac(ptr noundef nonnull @test_keys, ptr noundef nonnull @test_data, i64 noundef %4, ptr noundef nonnull %2)
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %18, label %.split22.us

.split.us.preheader:                              ; preds = %1
  %7 = load i64, ptr @test_data_len, align 16, !tbaa !5
  %8 = call i32 @mbedtls_poly1305_mac(ptr noundef nonnull @test_keys, ptr noundef nonnull @test_data, i64 noundef %7, ptr noundef nonnull %2)
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %.critedge

10:                                               ; preds = %.split.us.preheader
  %bcmp.us = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %2, ptr noundef nonnull dereferenceable(16) @test_mac, i64 16)
  %11 = icmp eq i32 %bcmp.us, 0
  br i1 %11, label %.split.us.1, label %.critedge

.split.us.1:                                      ; preds = %10
  %12 = load i64, ptr getelementptr inbounds (i8, ptr @test_data_len, i64 8), align 8, !tbaa !5
  %13 = call i32 @mbedtls_poly1305_mac(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_keys, i64 32), ptr noundef nonnull getelementptr inbounds (i8, ptr @test_data, i64 127), i64 noundef %12, ptr noundef nonnull %2)
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %.critedge

15:                                               ; preds = %.split.us.1
  %bcmp.us.1 = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %2, ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @test_mac, i64 16), i64 16)
  %16 = icmp ne i32 %bcmp.us.1, 0
  %spec.select = sext i1 %16 to i32
  br label %.critedge

.split22.us:                                      ; preds = %.split.1, %.split.preheader
  %.us-phi = phi i32 [ %5, %.split.preheader ], [ %24, %.split.1 ]
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.us-phi)
  br label %.critedge

18:                                               ; preds = %.split.preheader
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %2, ptr noundef nonnull dereferenceable(16) @test_mac, i64 16)
  %19 = icmp eq i32 %bcmp, 0
  br i1 %19, label %.split.1, label %.split25.us

.split25.us:                                      ; preds = %26, %18
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.critedge

.split.1:                                         ; preds = %18
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 1)
  %23 = load i64, ptr getelementptr inbounds (i8, ptr @test_data_len, i64 8), align 8, !tbaa !5
  %24 = call i32 @mbedtls_poly1305_mac(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_keys, i64 32), ptr noundef nonnull getelementptr inbounds (i8, ptr @test_data, i64 127), i64 noundef %23, ptr noundef nonnull %2)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %.split22.us

26:                                               ; preds = %.split.1
  %bcmp.1 = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %2, ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @test_mac, i64 16), i64 16)
  %27 = icmp eq i32 %bcmp.1, 0
  br i1 %27, label %28, label %.split25.us

28:                                               ; preds = %26
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %.critedge

.critedge:                                        ; preds = %15, %.split.us.1, %.split.us.preheader, %10, %28, %.split25.us, %.split22.us
  %.015 = phi i32 [ -1, %.split22.us ], [ -1, %.split25.us ], [ 0, %28 ], [ -1, %10 ], [ -1, %.split.us.preheader ], [ -1, %.split.us.1 ], [ %spec.select, %15 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  ret i32 %.015
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #3

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 = { nofree nounwind "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 = { nofree nounwind willreturn memory(argmem: read) }
attributes #4 = { 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass