; LLVM IR from DiTo97/gol :: src/cpu (gol)

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

@stdout = external global ptr, align 8
@.str.51 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [27 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

declare i32 @fflush(ptr noundef) #1

declare i32 @usleep(i32 noundef) #1

; 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 @get_grid_status(ptr noundef byval(%struct.life) align 8 %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !5
  store i32 %9, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %10 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !13
  store i32 %11, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !12
  store i32 0, ptr %2, align 4, !tbaa !12
  br label %12

12:                                               ; preds = %47, %1
  %13 = load i32, ptr %2, align 4, !tbaa !12
  %14 = load i32, ptr %5, align 4, !tbaa !12
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %50

16:                                               ; preds = %12
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %43, %16
  %18 = load i32, ptr %3, align 4, !tbaa !12
  %19 = load i32, ptr %4, align 4, !tbaa !12
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %46

21:                                               ; preds = %17
  %22 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 5
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load i32, ptr %2, align 4, !tbaa !12
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = load i32, ptr %3, align 4, !tbaa !12
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %27, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !16, !range !18, !noundef !19
  %32 = trunc i8 %31 to i1
  %33 = zext i1 %32 to i32
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %38

35:                                               ; preds = %21
  %36 = load i32, ptr %6, align 4, !tbaa !12
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !12
  br label %41

38:                                               ; preds = %21
  %39 = load i32, ptr %7, align 4, !tbaa !12
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !12
  br label %41

41:                                               ; preds = %38, %35
  %42 = phi i32 [ %36, %35 ], [ %39, %38 ]
  br label %43

43:                                               ; preds = %41
  %44 = load i32, ptr %3, align 4, !tbaa !12
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %3, align 4, !tbaa !12
  br label %17, !llvm.loop !20

46:                                               ; preds = %17
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %2, align 4, !tbaa !12
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %2, align 4, !tbaa !12
  br label %12, !llvm.loop !22

50:                                               ; preds = %12
  %51 = load i32, ptr %6, align 4, !tbaa !12
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.51, i32 noundef %51)
  %53 = load i32, ptr %7, align 4, !tbaa !12
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.52, i32 noundef %53)
  %55 = load ptr, ptr @stdout, align 8, !tbaa !15
  %56 = call i32 @fflush(ptr noundef %55)
  %57 = call i32 @usleep(i32 noundef 320000)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !7, i64 0}
!6 = !{!"life", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !11, i64 32}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !8, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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

@stdout = external local_unnamed_addr global ptr, align 8
@.str.51 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #0

declare i32 @usleep(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @get_grid_status(ptr nocapture noundef readonly byval(%struct.life) align 8 %0) local_unnamed_addr #2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !12
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge24

.preheader.lr.ph:                                 ; preds = %1
  %6 = icmp sgt i32 %2, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load ptr, ptr %7, align 8
  br i1 %6, label %.preheader.us.preheader, label %._crit_edge24

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count33 = zext nneg i32 %4 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 8
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv30 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next31, %._crit_edge.us ]
  %.023.us = phi i32 [ 0, %.preheader.us.preheader ], [ %.2.us.lcssa, %._crit_edge.us ]
  %.01222.us = phi i32 [ 0, %.preheader.us.preheader ], [ %.214.us.lcssa, %._crit_edge.us ]
  %9 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv30
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader.us
  %11 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %.023.us, i64 0
  %12 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %.01222.us, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %11, %vector.ph ], [ %23, %vector.body ]
  %vec.phi35 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %24, %vector.body ]
  %vec.phi36 = phi <4 x i32> [ %12, %vector.ph ], [ %17, %vector.body ]
  %vec.phi37 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]
  %13 = getelementptr inbounds i8, ptr %10, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %wide.load = load <4 x i8>, ptr %13, align 1, !tbaa !14
  %wide.load38 = load <4 x i8>, ptr %14, align 1, !tbaa !14
  %15 = zext <4 x i8> %wide.load to <4 x i32>
  %16 = zext <4 x i8> %wide.load38 to <4 x i32>
  %17 = add <4 x i32> %vec.phi36, %15
  %18 = add <4 x i32> %vec.phi37, %16
  %19 = xor <4 x i8> %wide.load, <i8 1, i8 1, i8 1, i8 1>
  %20 = xor <4 x i8> %wide.load38, <i8 1, i8 1, i8 1, i8 1>
  %21 = zext <4 x i8> %19 to <4 x i32>
  %22 = zext <4 x i8> %20 to <4 x i32>
  %23 = add <4 x i32> %vec.phi, %21
  %24 = add <4 x i32> %vec.phi35, %22
  %index.next = add nuw i64 %index, 8
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %24, %23
  %26 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %bin.rdx39 = add <4 x i32> %18, %17
  %27 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx39)
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  %.119.us.ph = phi i32 [ %.023.us, %.preheader.us ], [ %26, %middle.block ]
  %.11318.us.ph = phi i32 [ %.01222.us, %.preheader.us ], [ %27, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.119.us = phi i32 [ %.2.us, %scalar.ph ], [ %.119.us.ph, %scalar.ph.preheader ]
  %.11318.us = phi i32 [ %.214.us, %scalar.ph ], [ %.11318.us.ph, %scalar.ph.preheader ]
  %28 = getelementptr inbounds i8, ptr %10, i64 %indvars.iv
  %29 = load i8, ptr %28, align 1, !tbaa !14, !range !20, !noundef !21
  %30 = zext nneg i8 %29 to i32
  %.214.us = add nsw i32 %.11318.us, %30
  %31 = xor i8 %29, 1
  %not..us = zext nneg i8 %31 to i32
  %.2.us = add nsw i32 %.119.us, %not..us
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !22

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %.214.us.lcssa = phi i32 [ %27, %middle.block ], [ %.214.us, %scalar.ph ]
  %.2.us.lcssa = phi i32 [ %26, %middle.block ], [ %.2.us, %scalar.ph ]
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count33
  br i1 %exitcond34.not, label %._crit_edge24, label %.preheader.us, !llvm.loop !23

._crit_edge24:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %1
  %.012.lcssa = phi i32 [ 0, %1 ], [ 0, %.preheader.lr.ph ], [ %.214.us.lcssa, %._crit_edge.us ]
  %.0.lcssa = phi i32 [ 0, %1 ], [ 0, %.preheader.lr.ph ], [ %.2.us.lcssa, %._crit_edge.us ]
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.51, i32 noundef %.012.lcssa)
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.52, i32 noundef %.0.lcssa)
  %34 = load ptr, ptr @stdout, align 8, !tbaa !13
  %35 = tail call i32 @fflush(ptr noundef %34)
  %36 = tail call i32 @usleep(i32 noundef 320000) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #3

attributes #0 = { nofree nounwind "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 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"life", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !8, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = distinct !{!22, !17, !19, !18}
!23 = distinct !{!23, !17}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass