; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Doom/mc1-doom/src (g_game)

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

@consoleplayer = external dso_local global i32, align 4
@gamemap = external dso_local global i32, align 4
@playeringame = external dso_local global [4 x i32], align 16
@gameepisode = external dso_local global i32, align 4
@gameskill = external dso_local global i32, align 4
@deathmatch = external dso_local global i32, align 4
@respawnparm = external global i32, align 4
@fastparm = external global i32, align 4
@nomonsters = external global i32, align 4
@demo_p = external dso_local global ptr, align 8
@demobuffer = external dso_local global ptr, align 8

; 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 @G_BeginRecording() #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %2 = load ptr, ptr @demobuffer, align 8, !tbaa !5
  store ptr %2, ptr @demo_p, align 8, !tbaa !5
  %3 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i32 1
  store ptr %4, ptr @demo_p, align 8, !tbaa !5
  store i8 110, ptr %3, align 1, !tbaa !9
  %5 = load i32, ptr @gameskill, align 4, !tbaa !10
  %6 = trunc i32 %5 to i8
  %7 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i32 1
  store ptr %8, ptr @demo_p, align 8, !tbaa !5
  store i8 %6, ptr %7, align 1, !tbaa !9
  %9 = load i32, ptr @gameepisode, align 4, !tbaa !10
  %10 = trunc i32 %9 to i8
  %11 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i32 1
  store ptr %12, ptr @demo_p, align 8, !tbaa !5
  store i8 %10, ptr %11, align 1, !tbaa !9
  %13 = load i32, ptr @gamemap, align 4, !tbaa !10
  %14 = trunc i32 %13 to i8
  %15 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i32 1
  store ptr %16, ptr @demo_p, align 8, !tbaa !5
  store i8 %14, ptr %15, align 1, !tbaa !9
  %17 = load i32, ptr @deathmatch, align 4, !tbaa !10
  %18 = trunc i32 %17 to i8
  %19 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr @demo_p, align 8, !tbaa !5
  store i8 %18, ptr %19, align 1, !tbaa !9
  %21 = load i32, ptr @respawnparm, align 4, !tbaa !10
  %22 = trunc i32 %21 to i8
  %23 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i32 1
  store ptr %24, ptr @demo_p, align 8, !tbaa !5
  store i8 %22, ptr %23, align 1, !tbaa !9
  %25 = load i32, ptr @fastparm, align 4, !tbaa !10
  %26 = trunc i32 %25 to i8
  %27 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr @demo_p, align 8, !tbaa !5
  store i8 %26, ptr %27, align 1, !tbaa !9
  %29 = load i32, ptr @nomonsters, align 4, !tbaa !10
  %30 = trunc i32 %29 to i8
  %31 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr @demo_p, align 8, !tbaa !5
  store i8 %30, ptr %31, align 1, !tbaa !9
  %33 = load i32, ptr @consoleplayer, align 4, !tbaa !10
  %34 = trunc i32 %33 to i8
  %35 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr @demo_p, align 8, !tbaa !5
  store i8 %34, ptr %35, align 1, !tbaa !9
  store i32 0, ptr %1, align 4, !tbaa !10
  br label %37

37:                                               ; preds = %48, %0
  %38 = load i32, ptr %1, align 4, !tbaa !10
  %39 = icmp slt i32 %38, 4
  br i1 %39, label %40, label %51

40:                                               ; preds = %37
  %41 = load i32, ptr %1, align 4, !tbaa !10
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4 x i32], ptr @playeringame, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !10
  %45 = trunc i32 %44 to i8
  %46 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr @demo_p, align 8, !tbaa !5
  store i8 %45, ptr %46, align 1, !tbaa !9
  br label %48

48:                                               ; preds = %40
  %49 = load i32, ptr %1, align 4, !tbaa !10
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %1, align 4, !tbaa !10
  br label %37, !llvm.loop !12

51:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@consoleplayer = external dso_local local_unnamed_addr global i32, align 4
@gamemap = external dso_local local_unnamed_addr global i32, align 4
@playeringame = external dso_local local_unnamed_addr global [4 x i32], align 16
@gameepisode = external dso_local local_unnamed_addr global i32, align 4
@gameskill = external dso_local local_unnamed_addr global i32, align 4
@deathmatch = external dso_local local_unnamed_addr global i32, align 4
@respawnparm = external local_unnamed_addr global i32, align 4
@fastparm = external local_unnamed_addr global i32, align 4
@nomonsters = external local_unnamed_addr global i32, align 4
@demo_p = external dso_local local_unnamed_addr global ptr, align 8
@demobuffer = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @G_BeginRecording() local_unnamed_addr #0 {
  %1 = load ptr, ptr @demobuffer, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 1
  store ptr %2, ptr @demo_p, align 8, !tbaa !5
  store i8 110, ptr %1, align 1, !tbaa !9
  %3 = load i32, ptr @gameskill, align 4, !tbaa !10
  %4 = trunc i32 %3 to i8
  %5 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 1
  store ptr %6, ptr @demo_p, align 8, !tbaa !5
  store i8 %4, ptr %5, align 1, !tbaa !9
  %7 = load i32, ptr @gameepisode, align 4, !tbaa !10
  %8 = trunc i32 %7 to i8
  %9 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 1
  store ptr %10, ptr @demo_p, align 8, !tbaa !5
  store i8 %8, ptr %9, align 1, !tbaa !9
  %11 = load i32, ptr @gamemap, align 4, !tbaa !10
  %12 = trunc i32 %11 to i8
  %13 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 1
  store ptr %14, ptr @demo_p, align 8, !tbaa !5
  store i8 %12, ptr %13, align 1, !tbaa !9
  %15 = load i32, ptr @deathmatch, align 4, !tbaa !10
  %16 = trunc i32 %15 to i8
  %17 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 1
  store ptr %18, ptr @demo_p, align 8, !tbaa !5
  store i8 %16, ptr %17, align 1, !tbaa !9
  %19 = load i32, ptr @respawnparm, align 4, !tbaa !10
  %20 = trunc i32 %19 to i8
  %21 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 1
  store ptr %22, ptr @demo_p, align 8, !tbaa !5
  store i8 %20, ptr %21, align 1, !tbaa !9
  %23 = load i32, ptr @fastparm, align 4, !tbaa !10
  %24 = trunc i32 %23 to i8
  %25 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 1
  store ptr %26, ptr @demo_p, align 8, !tbaa !5
  store i8 %24, ptr %25, align 1, !tbaa !9
  %27 = load i32, ptr @nomonsters, align 4, !tbaa !10
  %28 = trunc i32 %27 to i8
  %29 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 1
  store ptr %30, ptr @demo_p, align 8, !tbaa !5
  store i8 %28, ptr %29, align 1, !tbaa !9
  %31 = load i32, ptr @consoleplayer, align 4, !tbaa !10
  %32 = trunc i32 %31 to i8
  %33 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  store ptr %34, ptr @demo_p, align 8, !tbaa !5
  store i8 %32, ptr %33, align 1, !tbaa !9
  %35 = load i32, ptr @playeringame, align 16, !tbaa !10
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 1
  store ptr %38, ptr @demo_p, align 8, !tbaa !5
  store i8 %36, ptr %37, align 1, !tbaa !9
  %39 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 4), align 4, !tbaa !10
  %40 = trunc i32 %39 to i8
  %41 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 1
  store ptr %42, ptr @demo_p, align 8, !tbaa !5
  store i8 %40, ptr %41, align 1, !tbaa !9
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 8), align 8, !tbaa !10
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 1
  store ptr %46, ptr @demo_p, align 8, !tbaa !5
  store i8 %44, ptr %45, align 1, !tbaa !9
  %47 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 12), align 4, !tbaa !10
  %48 = trunc i32 %47 to i8
  %49 = load ptr, ptr @demo_p, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 1
  store ptr %50, ptr @demo_p, align 8, !tbaa !5
  store i8 %48, ptr %49, align 1, !tbaa !9
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) 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" }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass