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

; 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.mobj_s = type { %struct.thinker_s, i32, i32, i32, ptr, ptr, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr, i32, i32, i32, i32, ptr, i32, i32, ptr, i32, %struct.mapthing_t, ptr }
%struct.thinker_s = type { ptr, ptr, %union.actionf_t }
%union.actionf_t = type { ptr }
%struct.mapthing_t = type { i16, i16, i16, i16, i16 }
%struct.line_s = type { ptr, ptr, i32, i32, i16, i16, i16, [2 x i16], [4 x i32], i32, ptr, ptr, i32, ptr }

; 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 i32 @EV_DoDoor(ptr noundef, i32 noundef) #1

declare i32 @EV_DoFloor(ptr noundef, i32 noundef) #1

declare i32 @EV_DoPlat(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @P_ShootSpecialLine(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.mobj_s, ptr %7, i32 0, i32 31
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %22, label %11

11:                                               ; preds = %2
  store i32 0, ptr %5, align 4, !tbaa !15
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.line_s, ptr %12, i32 0, i32 5
  %14 = load i16, ptr %13, align 2, !tbaa !16
  %15 = sext i16 %14 to i32
  switch i32 %15, label %17 [
    i32 46, label %16
  ]

16:                                               ; preds = %11
  store i32 1, ptr %5, align 4, !tbaa !15
  br label %17

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

20:                                               ; preds = %17
  store i32 1, ptr %6, align 4
  br label %40

21:                                               ; preds = %17
  br label %22

22:                                               ; preds = %21, %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.line_s, ptr %23, i32 0, i32 5
  %25 = load i16, ptr %24, align 2, !tbaa !16
  %26 = sext i16 %25 to i32
  switch i32 %26, label %39 [
    i32 24, label %27
    i32 46, label %31
    i32 47, label %35
  ]

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call i32 @EV_DoFloor(ptr noundef %28, i32 noundef 3)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  call void @P_ChangeSwitchTexture(ptr noundef %30, i32 noundef 0)
  br label %39

31:                                               ; preds = %22
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call i32 @EV_DoDoor(ptr noundef %32, i32 noundef 3)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @P_ChangeSwitchTexture(ptr noundef %34, i32 noundef 1)
  br label %39

35:                                               ; preds = %22
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = call i32 @EV_DoPlat(ptr noundef %36, i32 noundef 3, i32 noundef 0)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @P_ChangeSwitchTexture(ptr noundef %38, i32 noundef 0)
  br label %39

39:                                               ; preds = %35, %31, %27, %22
  store i32 0, ptr %6, align 4
  br label %40

40:                                               ; preds = %39, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %41 = load i32, ptr %6, align 4
  switch i32 %41, label %43 [
    i32 0, label %42
    i32 1, label %42
  ]

42:                                               ; preds = %40, %40
  ret void

43:                                               ; preds = %40
  unreachable
}

declare void @P_ChangeSwitchTexture(ptr noundef, i32 noundef) #1

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 192}
!10 = !{!"mobj_s", !11, i64 0, !12, i64 24, !12, i64 28, !12, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !6, i64 136, !12, i64 144, !6, i64 152, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172, !6, i64 176, !12, i64 184, !12, i64 188, !6, i64 192, !12, i64 200, !13, i64 204, !6, i64 216}
!11 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !14, i64 26}
!17 = !{!"line_s", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !14, i64 24, !14, i64 26, !14, i64 28, !7, i64 30, !7, i64 36, !12, i64 52, !6, i64 56, !6, i64 64, !12, i64 72, !6, i64 80}


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

declare i32 @EV_DoDoor(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @EV_DoFloor(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @EV_DoPlat(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @P_ShootSpecialLine(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 192
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  %5 = getelementptr inbounds i8, ptr %1, i64 26
  %6 = load i16, ptr %5, align 2, !tbaa !14
  br i1 %.not, label %7, label %8

7:                                                ; preds = %2
  %cond = icmp eq i16 %6, 46
  br i1 %cond, label %.thread, label %14

8:                                                ; preds = %2
  switch i16 %6, label %14 [
    i16 24, label %9
    i16 46, label %.thread
    i16 47, label %12
  ]

9:                                                ; preds = %8
  %10 = tail call i32 @EV_DoFloor(ptr noundef nonnull %1, i32 noundef 3) #2
  br label %.sink.split

.thread:                                          ; preds = %7, %8
  %11 = tail call i32 @EV_DoDoor(ptr noundef nonnull %1, i32 noundef 3) #2
  br label %.sink.split

12:                                               ; preds = %8
  %13 = tail call i32 @EV_DoPlat(ptr noundef nonnull %1, i32 noundef 3, i32 noundef 0) #2
  br label %.sink.split

.sink.split:                                      ; preds = %12, %.thread, %9
  %.sink = phi i32 [ 0, %9 ], [ 1, %.thread ], [ 0, %12 ]
  tail call void @P_ChangeSwitchTexture(ptr noundef nonnull %1, i32 noundef %.sink) #2
  br label %14

14:                                               ; preds = %.sink.split, %8, %7
  ret void
}

declare void @P_ChangeSwitchTexture(ptr noundef, i32 noundef) local_unnamed_addr #0

attributes #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 = { 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, !8, i64 192}
!6 = !{!"mobj_s", !7, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !8, i64 40, !8, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !8, i64 136, !11, i64 144, !8, i64 152, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !8, i64 176, !11, i64 184, !11, i64 188, !8, i64 192, !11, i64 200, !12, i64 204, !8, i64 216}
!7 = !{!"thinker_s", !8, i64 0, !8, i64 8, !9, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8}
!13 = !{!"short", !9, i64 0}
!14 = !{!15, !13, i64 26}
!15 = !{!"line_s", !8, i64 0, !8, i64 8, !11, i64 16, !11, i64 20, !13, i64 24, !13, i64 26, !13, i64 28, !9, i64 30, !9, i64 36, !11, i64 52, !8, i64 56, !8, i64 64, !11, i64 72, !8, i64 80}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass