; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@DEFAULT_LOGS_DIR = external dso_local global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [39 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

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @init_log_file(ptr noundef byval(%struct.life) align 8 %0, i32 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca [100 x i8], align 16
  %6 = alloca [7 x i8], align 1
  %7 = alloca [8 x i8], align 1
  %8 = alloca [15 x i8], align 1
  %9 = alloca %struct.stat, align 8
  %10 = alloca ptr, align 8
  store i32 %1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %11 = load ptr, ptr @DEFAULT_LOGS_DIR, align 8, !tbaa !9
  store ptr %11, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 100, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 7, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 15, ptr %8) #5
  %12 = getelementptr inbounds [7 x i8], ptr %6, i64 0, i64 0
  %13 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %12, ptr noundef @.str.13) #5
  %14 = getelementptr inbounds [8 x i8], ptr %7, i64 0, i64 0
  %15 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %14, ptr noundef @.str.13) #5
  %16 = getelementptr inbounds [15 x i8], ptr %8, i64 0, i64 0
  %17 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %16, ptr noundef @.str.13) #5
  call void @llvm.lifetime.start.p0(i64 144, ptr %9) #5
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 144, i1 false)
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = call i32 @stat(ptr noundef %18, ptr noundef %9) #5
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %24

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = call i32 @mkdir(ptr noundef %22, i32 noundef 484) #5
  br label %24

24:                                               ; preds = %21, %2
  %25 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %42

28:                                               ; preds = %24
  %29 = getelementptr inbounds [100 x i8], ptr %5, i64 0, i64 0
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = getelementptr inbounds [8 x i8], ptr %7, i64 0, i64 0
  %32 = getelementptr inbounds [7 x i8], ptr %6, i64 0, i64 0
  %33 = getelementptr inbounds [15 x i8], ptr %8, i64 0, i64 0
  %34 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !15
  %38 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !16
  %40 = call i64 @time(ptr noundef null) #5
  %41 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %29, ptr noundef @.str.14, ptr noundef %30, ptr noundef %31, ptr noundef %32, ptr noundef %33, i32 noundef %35, i32 noundef %37, i32 noundef %39, i64 noundef %40) #5
  br label %60

42:                                               ; preds = %24
  %43 = getelementptr inbounds [100 x i8], ptr %5, i64 0, i64 0
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  %45 = getelementptr inbounds [8 x i8], ptr %7, i64 0, i64 0
  %46 = getelementptr inbounds [7 x i8], ptr %6, i64 0, i64 0
  %47 = getelementptr inbounds [15 x i8], ptr %8, i64 0, i64 0
  %48 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !14
  %50 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !16
  %54 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 3
  %55 = load double, ptr %54, align 8, !tbaa !17
  %56 = getelementptr inbounds %struct.life, ptr %0, i32 0, i32 4
  %57 = load i32, ptr %56, align 8, !tbaa !18
  %58 = call i64 @time(ptr noundef null) #5
  %59 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %43, ptr noundef @.str.15, ptr noundef %44, ptr noundef %45, ptr noundef %46, ptr noundef %47, i32 noundef %49, i32 noundef %51, i32 noundef %53, double noundef %55, i32 noundef %57, i64 noundef %58) #5
  br label %60

60:                                               ; preds = %42, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %61 = getelementptr inbounds [100 x i8], ptr %5, i64 0, i64 0
  %62 = call noalias ptr @fopen(ptr noundef %61, ptr noundef @.str.6)
  store ptr %62, ptr %10, align 8, !tbaa !9
  %63 = load ptr, ptr %10, align 8, !tbaa !9
  %64 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %63, ptr noundef @.str.16) #5
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 15, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 7, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  ret ptr %65
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind
declare i32 @stat(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @mkdir(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #2

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


; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@DEFAULT_LOGS_DIR = external dso_local local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [39 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @init_log_file(ptr nocapture noundef readonly byval(%struct.life) align 8 %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca [100 x i8], align 16
  %4 = alloca [7 x i8], align 1
  %5 = alloca [8 x i8], align 1
  %6 = alloca [15 x i8], align 1
  %7 = alloca %struct.stat, align 8
  %8 = load ptr, ptr @DEFAULT_LOGS_DIR, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 7, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 15, ptr nonnull %6) #5
  %9 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) @.str.13) #5
  %10 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) @.str.13) #5
  %11 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) @.str.13) #5
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %7) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(144) %7, i8 0, i64 144, i1 false)
  %12 = call i32 @stat(ptr noundef %8, ptr noundef nonnull %7) #5
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = tail call i32 @mkdir(ptr noundef %8, i32 noundef 484) #5
  br label %16

16:                                               ; preds = %14, %2
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %.not = icmp eq ptr %18, null
  %19 = load i32, ptr %0, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !15
  br i1 %.not, label %27, label %24

24:                                               ; preds = %16
  %25 = tail call i64 @time(ptr noundef null) #5
  %26 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.14, ptr noundef %8, ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef nonnull %6, i32 noundef %19, i32 noundef %21, i32 noundef %23, i64 noundef %25) #5
  br label %34

27:                                               ; preds = %16
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load double, ptr %28, align 8, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = load i32, ptr %30, align 8, !tbaa !17
  %32 = tail call i64 @time(ptr noundef null) #5
  %33 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.15, ptr noundef %8, ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef nonnull %6, i32 noundef %19, i32 noundef %21, i32 noundef %23, double noundef %29, i32 noundef %31, i64 noundef %32) #5
  br label %34

34:                                               ; preds = %27, %24
  %35 = call noalias ptr @fopen(ptr noundef nonnull %3, ptr noundef nonnull @.str.6)
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str.16) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 15, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %3) #5
  ret ptr %35
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i32 @stat(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @mkdir(ptr nocapture noundef readonly, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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, !6, i64 48}
!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 = !{!10, !11, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !12, i64 16}
!17 = !{!10, !11, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass