; 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 }
%struct.timeval = type { i64, i64 }

@.str.53 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_big(ptr noundef byval(%struct.life) align 8) #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @display(ptr noundef byval(%struct.life) align 8, i1 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local double @elapsed_wtime(i64, i64, i64, i64) #0

; Function Attrs: nounwind uwtable
declare dso_local void @initialize(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local double @game(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.timeval, align 8
  %7 = alloca %struct.timeval, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  call void @initialize(ptr noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.life, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  store i32 %15, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.life, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !14
  store i32 %18, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 0.000000e+00, ptr %10, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store double 0.000000e+00, ptr %11, align 8, !tbaa !15
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  call void @display(ptr noundef byval(%struct.life) align 8 %19, i1 noundef zeroext false)
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %60, %1
  %21 = load i32, ptr %5, align 4, !tbaa !13
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.life, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %26, label %63

26:                                               ; preds = %20
  %27 = call i32 @gettimeofday(ptr noundef %6, ptr noundef null) #4
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  call void @evolve(ptr noundef %28)
  %29 = call i32 @gettimeofday(ptr noundef %7, ptr noundef null) #4
  %30 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %31 = load i64, ptr %30, align 8
  %32 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %33 = load i64, ptr %32, align 8
  %34 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %35 = load i64, ptr %34, align 8
  %36 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %37 = load i64, ptr %36, align 8
  %38 = call double @elapsed_wtime(i64 %31, i64 %33, i64 %35, i64 %37)
  store double %38, ptr %11, align 8, !tbaa !15
  %39 = load double, ptr %11, align 8, !tbaa !15
  %40 = load double, ptr %10, align 8, !tbaa !15
  %41 = fadd double %40, %39
  store double %41, ptr %10, align 8, !tbaa !15
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = call zeroext i1 @is_big(ptr noundef byval(%struct.life) align 8 %42)
  br i1 %43, label %44, label %57

44:                                               ; preds = %26
  %45 = load i32, ptr %5, align 4, !tbaa !13
  %46 = load double, ptr %11, align 8, !tbaa !15
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.53, i32 noundef %45, double noundef %46)
  %48 = load i32, ptr %5, align 4, !tbaa !13
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.life, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !16
  %52 = sub nsw i32 %51, 1
  %53 = icmp eq i32 %48, %52
  br i1 %53, label %54, label %56

54:                                               ; preds = %44
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  call void @display(ptr noundef byval(%struct.life) align 8 %55, i1 noundef zeroext true)
  br label %56

56:                                               ; preds = %54, %44
  br label %59

57:                                               ; preds = %26
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  call void @display(ptr noundef byval(%struct.life) align 8 %58, i1 noundef zeroext true)
  br label %59

59:                                               ; preds = %57, %56
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %5, align 4, !tbaa !13
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !13
  br label %20, !llvm.loop !17

63:                                               ; preds = %20
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.life, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8, !tbaa !16
  %67 = load double, ptr %10, align 8, !tbaa !15
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.54, i32 noundef %66, double noundef %67)
  %69 = load double, ptr %10, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret double %69
}

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @evolve(ptr noundef) #0

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

%struct.life = type { i32, i32, i32, double, i32, ptr, ptr, ptr, ptr }
%struct.timeval = type { i64, i64 }

@.str.53 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_big(ptr noundef byval(%struct.life) align 8) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @display(ptr noundef byval(%struct.life) align 8, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @elapsed_wtime(i64, i64, i64, i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @initialize(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef double @game(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.timeval, align 8
  %3 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  tail call void @initialize(ptr noundef %0)
  tail call void @display(ptr noundef byval(%struct.life) align 8 %0, i1 noundef zeroext false)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  br label %9

9:                                                ; preds = %.lr.ph, %24
  %.022 = phi double [ 0.000000e+00, %.lr.ph ], [ %17, %24 ]
  %.01921 = phi i32 [ 0, %.lr.ph ], [ %25, %24 ]
  %10 = call i32 @gettimeofday(ptr noundef nonnull %2, ptr noundef null) #3
  tail call void @evolve(ptr noundef nonnull %0)
  %11 = call i32 @gettimeofday(ptr noundef nonnull %3, ptr noundef null) #3
  %12 = load i64, ptr %2, align 8
  %13 = load i64, ptr %7, align 8
  %14 = load i64, ptr %3, align 8
  %15 = load i64, ptr %8, align 8
  %16 = tail call double @elapsed_wtime(i64 %12, i64 %13, i64 %14, i64 %15)
  %17 = fadd double %.022, %16
  %18 = tail call zeroext i1 @is_big(ptr noundef nonnull byval(%struct.life) align 8 %0)
  br i1 %18, label %19, label %.sink.split

19:                                               ; preds = %9
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.53, i32 noundef %.01921, double noundef %16)
  %21 = load i32, ptr %4, align 8, !tbaa !5
  %22 = add nsw i32 %21, -1
  %23 = icmp eq i32 %.01921, %22
  br i1 %23, label %.sink.split, label %24

.sink.split:                                      ; preds = %9, %19
  tail call void @display(ptr noundef nonnull byval(%struct.life) align 8 %0, i1 noundef zeroext true)
  br label %24

24:                                               ; preds = %.sink.split, %19
  %25 = add nuw nsw i32 %.01921, 1
  %26 = load i32, ptr %4, align 8, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %9, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %24, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %17, %24 ]
  %.lcssa = phi i32 [ %5, %1 ], [ %26, %24 ]
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.54, i32 noundef %.lcssa, double noundef %.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  ret double %.0.lcssa
}

; Function Attrs: nofree nounwind
declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @evolve(ptr noundef) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 8}
!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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