; LLVM IR from ninn-kou/Lux :: Independent Codes (1231_T6Q3_recursion)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @print_int128(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i128, align 16
  %5 = alloca i128, align 16
  %6 = alloca [40 x i8], align 16
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 0
  store i64 %0, ptr %9, align 16
  %10 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 1
  store i64 %1, ptr %10, align 8
  %11 = load i128, ptr %4, align 16, !tbaa !5
  store i128 %11, ptr %5, align 16, !tbaa !5
  %12 = load i128, ptr %5, align 16, !tbaa !5
  %13 = icmp eq i128 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  store i32 %15, ptr %3, align 4
  br label %42

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %17 = getelementptr inbounds [40 x i8], ptr %6, i64 0, i64 0
  %18 = getelementptr inbounds i8, ptr %17, i64 40
  %19 = getelementptr inbounds i8, ptr %18, i64 -1
  store ptr %19, ptr %7, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %28, %16
  %21 = load i128, ptr %5, align 16, !tbaa !5
  %22 = icmp ne i128 %21, 0
  br i1 %22, label %23, label %38

23:                                               ; preds = %20
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds [40 x i8], ptr %6, i64 0, i64 0
  %26 = icmp eq ptr %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %41

28:                                               ; preds = %23
  %29 = load i128, ptr %5, align 16, !tbaa !5
  %30 = srem i128 %29, 10
  %31 = trunc i128 %30 to i64
  %32 = getelementptr inbounds [11 x i8], ptr @.str.1, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %34, i32 -1
  store ptr %35, ptr %7, align 8, !tbaa !9
  store i8 %33, ptr %35, align 1, !tbaa !11
  %36 = load i128, ptr %5, align 16, !tbaa !5
  %37 = sdiv i128 %36, 10
  store i128 %37, ptr %5, align 16, !tbaa !5
  br label %20, !llvm.loop !12

38:                                               ; preds = %20
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %39)
  store i32 %40, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %41

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

42:                                               ; preds = %41, %14
  %43 = load i32, ptr %3, align 4
  ret i32 %43
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"__int128", !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @print_int128(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [40 x i8], align 16
  %.sroa.2.0.insert.ext = zext i64 %1 to i128
  %.sroa.2.0.insert.shift = shl nuw i128 %.sroa.2.0.insert.ext, 64
  %.sroa.0.0.insert.ext = zext i64 %0 to i128
  %.sroa.0.0.insert.insert = or disjoint i128 %.sroa.2.0.insert.shift, %.sroa.0.0.insert.ext
  %4 = icmp eq i128 %.sroa.0.0.insert.insert, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %27

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %3, i8 0, i64 40, i1 false)
  %8 = getelementptr inbounds i8, ptr %3, i64 39
  br label %9

9:                                                ; preds = %18, %7
  %.011 = phi ptr [ %8, %7 ], [ %23, %18 ]
  %.0710 = phi i128 [ %.sroa.0.0.insert.insert, %7 ], [ %24, %18 ]
  %.0710.frozen = freeze i128 %.0710
  %10 = sdiv i128 %.0710.frozen, 10
  %11 = mul i128 %10, 10
  %.decomposed = sub i128 %.0710.frozen, %11
  %12 = trunc nsw i128 %.decomposed to i64
  %13 = getelementptr inbounds [11 x i8], ptr @.str.1, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.011, i64 -1
  store i8 %14, ptr %15, align 1, !tbaa !5
  %.0710.off = add i128 %.0710, 9
  %.not = icmp ult i128 %.0710.off, 19
  br i1 %.not, label %25, label %16, !llvm.loop !8

16:                                               ; preds = %9
  %17 = icmp eq ptr %15, %3
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %16
  %19 = srem i128 %10, 10
  %20 = trunc nsw i128 %19 to i64
  %21 = getelementptr inbounds [11 x i8], ptr @.str.1, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %.011, i64 -2
  store i8 %22, ptr %23, align 1, !tbaa !5
  %24 = sdiv i128 %.0710, 100
  %.0710.off.1 = add nsw i128 %10, 9
  %.not.1 = icmp ult i128 %.0710.off.1, 19
  br i1 %.not.1, label %25, label %9, !llvm.loop !8

25:                                               ; preds = %18, %9
  %.lcssa = phi ptr [ %15, %9 ], [ %23, %18 ]
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %.lcssa)
  br label %.loopexit

.loopexit:                                        ; preds = %16, %25
  %.08 = phi i32 [ %26, %25 ], [ -1, %16 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  br label %27

27:                                               ; preds = %.loopexit, %5
  %.1 = phi i32 [ %6, %5 ], [ %.08, %.loopexit ]
  ret i32 %.1
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

attributes #0 = { nofree 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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass