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

@precache = external dso_local global i32, align 4
@consoleplayer = external dso_local global i32, align 4
@playeringame = external dso_local global [4 x i32], align 16
@gameaction = external dso_local global i32, align 4
@deathmatch = external dso_local global i32, align 4
@demoplayback = external dso_local global i32, align 4
@netgame = external dso_local global i32, align 4
@netdemo = 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
@usergame = external dso_local global i32, align 4
@demo_p = external dso_local global ptr, align 8
@demobuffer = external dso_local global ptr, align 8
@defdemoname = external dso_local global ptr, align 8
@stderr = external global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [40 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

; Function Attrs: nounwind uwtable
define dso_local void @G_DoPlayDemo() #1 {
  %1 = alloca i32, align 4
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  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
  store i32 0, ptr @gameaction, align 4, !tbaa !5
  %7 = load ptr, ptr @defdemoname, align 8, !tbaa !9
  %8 = call ptr @W_CacheLumpName(ptr noundef %7, i32 noundef 1)
  store ptr %8, ptr @demo_p, align 8, !tbaa !9
  store ptr %8, ptr @demobuffer, align 8, !tbaa !9
  %9 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i32 1
  store ptr %10, ptr @demo_p, align 8, !tbaa !9
  %11 = load i8, ptr %9, align 1, !tbaa !11
  %12 = zext i8 %11 to i32
  store i32 %12, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 110
  br i1 %14, label %15, label %21

15:                                               ; preds = %0
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 109
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.19) #4
  store i32 0, ptr @gameaction, align 4, !tbaa !5
  store i32 1, ptr %6, align 4
  br label %76

21:                                               ; preds = %15, %0
  %22 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr @demo_p, align 8, !tbaa !9
  %24 = load i8, ptr %22, align 1, !tbaa !11
  %25 = zext i8 %24 to i32
  store i32 %25, ptr %1, align 4, !tbaa !5
  %26 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr @demo_p, align 8, !tbaa !9
  %28 = load i8, ptr %26, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  store i32 %29, ptr %3, align 4, !tbaa !5
  %30 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %30, i32 1
  store ptr %31, ptr @demo_p, align 8, !tbaa !9
  %32 = load i8, ptr %30, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  store i32 %33, ptr %4, align 4, !tbaa !5
  %34 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %34, i32 1
  store ptr %35, ptr @demo_p, align 8, !tbaa !9
  %36 = load i8, ptr %34, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  store i32 %37, ptr @deathmatch, align 4, !tbaa !5
  %38 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr @demo_p, align 8, !tbaa !9
  %40 = load i8, ptr %38, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  store i32 %41, ptr @respawnparm, align 4, !tbaa !5
  %42 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr @demo_p, align 8, !tbaa !9
  %44 = load i8, ptr %42, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  store i32 %45, ptr @fastparm, align 4, !tbaa !5
  %46 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr @demo_p, align 8, !tbaa !9
  %48 = load i8, ptr %46, align 1, !tbaa !11
  %49 = zext i8 %48 to i32
  store i32 %49, ptr @nomonsters, align 4, !tbaa !5
  %50 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr @demo_p, align 8, !tbaa !9
  %52 = load i8, ptr %50, align 1, !tbaa !11
  %53 = zext i8 %52 to i32
  store i32 %53, ptr @consoleplayer, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %65, %21
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = icmp slt i32 %55, 4
  br i1 %56, label %57, label %68

57:                                               ; preds = %54
  %58 = load ptr, ptr @demo_p, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr @demo_p, align 8, !tbaa !9
  %60 = load i8, ptr %58, align 1, !tbaa !11
  %61 = zext i8 %60 to i32
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [4 x i32], ptr @playeringame, i64 0, i64 %63
  store i32 %61, ptr %64, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %57
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %2, align 4, !tbaa !5
  br label %54, !llvm.loop !12

68:                                               ; preds = %54
  %69 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @playeringame, i64 0, i64 1), align 4, !tbaa !5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  store i32 1, ptr @netgame, align 4, !tbaa !5
  store i32 1, ptr @netdemo, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %71, %68
  store i32 0, ptr @precache, align 4, !tbaa !5
  %73 = load i32, ptr %1, align 4, !tbaa !5
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  call void @G_InitNew(i32 noundef %73, i32 noundef %74, i32 noundef %75)
  store i32 1, ptr @precache, align 4, !tbaa !5
  store i32 0, ptr @usergame, align 4, !tbaa !5
  store i32 1, ptr @demoplayback, align 4, !tbaa !5
  store i32 0, ptr %6, align 4
  br label %76

76:                                               ; preds = %72, %18
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  %77 = load i32, ptr %6, align 4
  switch i32 %77, label %79 [
    i32 0, label %78
    i32 1, label %78
  ]

78:                                               ; preds = %76, %76
  ret void

79:                                               ; preds = %76
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local void @G_InitNew(i32 noundef, i32 noundef, i32 noundef) #1

declare ptr @W_CacheLumpName(ptr noundef, i32 noundef) #2

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

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 "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 = !{!"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 = !{!7, !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"

@precache = external dso_local local_unnamed_addr global i32, align 4
@consoleplayer = external dso_local local_unnamed_addr global i32, align 4
@playeringame = external dso_local local_unnamed_addr global [4 x i32], align 16
@gameaction = external dso_local local_unnamed_addr global i32, align 4
@deathmatch = external dso_local local_unnamed_addr global i32, align 4
@demoplayback = external dso_local local_unnamed_addr global i32, align 4
@netgame = external dso_local local_unnamed_addr global i32, align 4
@netdemo = 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
@usergame = external dso_local 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
@defdemoname = external dso_local local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @G_DoPlayDemo() local_unnamed_addr #0 {
  store i32 0, ptr @gameaction, align 4, !tbaa !5
  %1 = load ptr, ptr @defdemoname, align 8, !tbaa !9
  %2 = tail call ptr @W_CacheLumpName(ptr noundef %1, i32 noundef 1) #3
  store ptr %2, ptr @demobuffer, align 8, !tbaa !9
  %3 = getelementptr inbounds i8, ptr %2, i64 1
  store ptr %3, ptr @demo_p, align 8, !tbaa !9
  %4 = load i8, ptr %2, align 1, !tbaa !11
  %5 = add i8 %4, -109
  %or.cond = icmp ult i8 %5, 2
  br i1 %or.cond, label %9, label %6

6:                                                ; preds = %0
  %7 = load ptr, ptr @stderr, align 8, !tbaa !9
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.19) #4
  store i32 0, ptr @gameaction, align 4, !tbaa !5
  br label %40

9:                                                ; preds = %0
  %10 = getelementptr inbounds i8, ptr %2, i64 2
  store ptr %10, ptr @demo_p, align 8, !tbaa !9
  %11 = load i8, ptr %3, align 1, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %2, i64 3
  store ptr %12, ptr @demo_p, align 8, !tbaa !9
  %13 = load i8, ptr %10, align 1, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %2, i64 4
  store ptr %14, ptr @demo_p, align 8, !tbaa !9
  %15 = load i8, ptr %12, align 1, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %2, i64 5
  store ptr %16, ptr @demo_p, align 8, !tbaa !9
  %17 = load i8, ptr %14, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  store i32 %18, ptr @deathmatch, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %2, i64 6
  store ptr %19, ptr @demo_p, align 8, !tbaa !9
  %20 = load i8, ptr %16, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  store i32 %21, ptr @respawnparm, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %2, i64 7
  store ptr %22, ptr @demo_p, align 8, !tbaa !9
  %23 = load i8, ptr %19, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  store i32 %24, ptr @fastparm, align 4, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %25, ptr @demo_p, align 8, !tbaa !9
  %26 = load i8, ptr %22, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  store i32 %27, ptr @nomonsters, align 4, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %2, i64 9
  %29 = load i8, ptr %25, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  store i32 %30, ptr @consoleplayer, align 4, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %2, i64 13
  store ptr %31, ptr @demo_p, align 8, !tbaa !9
  %32 = load <4 x i8>, ptr %28, align 1, !tbaa !11
  %33 = zext <4 x i8> %32 to <4 x i32>
  store <4 x i32> %33, ptr @playeringame, align 16, !tbaa !5
  %34 = zext i8 %11 to i32
  %35 = zext i8 %13 to i32
  %36 = zext i8 %15 to i32
  %37 = extractelement <4 x i8> %32, i64 1
  %.not = icmp eq i8 %37, 0
  br i1 %.not, label %39, label %38

38:                                               ; preds = %9
  store i32 1, ptr @netgame, align 4, !tbaa !5
  store i32 1, ptr @netdemo, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %38, %9
  store i32 0, ptr @precache, align 4, !tbaa !5
  tail call void @G_InitNew(i32 noundef %34, i32 noundef %35, i32 noundef %36)
  store i32 1, ptr @precache, align 4, !tbaa !5
  store i32 0, ptr @usergame, align 4, !tbaa !5
  store i32 1, ptr @demoplayback, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %39, %6
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @G_InitNew(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @W_CacheLumpName(ptr noundef, i32 noundef) local_unnamed_addr #1

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

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 = { 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 }
attributes #4 = { cold 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 = !{!7, !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass