; LLVM IR from mist64/perfect6502 :: measure (resetChip_test)

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

@state = external dso_local global ptr, align 8
@cycle = external global i32, align 4

; 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 @resetChip_test() #1 {
  %1 = alloca i32, align 4
  %2 = call ptr (...) @initAndResetChip()
  store ptr %2, ptr @state, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %3

3:                                                ; preds = %9, %0
  %4 = load i32, ptr %1, align 4, !tbaa !9
  %5 = icmp slt i32 %4, 62
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %12

7:                                                ; preds = %3
  %8 = load ptr, ptr @state, align 8, !tbaa !5
  call void @step(ptr noundef %8)
  br label %9

9:                                                ; preds = %7
  %10 = load i32, ptr %1, align 4, !tbaa !9
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %1, align 4, !tbaa !9
  br label %3, !llvm.loop !11

12:                                               ; preds = %6
  store i32 -1, ptr @cycle, align 4, !tbaa !9
  ret void
}

declare ptr @initAndResetChip(...) #2

declare void @step(ptr noundef) #2

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 = { "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 #3 = { 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 = !{!"any pointer", !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 = distinct !{!11, !12}
!12 = !{!"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"

@state = external dso_local local_unnamed_addr global ptr, align 8
@cycle = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @resetChip_test() local_unnamed_addr #0 {
  %1 = tail call ptr (...) @initAndResetChip() #2
  store ptr %1, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %1) #2
  %2 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %2) #2
  %3 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %3) #2
  %4 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %4) #2
  %5 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %5) #2
  %6 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %6) #2
  %7 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %7) #2
  %8 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %8) #2
  %9 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %9) #2
  %10 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %10) #2
  %11 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %11) #2
  %12 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %12) #2
  %13 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %13) #2
  %14 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %14) #2
  %15 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %15) #2
  %16 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %16) #2
  %17 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %17) #2
  %18 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %18) #2
  %19 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %19) #2
  %20 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %20) #2
  %21 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %21) #2
  %22 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %22) #2
  %23 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %23) #2
  %24 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %24) #2
  %25 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %25) #2
  %26 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %26) #2
  %27 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %27) #2
  %28 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %28) #2
  %29 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %29) #2
  %30 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %30) #2
  %31 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %31) #2
  %32 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %32) #2
  %33 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %33) #2
  %34 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %34) #2
  %35 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %35) #2
  %36 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %36) #2
  %37 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %37) #2
  %38 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %38) #2
  %39 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %39) #2
  %40 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %40) #2
  %41 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %41) #2
  %42 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %42) #2
  %43 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %43) #2
  %44 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %44) #2
  %45 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %45) #2
  %46 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %46) #2
  %47 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %47) #2
  %48 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %48) #2
  %49 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %49) #2
  %50 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %50) #2
  %51 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %51) #2
  %52 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %52) #2
  %53 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %53) #2
  %54 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %54) #2
  %55 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %55) #2
  %56 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %56) #2
  %57 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %57) #2
  %58 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %58) #2
  %59 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %59) #2
  %60 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %60) #2
  %61 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %61) #2
  %62 = load ptr, ptr @state, align 8, !tbaa !5
  tail call void @step(ptr noundef %62) #2
  store i32 -1, ptr @cycle, align 4, !tbaa !9
  ret void
}

declare ptr @initAndResetChip(...) local_unnamed_addr #1

declare void @step(ptr noundef) local_unnamed_addr #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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass