; LLVM IR from jingweizhanghuai/Morn :: src/math (morn_calculate)

; 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.CalculateFunction = type { [32 x i8], %union.anon }
%union.anon = type { ptr }

@morn_calculate_function_num = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [81 x i8], align 1
@__FUNCTION__.m_CalculateFunction = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@morn_calculate_function = external dso_local global [128 x %struct.CalculateFunction], align 16

; Function Attrs: nounwind uwtable
define dso_local void @m_CalculateFunction(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  %11 = zext i1 %10 to i32
  store i32 %11, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  %15 = load i32, ptr %5, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %15, i32 noundef -1, ptr noundef @.str, i32 noundef 32, ptr noundef @__FUNCTION__.m_CalculateFunction, ptr noundef @.str.1)
  br label %16

16:                                               ; preds = %14, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %17

17:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %18 = load i32, ptr @morn_calculate_function_num, align 4, !tbaa !9
  store i32 %18, ptr %6, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp sgt i32 %20, 128
  %22 = zext i1 %21 to i32
  store i32 %22, ptr %7, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %19
  %26 = load i32, ptr %7, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %26, i32 noundef -1, ptr noundef @.str, i32 noundef 34, ptr noundef @__FUNCTION__.m_CalculateFunction, ptr noundef @.str.2)
  br label %27

27:                                               ; preds = %25, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr @morn_calculate_function_num, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @morn_calculate_function_num, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [128 x %struct.CalculateFunction], ptr @morn_calculate_function, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.CalculateFunction, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [32 x i8], ptr %35, i64 0, i64 0
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = call ptr @strncpy(ptr noundef %36, ptr noundef %37, i64 noundef 32) #4
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [128 x %struct.CalculateFunction], ptr @morn_calculate_function, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.CalculateFunction, ptr %42, i32 0, i32 1
  store ptr %39, ptr %43, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret void
}

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #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 = { 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 = { 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 = !{!"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}


; 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.CalculateFunction = type { [32 x i8], %union.anon }
%union.anon = type { ptr }

@morn_calculate_function_num = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [81 x i8], align 1
@__FUNCTION__.m_CalculateFunction = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@morn_calculate_function = external dso_local global [128 x %struct.CalculateFunction], align 16

; Function Attrs: nounwind uwtable
define dso_local void @m_CalculateFunction(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 32, ptr noundef nonnull @__FUNCTION__.m_CalculateFunction, ptr noundef nonnull @.str.1) #3
  br label %5

5:                                                ; preds = %4, %2
  %6 = load i32, ptr @morn_calculate_function_num, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 128
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 34, ptr noundef nonnull @__FUNCTION__.m_CalculateFunction, ptr noundef nonnull @.str.2) #3
  %.pre = load i32, ptr @morn_calculate_function_num, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %8, %5
  %10 = phi i32 [ %.pre, %8 ], [ %6, %5 ]
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @morn_calculate_function_num, align 4, !tbaa !5
  %12 = sext i32 %6 to i64
  %13 = getelementptr inbounds [128 x %struct.CalculateFunction], ptr @morn_calculate_function, i64 0, i64 %12
  %14 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 32) #3
  %15 = getelementptr inbounds i8, ptr %13, i64 32
  store ptr %1, ptr %15, align 8, !tbaa !9
  ret void
}

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

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

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 = { "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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass