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

; 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_nonces = external hidden constant [2 x [12 x i8]], align 16
@test_counters = external hidden constant [2 x i32], align 4
@test_lengths = external hidden constant [2 x i64], align 16
@test_input = external hidden constant [2 x [375 x i8]], align 16
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 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_output = external hidden constant <{ <{ [64 x i8], [311 x i8] }>, [375 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_chacha20_crypt(ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_chacha20_self_test(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [381 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 381, 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 = %79, %1
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp ult i32 %9, 2
  br i1 %10, label %11, label %82

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 [12 x i8]], ptr @test_nonces, i64 0, i64 %23
  %25 = getelementptr inbounds [12 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 i32], ptr @test_counters, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [2 x i64], ptr @test_lengths, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [2 x [375 x i8]], ptr @test_input, i64 0, i64 %35
  %37 = getelementptr inbounds [375 x i8], ptr %36, i64 0, i64 0
  %38 = getelementptr inbounds [381 x i8], ptr %4, i64 0, i64 0
  %39 = call i32 @mbedtls_chacha20_crypt(ptr noundef %21, ptr noundef %25, i32 noundef %29, i64 noundef %33, ptr noundef %37, ptr noundef %38)
  store i32 %39, ptr %6, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %17
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = icmp eq i32 0, %41
  br i1 %42, label %50, label %43

43:                                               ; preds = %40
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %43
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %47)
  br label %49

49:                                               ; preds = %46, %43
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %88

50:                                               ; preds = %40
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  %54 = getelementptr inbounds [381 x i8], ptr %4, i64 0, i64 0
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds [2 x [375 x i8]], ptr @test_output, i64 0, i64 %56
  %58 = getelementptr inbounds [375 x i8], ptr %57, i64 0, i64 0
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds [2 x i64], ptr @test_lengths, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = call i32 @memcmp(ptr noundef %54, ptr noundef %58, i64 noundef %62) #5
  %64 = icmp eq i32 0, %63
  br i1 %64, label %71, label %65

65:                                               ; preds = %53
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %65
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %70

70:                                               ; preds = %68, %65
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %88

71:                                               ; preds = %53
  br label %72

72:                                               ; preds = %71
  br label %73

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

76:                                               ; preds = %73
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %78

78:                                               ; preds = %76, %73
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = add i32 %80, 1
  store i32 %81, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !11

82:                                               ; preds = %8
  %83 = load i32, ptr %3, align 4, !tbaa !5
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %87

85:                                               ; preds = %82
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %87

87:                                               ; preds = %85, %82
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %88

88:                                               ; preds = %87, %70, %49
  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 381, ptr %4) #4
  %89 = load i32, ptr %2, align 4
  ret i32 %89
}

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_nonces = external hidden constant [2 x [12 x i8]], align 16
@test_counters = external hidden local_unnamed_addr constant [2 x i32], align 4
@test_lengths = external hidden local_unnamed_addr constant [2 x i64], align 16
@test_input = external hidden constant [2 x [375 x i8]], align 16
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 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_output = external hidden constant <{ <{ [64 x i8], [311 x i8] }>, [375 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_chacha20_crypt(ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @mbedtls_chacha20_self_test(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [381 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 381, ptr nonnull %2) #4
  %.not20 = icmp eq i32 %0, 0
  br i1 %.not20, 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 i32, ptr @test_counters, align 4, !tbaa !5
  %5 = load i64, ptr @test_lengths, align 16, !tbaa !9
  %6 = call i32 @mbedtls_chacha20_crypt(ptr noundef nonnull @test_keys, ptr noundef nonnull @test_nonces, i32 noundef %4, i64 noundef %5, ptr noundef nonnull @test_input, ptr noundef nonnull %2)
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %21, label %.split25.us

.split.us.preheader:                              ; preds = %1
  %8 = load i32, ptr @test_counters, align 4, !tbaa !5
  %9 = load i64, ptr @test_lengths, align 16, !tbaa !9
  %10 = call i32 @mbedtls_chacha20_crypt(ptr noundef nonnull @test_keys, ptr noundef nonnull @test_nonces, i32 noundef %8, i64 noundef %9, ptr noundef nonnull @test_input, ptr noundef nonnull %2)
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %.split.us.preheader
  %bcmp.us = call i32 @bcmp(ptr nonnull %2, ptr nonnull @test_output, i64 %9)
  %13 = icmp eq i32 %bcmp.us, 0
  br i1 %13, label %.split.us.1, label %.critedge

.split.us.1:                                      ; preds = %12
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @test_counters, i64 4), align 4, !tbaa !5
  %15 = load i64, ptr getelementptr inbounds (i8, ptr @test_lengths, i64 8), align 8, !tbaa !9
  %16 = call i32 @mbedtls_chacha20_crypt(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_keys, i64 32), ptr noundef nonnull getelementptr inbounds (i8, ptr @test_nonces, i64 12), i32 noundef %14, i64 noundef %15, ptr noundef nonnull getelementptr inbounds (i8, ptr @test_input, i64 375), ptr noundef nonnull %2)
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %.critedge

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

.split25.us:                                      ; preds = %.split.1, %.split.preheader
  %.us-phi = phi i32 [ %6, %.split.preheader ], [ %28, %.split.1 ]
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.us-phi)
  br label %.critedge

21:                                               ; preds = %.split.preheader
  %bcmp = call i32 @bcmp(ptr nonnull %2, ptr nonnull @test_output, i64 %5)
  %22 = icmp eq i32 %bcmp, 0
  br i1 %22, label %.split.1, label %.split28.us

.split28.us:                                      ; preds = %30, %21
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.critedge

.split.1:                                         ; preds = %21
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 1)
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @test_counters, i64 4), align 4, !tbaa !5
  %27 = load i64, ptr getelementptr inbounds (i8, ptr @test_lengths, i64 8), align 8, !tbaa !9
  %28 = call i32 @mbedtls_chacha20_crypt(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_keys, i64 32), ptr noundef nonnull getelementptr inbounds (i8, ptr @test_nonces, i64 12), i32 noundef %26, i64 noundef %27, ptr noundef nonnull getelementptr inbounds (i8, ptr @test_input, i64 375), ptr noundef nonnull %2)
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %.split25.us

30:                                               ; preds = %.split.1
  %bcmp.1 = call i32 @bcmp(ptr nonnull %2, ptr nonnull getelementptr inbounds (i8, ptr @test_output, i64 375), i64 %27)
  %31 = icmp eq i32 %bcmp.1, 0
  br i1 %31, label %32, label %.split28.us

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

.critedge:                                        ; preds = %18, %.split.us.1, %.split.us.preheader, %12, %32, %.split28.us, %.split25.us
  %.018 = phi i32 [ -1, %.split25.us ], [ -1, %.split28.us ], [ 0, %32 ], [ -1, %12 ], [ -1, %.split.us.preheader ], [ -1, %.split.us.1 ], [ %spec.select, %18 ]
  call void @llvm.lifetime.end.p0(i64 381, ptr nonnull %2) #4
  ret i32 %.018
}

; 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 = !{!"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}


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