; LLVM IR from AlgoGenesis/C :: Mathematical Algorithms/Chinese Remainder Theorem (program)

; 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 [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = call ptr @llvm.stacksave.p0()
  store ptr %17, ptr %3, align 8
  %18 = alloca i32, i64 %16, align 16
  store i64 %16, ptr %4, align 8
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = alloca i32, i64 %20, align 16
  store i64 %20, ptr %5, align 8
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %33, %0
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %36

28:                                               ; preds = %23
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %18, i64 %30
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %31)
  br label %33

33:                                               ; preds = %28
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %6, align 4, !tbaa !5
  br label %23, !llvm.loop !9

36:                                               ; preds = %27
  %37 = call i32 (ptr, ...) @printf(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 %38

38:                                               ; preds = %48, %36
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %51

43:                                               ; preds = %38
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %21, i64 %45
  %47 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %46)
  br label %48

48:                                               ; preds = %43
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %38, !llvm.loop !11

51:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %85, %51
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  store i32 8, ptr %9, align 4
  br label %88

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %10, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %79, %57
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %60
  store i32 11, ptr %9, align 4
  br label %82

65:                                               ; preds = %60
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %18, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %18, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = call i32 @gcd(i32 noundef %69, i32 noundef %73)
  %75 = icmp ne i32 %74, 1
  br i1 %75, label %76, label %78

76:                                               ; preds = %65
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %82

78:                                               ; preds = %65
  br label %79

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

82:                                               ; preds = %76, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %83 = load i32, ptr %9, align 4
  switch i32 %83, label %88 [
    i32 11, label %84
  ]

84:                                               ; preds = %82
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %8, align 4, !tbaa !5
  br label %52, !llvm.loop !13

88:                                               ; preds = %82, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %89 = load i32, ptr %9, align 4
  switch i32 %89, label %96 [
    i32 8, label %90
  ]

90:                                               ; preds = %88
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %91 = load i32, ptr %2, align 4, !tbaa !5
  %92 = call i32 @chineseRemainder(ptr noundef %18, ptr noundef %21, i32 noundef %91, ptr noundef %11)
  store i32 %92, ptr %12, align 4, !tbaa !5
  %93 = load i32, ptr %12, align 4, !tbaa !5
  %94 = load i32, ptr %11, align 4, !tbaa !5
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %93, i32 noundef %94)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %96

96:                                               ; preds = %90, %88
  %97 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %97)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %98 = load i32, ptr %1, align 4
  ret i32 %98
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; 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 [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcd(i32 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 @chineseRemainder(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = call ptr @llvm.stacksave.p0()
  %8 = alloca i32, i64 %6, align 16
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = alloca i32, i64 %10, align 16
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph32, label %.thread27

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %18 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %18)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %indvars.iv.next, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph32
  %.not2537 = icmp sgt i32 %25, 0
  br i1 %.not2537, label %.lr.ph39, label %.thread27

.lr.ph32:                                         ; preds = %._crit_edge, %.lr.ph32
  %indvars.iv41 = phi i64 [ %indvars.iv.next42, %.lr.ph32 ], [ 0, %._crit_edge ]
  %23 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv41
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %23)
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next42, %26
  br i1 %27, label %.lr.ph32, label %.preheader, !llvm.loop !11

.loopexit.loopexit:                               ; preds = %32
  %.pre = sext i32 %33 to i64
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.lr.ph39
  %.pre-phi = phi i64 [ %.pre, %.loopexit.loopexit ], [ %30, %.lr.ph39 ]
  %28 = phi i32 [ %33, %.loopexit.loopexit ], [ %29, %.lr.ph39 ]
  %.not25 = icmp slt i64 %indvars.iv.next50, %.pre-phi
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  br i1 %.not25, label %.lr.ph39, label %.thread27

.lr.ph39:                                         ; preds = %.preheader, %.loopexit
  %29 = phi i32 [ %28, %.loopexit ], [ %25, %.preheader ]
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %.loopexit ], [ 0, %.preheader ]
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %.loopexit ], [ 1, %.preheader ]
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %30 = sext i32 %29 to i64
  %.not2433 = icmp slt i64 %indvars.iv.next50, %30
  br i1 %.not2433, label %.lr.ph36, label %.loopexit

.lr.ph36:                                         ; preds = %.lr.ph39
  %31 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv49
  br label %35

32:                                               ; preds = %35
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = trunc nuw i64 %indvars.iv.next47 to i32
  %.not24 = icmp sgt i32 %33, %34
  br i1 %.not24, label %35, label %.loopexit.loopexit, !llvm.loop !12

35:                                               ; preds = %.lr.ph36, %32
  %indvars.iv46 = phi i64 [ %indvars.iv44, %.lr.ph36 ], [ %indvars.iv.next47, %32 ]
  %36 = load i32, ptr %31, align 4, !tbaa !5
  %37 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv46
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = call i32 @gcd(i32 noundef %36, i32 noundef %38)
  %.not = icmp eq i32 %39, 1
  br i1 %.not, label %32, label %40

40:                                               ; preds = %35
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %46

.thread27:                                        ; preds = %.loopexit, %._crit_edge, %.preheader
  %42 = phi i32 [ %25, %.preheader ], [ %16, %._crit_edge ], [ %28, %.loopexit ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %43 = call i32 @chineseRemainder(ptr noundef nonnull %8, ptr noundef nonnull %11, i32 noundef %42, ptr noundef nonnull %2)
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %43, i32 noundef %44)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %46

46:                                               ; preds = %40, %.thread27
  %.3 = phi i32 [ 0, %.thread27 ], [ 1, %40 ]
  call void @llvm.stackrestore.p0(ptr %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 %.3
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass