; LLVM IR from greensoftwarelab/Energy-Languages :: C/chameneos-redux/chameneosredux.gcc-5 (spell_number)

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

@spell_number.buf = external hidden global [128 x i8], align 16
@spell_number.numbers = external hidden global [10 x ptr], align 16

; 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 ptr @spell_number(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca [32 x i64], align 16
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %16, %1
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = urem i64 %8, 10
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds [32 x i64], ptr %3, i64 0, i64 %10
  store i64 %9, ptr %11, align 8, !tbaa !5
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = add i64 %12, 1
  store i64 %13, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = udiv i64 %14, 10
  store i64 %15, ptr %2, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %7
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %7, label %19, !llvm.loop !9

19:                                               ; preds = %16
  store ptr @spell_number.buf, ptr %6, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %44, %19
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %45

23:                                               ; preds = %20
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = sub i64 %24, 1
  store i64 %25, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds [32 x i64], ptr %3, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds [10 x ptr], ptr @spell_number.numbers, i64 0, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  store ptr %30, ptr %5, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %36, %23
  %32 = load ptr, ptr %5, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %32, i64 0
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = icmp ne i8 %34, 0
  br i1 %35, label %36, label %44

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !11
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %5, align 8, !tbaa !11
  %39 = getelementptr inbounds i8, ptr %37, i64 0
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = load ptr, ptr %6, align 8, !tbaa !11
  %42 = getelementptr inbounds i8, ptr %41, i32 1
  store ptr %42, ptr %6, align 8, !tbaa !11
  %43 = getelementptr inbounds i8, ptr %41, i64 0
  store i8 %40, ptr %43, align 1, !tbaa !13
  br label %31, !llvm.loop !14

44:                                               ; preds = %31
  br label %20, !llvm.loop !15

45:                                               ; preds = %20
  %46 = load ptr, ptr %6, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %46, i64 0
  store i8 0, ptr %47, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 256, ptr %3) #2
  ret ptr @spell_number.buf
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !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"

@spell_number.buf = external hidden global [128 x i8], align 16
@spell_number.numbers = external hidden local_unnamed_addr global [10 x ptr], align 16

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

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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef nonnull ptr @spell_number(i64 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [32 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %2) #2
  br label %3

3:                                                ; preds = %3, %1
  %.014 = phi i64 [ %0, %1 ], [ %7, %3 ]
  %.012 = phi i64 [ 0, %1 ], [ %6, %3 ]
  %4 = urem i64 %.014, 10
  %5 = getelementptr inbounds [32 x i64], ptr %2, i64 0, i64 %.012
  store i64 %4, ptr %5, align 8, !tbaa !5
  %6 = add i64 %.012, 1
  %7 = udiv i64 %.014, 10
  %.not = icmp ult i64 %.014, 10
  br i1 %.not, label %.preheader, label %3, !llvm.loop !9

.preheader:                                       ; preds = %3
  %.not1621 = icmp eq i64 %6, 0
  br i1 %.not1621, label %._crit_edge, label %.lr.ph24.preheader

.lr.ph24.preheader:                               ; preds = %.preheader
  %8 = and i64 %.012, 1
  %lcmp.mod.not.not = icmp eq i64 %8, 0
  br i1 %lcmp.mod.not.not, label %.lr.ph24.prol, label %.lr.ph24.prol.loopexit

.lr.ph24.prol:                                    ; preds = %.lr.ph24.preheader
  %9 = getelementptr inbounds [32 x i64], ptr %2, i64 0, i64 %.012
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds [10 x ptr], ptr @spell_number.numbers, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i8, ptr %12, align 1, !tbaa !13
  %.not1718.prol = icmp eq i8 %13, 0
  br i1 %.not1718.prol, label %.lr.ph24.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph24.prol, %.lr.ph.prol
  %14 = phi i8 [ %17, %.lr.ph.prol ], [ %13, %.lr.ph24.prol ]
  %.120.prol = phi ptr [ %16, %.lr.ph.prol ], [ @spell_number.buf, %.lr.ph24.prol ]
  %.01119.prol = phi ptr [ %15, %.lr.ph.prol ], [ %12, %.lr.ph24.prol ]
  %15 = getelementptr inbounds i8, ptr %.01119.prol, i64 1
  %16 = getelementptr inbounds i8, ptr %.120.prol, i64 1
  store i8 %14, ptr %.120.prol, align 1, !tbaa !13
  %17 = load i8, ptr %15, align 1, !tbaa !13
  %.not17.prol = icmp eq i8 %17, 0
  br i1 %.not17.prol, label %.lr.ph24.prol.loopexit, label %.lr.ph.prol, !llvm.loop !14

.lr.ph24.prol.loopexit:                           ; preds = %.lr.ph24.prol, %.lr.ph.prol, %.lr.ph24.preheader
  %.1.lcssa.lcssa.unr = phi ptr [ poison, %.lr.ph24.preheader ], [ @spell_number.buf, %.lr.ph24.prol ], [ %16, %.lr.ph.prol ]
  %.023.unr = phi ptr [ @spell_number.buf, %.lr.ph24.preheader ], [ @spell_number.buf, %.lr.ph24.prol ], [ %16, %.lr.ph.prol ]
  %.11322.unr = phi i64 [ %6, %.lr.ph24.preheader ], [ %.012, %.lr.ph.prol ], [ %.012, %.lr.ph24.prol ]
  %18 = icmp eq i64 %.012, 0
  br i1 %18, label %._crit_edge, label %.lr.ph24

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph24
  %.1.lcssa = phi ptr [ %.023, %.lr.ph24 ], [ %37, %.lr.ph ]
  %19 = add i64 %.11322, -2
  %20 = getelementptr inbounds [32 x i64], ptr %2, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds [10 x ptr], ptr @spell_number.numbers, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %.not1718.1 = icmp eq i8 %24, 0
  br i1 %.not1718.1, label %.loopexit.1, label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.loopexit, %.lr.ph.1
  %25 = phi i8 [ %28, %.lr.ph.1 ], [ %24, %.loopexit ]
  %.120.1 = phi ptr [ %27, %.lr.ph.1 ], [ %.1.lcssa, %.loopexit ]
  %.01119.1 = phi ptr [ %26, %.lr.ph.1 ], [ %23, %.loopexit ]
  %26 = getelementptr inbounds i8, ptr %.01119.1, i64 1
  %27 = getelementptr inbounds i8, ptr %.120.1, i64 1
  store i8 %25, ptr %.120.1, align 1, !tbaa !13
  %28 = load i8, ptr %26, align 1, !tbaa !13
  %.not17.1 = icmp eq i8 %28, 0
  br i1 %.not17.1, label %.loopexit.1, label %.lr.ph.1, !llvm.loop !14

.loopexit.1:                                      ; preds = %.lr.ph.1, %.loopexit
  %.1.lcssa.1 = phi ptr [ %.1.lcssa, %.loopexit ], [ %27, %.lr.ph.1 ]
  %.not16.1 = icmp eq i64 %19, 0
  br i1 %.not16.1, label %._crit_edge, label %.lr.ph24, !llvm.loop !15

.lr.ph24:                                         ; preds = %.lr.ph24.prol.loopexit, %.loopexit.1
  %.023 = phi ptr [ %.1.lcssa.1, %.loopexit.1 ], [ %.023.unr, %.lr.ph24.prol.loopexit ]
  %.11322 = phi i64 [ %19, %.loopexit.1 ], [ %.11322.unr, %.lr.ph24.prol.loopexit ]
  %29 = add i64 %.11322, -1
  %30 = getelementptr inbounds [32 x i64], ptr %2, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds [10 x ptr], ptr @spell_number.numbers, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %.not1718 = icmp eq i8 %34, 0
  br i1 %.not1718, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph24, %.lr.ph
  %35 = phi i8 [ %38, %.lr.ph ], [ %34, %.lr.ph24 ]
  %.120 = phi ptr [ %37, %.lr.ph ], [ %.023, %.lr.ph24 ]
  %.01119 = phi ptr [ %36, %.lr.ph ], [ %33, %.lr.ph24 ]
  %36 = getelementptr inbounds i8, ptr %.01119, i64 1
  %37 = getelementptr inbounds i8, ptr %.120, i64 1
  store i8 %35, ptr %.120, align 1, !tbaa !13
  %38 = load i8, ptr %36, align 1, !tbaa !13
  %.not17 = icmp eq i8 %38, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph24.prol.loopexit, %.loopexit.1, %.preheader
  %.0.lcssa = phi ptr [ @spell_number.buf, %.preheader ], [ %.1.lcssa.lcssa.unr, %.lr.ph24.prol.loopexit ], [ %.1.lcssa.1, %.loopexit.1 ]
  store i8 0, ptr %.0.lcssa, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %2) #2
  ret ptr @spell_number.buf
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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" }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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