; LLVM IR from freakout42/macrocalc :: mc/mex (display)

; 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.TERM = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@ttcol = external dso_local global i32, align 4
@term = external global %struct.TERM, align 8

; 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 @mlputli(i64 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = icmp slt i64 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = sub nsw i64 0, %9
  store i64 %10, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr getelementptr inbounds (%struct.TERM, ptr @term, i32 0, i32 5), align 8, !tbaa !11
  %12 = call i32 (i32, ...) %11(i32 noundef 45)
  br label %13

13:                                               ; preds = %8, %2
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = sdiv i64 %14, %16
  store i64 %17, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %13
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !9
  call void @mlputli(i64 noundef %21, i32 noundef %22)
  br label %23

23:                                               ; preds = %20, %13
  %24 = load ptr, ptr getelementptr inbounds (%struct.TERM, ptr @term, i32 0, i32 5), align 8, !tbaa !11
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = srem i64 %25, %27
  %29 = trunc i64 %28 to i32
  %30 = add nsw i32 %29, 48
  %31 = call i32 (i32, ...) %24(i32 noundef %30)
  %32 = load i32, ptr @ttcol, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @ttcol, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 32}
!12 = !{!"", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96}
!13 = !{!"any pointer", !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"

%struct.TERM = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@ttcol = external dso_local local_unnamed_addr global i32, align 4
@term = external local_unnamed_addr global %struct.TERM, align 8

; Function Attrs: nounwind uwtable
define dso_local void @mlputli(i64 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i64 %0, 0
  br i1 %3, label %4, label %8

4:                                                ; preds = %2
  %5 = sub nsw i64 0, %0
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @term, i64 32), align 8, !tbaa !5
  %7 = tail call i32 (i32, ...) %6(i32 noundef 45) #1
  br label %8

8:                                                ; preds = %4, %2
  %.0 = phi i64 [ %5, %4 ], [ %0, %2 ]
  %9 = sext i32 %1 to i64
  %10 = sdiv i64 %.0, %9
  %11 = srem i64 %.0, %9
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %8
  tail call void @mlputli(i64 noundef %10, i32 noundef %1)
  br label %13

13:                                               ; preds = %12, %8
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @term, i64 32), align 8, !tbaa !5
  %15 = trunc nuw nsw i64 %11 to i32
  %16 = add nuw nsw i32 %15, 48
  %17 = tail call i32 (i32, ...) %14(i32 noundef %16) #1
  %18 = load i32, ptr @ttcol, align 4, !tbaa !11
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @ttcol, align 4, !tbaa !11
  ret void
}

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 = { 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, !10, i64 32}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}


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