; LLVM IR from jingweizhanghuai/Morn :: src/math (morn_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"

%struct.MArray = type { i32, i16, %union.anon }
%union.anon = type { ptr }

@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__FUNCTION__.LIntAppend = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 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

; 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
define dso_local void @LIntAppend(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MArray, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp slt i32 %10, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %109

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MArray, ptr %17, i32 0, i32 1
  %19 = load i16, ptr %18, align 4, !tbaa !14
  %20 = sext i16 %19 to i64
  %21 = icmp ne i64 %20, 8
  br i1 %21, label %22, label %59

22:                                               ; preds = %16
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 2, ptr %5, align 4, !tbaa !9
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = add nsw i32 %28, 0
  call void @ArrayRedefine(ptr noundef %27, i32 noundef %29, i32 noundef -1, ptr noundef null)
  br label %55

30:                                               ; preds = %23
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 2
  br i1 %32, label %33, label %37

33:                                               ; preds = %30
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = add nsw i32 %35, 0
  call void @ArrayRedefine(ptr noundef %34, i32 noundef %36, i32 noundef 8, ptr noundef null)
  br label %54

37:                                               ; preds = %30
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 3
  br i1 %39, label %40, label %44

40:                                               ; preds = %37
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = add nsw i32 %42, 0
  call void @ArrayRedefine(ptr noundef %41, i32 noundef %43, i32 noundef 8, ptr noundef inttoptr (i64 -1 to ptr))
  br label %53

44:                                               ; preds = %37
  br label %45

45:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !9
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %45
  %49 = load i32, ptr %6, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %49, i32 noundef -1, ptr noundef @.str.1, i32 noundef 72, ptr noundef @__FUNCTION__.LIntAppend, ptr noundef @.str.2)
  br label %50

50:                                               ; preds = %48, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %40
  br label %54

54:                                               ; preds = %53, %33
  br label %55

55:                                               ; preds = %54, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.MArray, ptr %57, i32 0, i32 0
  store i32 2, ptr %58, align 8, !tbaa !11
  br label %109

59:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MArray, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !11
  store i32 %62, ptr %7, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %64 = load i8, ptr @.str.3, align 1, !tbaa !15
  %65 = sext i8 %64 to i32
  %66 = icmp ne i32 %65, 0
  %67 = zext i1 %66 to i32
  store i32 %67, ptr %8, align 4, !tbaa !9
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = icmp eq i32 %68, 1
  br i1 %69, label %70, label %80

70:                                               ; preds = %63
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.MArray, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !11
  %76 = sub nsw i32 %72, %75
  %77 = add nsw i32 %76, 0
  %78 = sext i32 %77 to i64
  %79 = trunc i64 %78 to i32
  call void @m_ArrayAppend(ptr noundef %71, ptr noundef null, i32 noundef %79)
  br label %103

80:                                               ; preds = %63
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = icmp eq i32 %81, 2
  br i1 %82, label %83, label %93

83:                                               ; preds = %80
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = load i32, ptr %4, align 4, !tbaa !9
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.MArray, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 8, !tbaa !11
  %89 = sub nsw i32 %85, %88
  %90 = add nsw i32 %89, 0
  %91 = sext i32 %90 to i64
  %92 = inttoptr i64 %91 to ptr
  call void @m_ArrayAppend(ptr noundef %84, ptr noundef %92, i32 noundef -1)
  br label %102

93:                                               ; preds = %80
  br label %94

94:                                               ; preds = %93
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !9
  %95 = load i32, ptr %9, align 4, !tbaa !9
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %99

97:                                               ; preds = %94
  %98 = load i32, ptr %9, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %98, i32 noundef -1, ptr noundef @.str.1, i32 noundef 73, ptr noundef @__FUNCTION__.LIntAppend, ptr noundef @.str.2)
  br label %99

99:                                               ; preds = %97, %94
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %100

100:                                              ; preds = %99
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101, %83
  br label %103

103:                                              ; preds = %102, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %7, align 4, !tbaa !9
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.MArray, ptr %107, i32 0, i32 0
  store i32 %106, ptr %108, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %109

109:                                              ; preds = %105, %56, %15
  ret void
}

declare void @ArrayRedefine(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #2

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

declare void @m_ArrayAppend(ptr noundef, ptr noundef, i32 noundef) #2

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 }

!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 = !{!12, !10, i64 0}
!12 = !{!"MArray", !10, i64 0, !13, i64 4, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{!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"

@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__FUNCTION__.LIntAppend = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @LIntAppend(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, %1
  br i1 %4, label %14, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i16, ptr %6, align 4, !tbaa !11
  %.not = icmp eq i16 %7, 8
  br i1 %.not, label %9, label %8

8:                                                ; preds = %5
  tail call void @ArrayRedefine(ptr noundef nonnull %0, i32 noundef %1, i32 noundef 8, ptr noundef null) #2
  br label %.sink.split

9:                                                ; preds = %5
  %10 = load i8, ptr @.str.3, align 1, !tbaa !12
  %.not28 = icmp eq i8 %10, 0
  br i1 %.not28, label %13, label %11

11:                                               ; preds = %9
  %12 = sub nsw i32 %1, %3
  tail call void @m_ArrayAppend(ptr noundef nonnull %0, ptr noundef null, i32 noundef %12) #2
  br label %.sink.split

13:                                               ; preds = %9
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.1, i32 noundef 73, ptr noundef nonnull @__FUNCTION__.LIntAppend, ptr noundef nonnull @.str.2) #2
  br label %.sink.split

.sink.split:                                      ; preds = %11, %13, %8
  %.sink = phi i32 [ 2, %8 ], [ %3, %13 ], [ %3, %11 ]
  store i32 %.sink, ptr %0, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %.sink.split, %2
  ret void
}

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

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

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

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


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