; LLVM IR from jingweizhanghuai/Morn :: test (test_large_integer)

; 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.1 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@__FUNCTION__.test_OpenSSL = external hidden unnamed_addr constant [13 x i8], align 1

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

declare void @_mTimerBegin(ptr noundef) #1

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

declare float @_mTimerEnd(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @test_OpenSSL(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %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 i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %10 = call ptr @BN_new()
  store ptr %10, ptr %6, align 8, !tbaa !9
  call void @_mTimerBegin(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %34, %2
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sdiv i32 1000000, %13
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %37

17:                                               ; preds = %11
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = call i32 @BN_set_word(ptr noundef %18, i64 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %30, %17
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %33

25:                                               ; preds = %20
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = call i32 @BN_mul_word(ptr noundef %26, i64 noundef %28)
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %9, align 4, !tbaa !5
  br label %20, !llvm.loop !11

33:                                               ; preds = %24
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %7, align 4, !tbaa !5
  br label %11, !llvm.loop !13

37:                                               ; preds = %16
  %38 = call float @_mTimerEnd(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 36, ptr noundef @__FUNCTION__.test_OpenSSL)
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = call ptr @BN_bn2dec(ptr noundef %40)
  %42 = call ptr @strcpy(ptr noundef %39, ptr noundef %41) #4
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  call void @BN_free(ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %44 = load i32, ptr %3, align 4
  ret i32 %44
}

declare ptr @BN_new() #1

declare i32 @BN_set_word(ptr noundef, i64 noundef) #1

declare i32 @BN_mul_word(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

declare ptr @BN_bn2dec(ptr noundef) #1

declare void @BN_free(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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.1 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@__FUNCTION__.test_OpenSSL = external hidden unnamed_addr constant [13 x i8], align 1

declare void @_mTimerBegin(ptr noundef) local_unnamed_addr #0

declare float @_mTimerEnd(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @test_OpenSSL(i32 noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @BN_new() #3
  tail call void @_mTimerBegin(ptr noundef nonnull @.str.3) #3
  %4 = sdiv i32 1000000, %0
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph17, label %._crit_edge18

.lr.ph17:                                         ; preds = %2
  %.not13 = icmp slt i32 %0, 1
  br i1 %.not13, label %.lr.ph17.split.us, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph17
  %6 = add nuw i32 %0, 1
  %wide.trip.count = zext i32 %6 to i64
  br label %.lr.ph

.lr.ph17.split.us:                                ; preds = %.lr.ph17, %.lr.ph17.split.us
  %.01215.us = phi i32 [ %8, %.lr.ph17.split.us ], [ 0, %.lr.ph17 ]
  %7 = tail call i32 @BN_set_word(ptr noundef %3, i64 noundef 1) #3
  %8 = add nuw nsw i32 %.01215.us, 1
  %exitcond22.not = icmp eq i32 %8, %4
  br i1 %exitcond22.not, label %._crit_edge18, label %.lr.ph17.split.us, !llvm.loop !5

._crit_edge18:                                    ; preds = %._crit_edge, %.lr.ph17.split.us, %2
  %9 = tail call float @_mTimerEnd(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 36, ptr noundef nonnull @__FUNCTION__.test_OpenSSL) #3
  %10 = tail call ptr @BN_bn2dec(ptr noundef %3) #3
  %11 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %10) #3
  tail call void @BN_free(ptr noundef %3) #3
  ret i32 undef

.lr.ph:                                           ; preds = %.lr.ph.preheader, %._crit_edge
  %.01215 = phi i32 [ %13, %._crit_edge ], [ 0, %.lr.ph.preheader ]
  %12 = tail call i32 @BN_set_word(ptr noundef %3, i64 noundef 1) #3
  br label %14

._crit_edge:                                      ; preds = %14
  %13 = add nuw nsw i32 %.01215, 1
  %exitcond21.not = icmp eq i32 %13, %4
  br i1 %exitcond21.not, label %._crit_edge18, label %.lr.ph, !llvm.loop !5

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %15 = tail call i32 @BN_mul_word(ptr noundef %3, i64 noundef %indvars.iv) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !7
}

declare ptr @BN_new() local_unnamed_addr #0

declare i32 @BN_set_word(ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @BN_mul_word(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #2

declare ptr @BN_bn2dec(ptr noundef) local_unnamed_addr #0

declare void @BN_free(ptr noundef) local_unnamed_addr #0

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass