; LLVM IR from rociodellasala/TP3_SO :: Kernel (converter)

; 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @uintToBase(i64 noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %13, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %36, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %6, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = urem i64 %15, %17
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %11, align 4, !tbaa !11
  %20 = load i32, ptr %11, align 4, !tbaa !11
  %21 = icmp ult i32 %20, 10
  br i1 %21, label %22, label %25

22:                                               ; preds = %14
  %23 = load i32, ptr %11, align 4, !tbaa !11
  %24 = add i32 %23, 48
  br label %29

25:                                               ; preds = %14
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = add i32 %26, 65
  %28 = sub i32 %27, 10
  br label %29

29:                                               ; preds = %25, %22
  %30 = phi i32 [ %24, %22 ], [ %28, %25 ]
  %31 = trunc i32 %30 to i8
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %32, i32 1
  store ptr %33, ptr %7, align 8, !tbaa !9
  store i8 %31, ptr %32, align 1, !tbaa !13
  %34 = load i32, ptr %10, align 4, !tbaa !11
  %35 = add i32 %34, 1
  store i32 %35, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %36

36:                                               ; preds = %29
  %37 = load i32, ptr %6, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = udiv i64 %39, %38
  store i64 %40, ptr %4, align 8, !tbaa !5
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %14, label %42, !llvm.loop !14

42:                                               ; preds = %36
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  store i8 0, ptr %43, align 1, !tbaa !13
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %44, ptr %8, align 8, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %45, i64 -1
  store ptr %46, ptr %9, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %51, %42
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  %50 = icmp ult ptr %48, %49
  br i1 %50, label %51, label %63

51:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  %52 = load ptr, ptr %8, align 8, !tbaa !9
  %53 = load i8, ptr %52, align 1, !tbaa !13
  store i8 %53, ptr %12, align 1, !tbaa !13
  %54 = load ptr, ptr %9, align 8, !tbaa !9
  %55 = load i8, ptr %54, align 1, !tbaa !13
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  store i8 %55, ptr %56, align 1, !tbaa !13
  %57 = load i8, ptr %12, align 1, !tbaa !13
  %58 = load ptr, ptr %9, align 8, !tbaa !9
  store i8 %57, ptr %58, align 1, !tbaa !13
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %59, i32 1
  store ptr %60, ptr %8, align 8, !tbaa !9
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = getelementptr inbounds i8, ptr %61, i32 -1
  store ptr %62, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  br label %47, !llvm.loop !16

63:                                               ; preds = %47
  %64 = load i32, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 %64
}

; 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

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 = { 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 = !{!"long", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @uintToBase(i64 noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i32 %2 to i64
  br label %5

5:                                                ; preds = %5, %3
  %.023 = phi i32 [ 0, %3 ], [ %13, %5 ]
  %.022 = phi ptr [ %1, %3 ], [ %12, %5 ]
  %.0 = phi i64 [ %0, %3 ], [ %14, %5 ]
  %6 = urem i64 %.0, %4
  %7 = trunc i64 %6 to i8
  %8 = icmp ult i64 %6, 10
  %9 = or i8 %7, 48
  %10 = add i8 %7, 55
  %11 = select i1 %8, i8 %9, i8 %10
  %12 = getelementptr inbounds i8, ptr %.022, i64 1
  store i8 %11, ptr %.022, align 1, !tbaa !5
  %13 = add i32 %.023, 1
  %14 = udiv i64 %.0, %4
  %.not = icmp ult i64 %.0, %4
  br i1 %.not, label %15, label %5, !llvm.loop !8

15:                                               ; preds = %5
  store i8 0, ptr %12, align 1, !tbaa !5
  %16 = icmp ugt ptr %.022, %1
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %15, %.lr.ph
  %.02430 = phi ptr [ %20, %.lr.ph ], [ %.022, %15 ]
  %.02529 = phi ptr [ %19, %.lr.ph ], [ %1, %15 ]
  %17 = load i8, ptr %.02529, align 1, !tbaa !5
  %18 = load i8, ptr %.02430, align 1, !tbaa !5
  store i8 %18, ptr %.02529, align 1, !tbaa !5
  store i8 %17, ptr %.02430, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.02529, i64 1
  %20 = getelementptr inbounds i8, ptr %.02430, i64 -1
  %21 = icmp ult ptr %19, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %15
  ret i32 %13
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

!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"}
!10 = distinct !{!10, !9}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass