Why this LLVM IR code crashing around 32000?

Hi, I wrote this attempt to create for loop but it crashes around 32000 iterations. Sometimes a little less, sometimes a little over 32k. Its nothing to do with my custom print function I’ve tried it without it.

; ModuleID = '../../main.n'
source_filename = "../../main.n"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"

@0 = private unnamed_addr constant [8 x i8] c"{13:64}\00", align 1

declare void @print(ptr, ...)

define dso_local void @main() {
entry:
  %0 = alloca i64, align 8
  store i64 1, ptr %0, align 4
  br label %1

1:                                                ; preds = %4, %entry
  %2 = load i64, ptr %0, align 4
  %3 = icmp sle i64 %2, 9223372036854775807
  br i1 %3, label %4, label %8

4:                                                ; preds = %1
  %5 = load i64, ptr %0, align 4
  call void (ptr, ...) @print(ptr @0, i64 %5)
  %6 = load i64, ptr %0, align 4
  %7 = add i64 %6, 1
  store i64 %7, ptr %0, align 4
  br label %1

8:                                                ; preds = %1
  ret void
}

Thanks for any reply.

The loop is fine. The only thing is that it is infinite.
You do %2 <= INT_MAX, which is always true. The check passes when %2=INT_MAX, then %7 becomes INT_MIN and the loop continues.

See here the optimized version of your code (where the infinite loop is very explicit): Compiler Explorer