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

; 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_arc4_context = type { i32, i32, [256 x i8] }

@.str = external hidden unnamed_addr constant [18 x i8], align 1
@arc4_test_pt = external hidden constant [3 x [8 x i8]], align 16
@arc4_test_key = external hidden constant [3 x [8 x i8]], align 16
@arc4_test_ct = external hidden constant [3 x [8 x i8]], align 16
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_arc4_init(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_arc4_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_arc4_setup(ptr noundef, 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
declare dso_local i32 @mbedtls_arc4_crypt(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #0

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

8:                                                ; preds = %50, %1
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 3
  br i1 %10, label %11, label %53

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

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

18:                                               ; preds = %14, %11
  %19 = getelementptr inbounds [8 x i8], ptr %5, i64 0, i64 0
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [3 x [8 x i8]], ptr @arc4_test_pt, i64 0, i64 %21
  %23 = getelementptr inbounds [8 x i8], ptr %22, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %19, ptr align 8 %23, i64 8, i1 false)
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [3 x [8 x i8]], ptr @arc4_test_key, i64 0, i64 %25
  %27 = getelementptr inbounds [8 x i8], ptr %26, i64 0, i64 0
  call void @mbedtls_arc4_setup(ptr noundef %7, ptr noundef %27, i32 noundef 8)
  %28 = getelementptr inbounds [8 x i8], ptr %5, i64 0, i64 0
  %29 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 0
  %30 = call i32 @mbedtls_arc4_crypt(ptr noundef %7, i64 noundef 8, ptr noundef %28, ptr noundef %29)
  %31 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 0
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [3 x [8 x i8]], ptr @arc4_test_ct, i64 0, i64 %33
  %35 = getelementptr inbounds [8 x i8], ptr %34, i64 0, i64 0
  %36 = call i32 @memcmp(ptr noundef %31, ptr noundef %35, i64 noundef 8) #6
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %18
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %43

43:                                               ; preds = %41, %38
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %59

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

47:                                               ; preds = %44
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %49

49:                                               ; preds = %47, %44
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !9

53:                                               ; preds = %8
  %54 = load i32, ptr %2, 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.3)
  br label %58

58:                                               ; preds = %56, %53
  br label %59

59:                                               ; preds = %58, %43
  call void @mbedtls_arc4_free(ptr noundef %7)
  %60 = load i32, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 264, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %60
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = distinct !{!9, !10}
!10 = !{!"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"

%struct.mbedtls_arc4_context = type { i32, i32, [256 x i8] }

@.str = external hidden unnamed_addr constant [18 x i8], align 1
@arc4_test_pt = external hidden local_unnamed_addr constant [3 x [8 x i8]], align 16
@arc4_test_key = external hidden constant [3 x [8 x i8]], align 16
@arc4_test_ct = external hidden constant [3 x [8 x i8]], align 16
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_arc4_init(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_arc4_free(ptr noundef) local_unnamed_addr #0

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

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

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

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

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

.split.preheader:                                 ; preds = %1
  %5 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 1)
  %6 = load i64, ptr @arc4_test_pt, align 16
  store i64 %6, ptr %2, align 8
  call void @mbedtls_arc4_setup(ptr noundef nonnull %4, ptr noundef nonnull @arc4_test_key, i32 noundef 8)
  %7 = call i32 @mbedtls_arc4_crypt(ptr noundef nonnull %4, i64 noundef 8, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %3, ptr noundef nonnull dereferenceable(8) @arc4_test_ct, i64 8)
  %.not13 = icmp eq i32 %bcmp, 0
  br i1 %.not13, label %.split.1, label %.critedge.sink.split

.split.us.preheader:                              ; preds = %1
  %8 = load i64, ptr @arc4_test_pt, align 16
  store i64 %8, ptr %2, align 8
  call void @mbedtls_arc4_setup(ptr noundef nonnull %4, ptr noundef nonnull @arc4_test_key, i32 noundef 8)
  %9 = call i32 @mbedtls_arc4_crypt(ptr noundef nonnull %4, i64 noundef 8, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %bcmp.us = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %3, ptr noundef nonnull dereferenceable(8) @arc4_test_ct, i64 8)
  %.not13.us = icmp eq i32 %bcmp.us, 0
  br i1 %.not13.us, label %.split.us.1, label %.critedge

.split.us.1:                                      ; preds = %.split.us.preheader
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @arc4_test_pt, i64 8), align 8
  store i64 %10, ptr %2, align 8
  call void @mbedtls_arc4_setup(ptr noundef nonnull %4, ptr noundef nonnull getelementptr inbounds (i8, ptr @arc4_test_key, i64 8), i32 noundef 8)
  %11 = call i32 @mbedtls_arc4_crypt(ptr noundef nonnull %4, i64 noundef 8, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %bcmp.us.1 = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %3, ptr noundef nonnull dereferenceable(8) getelementptr inbounds (i8, ptr @arc4_test_ct, i64 8), i64 8)
  %.not13.us.1 = icmp eq i32 %bcmp.us.1, 0
  br i1 %.not13.us.1, label %.split.us.2, label %.critedge

.split.us.2:                                      ; preds = %.split.us.1
  %12 = load i64, ptr getelementptr inbounds (i8, ptr @arc4_test_pt, i64 16), align 16
  store i64 %12, ptr %2, align 8
  call void @mbedtls_arc4_setup(ptr noundef nonnull %4, ptr noundef nonnull getelementptr inbounds (i8, ptr @arc4_test_key, i64 16), i32 noundef 8)
  %13 = call i32 @mbedtls_arc4_crypt(ptr noundef nonnull %4, i64 noundef 8, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %bcmp.us.2 = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %3, ptr noundef nonnull dereferenceable(8) getelementptr inbounds (i8, ptr @arc4_test_ct, i64 16), i64 8)
  %.not13.us.2 = icmp ne i32 %bcmp.us.2, 0
  %spec.select = zext i1 %.not13.us.2 to i32
  br label %.critedge

.split.1:                                         ; preds = %.split.preheader
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 2)
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @arc4_test_pt, i64 8), align 8
  store i64 %16, ptr %2, align 8
  call void @mbedtls_arc4_setup(ptr noundef nonnull %4, ptr noundef nonnull getelementptr inbounds (i8, ptr @arc4_test_key, i64 8), i32 noundef 8)
  %17 = call i32 @mbedtls_arc4_crypt(ptr noundef nonnull %4, i64 noundef 8, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %bcmp.1 = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %3, ptr noundef nonnull dereferenceable(8) getelementptr inbounds (i8, ptr @arc4_test_ct, i64 8), i64 8)
  %.not13.1 = icmp eq i32 %bcmp.1, 0
  br i1 %.not13.1, label %.split.2, label %.critedge.sink.split

.split.2:                                         ; preds = %.split.1
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 3)
  %20 = load i64, ptr getelementptr inbounds (i8, ptr @arc4_test_pt, i64 16), align 16
  store i64 %20, ptr %2, align 8
  call void @mbedtls_arc4_setup(ptr noundef nonnull %4, ptr noundef nonnull getelementptr inbounds (i8, ptr @arc4_test_key, i64 16), i32 noundef 8)
  %21 = call i32 @mbedtls_arc4_crypt(ptr noundef nonnull %4, i64 noundef 8, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %bcmp.2 = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %3, ptr noundef nonnull dereferenceable(8) getelementptr inbounds (i8, ptr @arc4_test_ct, i64 16), i64 8)
  %.not13.2 = icmp eq i32 %bcmp.2, 0
  br i1 %.not13.2, label %22, label %.critedge.sink.split

22:                                               ; preds = %.split.2
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.critedge.sink.split

.critedge.sink.split:                             ; preds = %.split.preheader, %.split.1, %.split.2, %22
  %.str.1.sink = phi ptr [ @.str.3, %22 ], [ @.str.1, %.split.2 ], [ @.str.1, %.split.1 ], [ @.str.1, %.split.preheader ]
  %.0.ph = phi i32 [ 0, %22 ], [ 1, %.split.2 ], [ 1, %.split.1 ], [ 1, %.split.preheader ]
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  br label %.critedge

.critedge:                                        ; preds = %.split.us.2, %.critedge.sink.split, %.split.us.preheader, %.split.us.1
  %.0 = phi i32 [ 1, %.split.us.1 ], [ 1, %.split.us.preheader ], [ %spec.select, %.split.us.2 ], [ %.0.ph, %.critedge.sink.split ]
  call void @mbedtls_arc4_free(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 264, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i32 %.0
}

; 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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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)"}


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