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

; 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 }
%struct.player_s = type { ptr, i32, %struct.ticcmd_t, i32, i32, i32, i32, i32, i32, i32, [6 x i32], [6 x i32], i32, [4 x i32], i32, i32, [9 x i32], [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, ptr, i32, i32, ptr, i32, i32, i32, [2 x %struct.pspdef_t], i32 }
%struct.ticcmd_t = type { i8, i8, i16, i16, i8, i8 }
%struct.pspdef_t = type { ptr, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [44 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [46 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

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

; 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 i32 @EV_DoLockedDoor(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.mobj_s, ptr %10, i32 0, i32 31
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.line_s, ptr %17, i32 0, i32 5
  %19 = load i16, ptr %18, align 2, !tbaa !16
  %20 = sext i16 %19 to i32
  switch i32 %20, label %81 [
    i32 99, label %21
    i32 133, label %21
    i32 134, label %41
    i32 135, label %41
    i32 136, label %61
    i32 137, label %61
  ]

21:                                               ; preds = %16, %16
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

25:                                               ; preds = %21
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.player_s, ptr %26, i32 0, i32 11
  %28 = getelementptr inbounds [6 x i32], ptr %27, i64 0, i64 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %40, label %31

31:                                               ; preds = %25
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.player_s, ptr %32, i32 0, i32 11
  %34 = getelementptr inbounds [6 x i32], ptr %33, i64 0, i64 3
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %40, label %37

37:                                               ; preds = %31
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.player_s, ptr %38, i32 0, i32 26
  store ptr @.str, ptr %39, align 8, !tbaa !18
  call void @S_StartSound(ptr noundef null, i32 noundef 34)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

40:                                               ; preds = %31, %25
  br label %81

41:                                               ; preds = %16, %16
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

45:                                               ; preds = %41
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.player_s, ptr %46, i32 0, i32 11
  %48 = getelementptr inbounds [6 x i32], ptr %47, i64 0, i64 2
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %60, label %51

51:                                               ; preds = %45
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.player_s, ptr %52, i32 0, i32 11
  %54 = getelementptr inbounds [6 x i32], ptr %53, i64 0, i64 5
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %60, label %57

57:                                               ; preds = %51
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.player_s, ptr %58, i32 0, i32 26
  store ptr @.str.1, ptr %59, align 8, !tbaa !18
  call void @S_StartSound(ptr noundef null, i32 noundef 34)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

60:                                               ; preds = %51, %45
  br label %81

61:                                               ; preds = %16, %16
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

65:                                               ; preds = %61
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.player_s, ptr %66, i32 0, i32 11
  %68 = getelementptr inbounds [6 x i32], ptr %67, i64 0, i64 1
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %80, label %71

71:                                               ; preds = %65
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.player_s, ptr %72, i32 0, i32 11
  %74 = getelementptr inbounds [6 x i32], ptr %73, i64 0, i64 4
  %75 = load i32, ptr %74, align 8, !tbaa !9
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %80, label %77

77:                                               ; preds = %71
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.player_s, ptr %78, i32 0, i32 26
  store ptr @.str.2, ptr %79, align 8, !tbaa !18
  call void @S_StartSound(ptr noundef null, i32 noundef 34)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

80:                                               ; preds = %71, %65
  br label %81

81:                                               ; preds = %80, %60, %40, %16
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = load i32, ptr %6, align 4, !tbaa !9
  %84 = call i32 @EV_DoDoor(ptr noundef %82, i32 noundef %83)
  store i32 %84, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

85:                                               ; preds = %81, %77, %64, %57, %44, %37, %24, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %86 = load i32, ptr %4, align 4
  ret i32 %86
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @EV_DoDoor(ptr noundef, i32 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 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 192}
!12 = !{!"mobj_s", !13, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !6, i64 176, !10, i64 184, !10, i64 188, !6, i64 192, !10, i64 200, !14, i64 204, !6, i64 216}
!13 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!14 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !15, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !15, i64 26}
!17 = !{!"line_s", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !15, i64 24, !15, i64 26, !15, i64 28, !7, i64 30, !7, i64 36, !10, i64 52, !6, i64 56, !6, i64 64, !10, i64 72, !6, i64 80}
!18 = !{!19, !6, i64 224}
!19 = !{!"player_s", !6, i64 0, !10, i64 8, !20, i64 12, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48, !7, i64 72, !10, i64 96, !7, i64 100, !10, i64 116, !10, i64 120, !7, i64 124, !7, i64 160, !7, i64 176, !10, i64 192, !10, i64 196, !10, i64 200, !10, i64 204, !10, i64 208, !10, i64 212, !10, i64 216, !6, i64 224, !10, i64 232, !10, i64 236, !6, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !7, i64 264, !10, i64 312}
!20 = !{!"", !7, i64 0, !7, i64 1, !15, i64 2, !15, i64 4, !7, i64 6, !7, i64 7}


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

@.str = external hidden unnamed_addr constant [44 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [46 x i8], align 1

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

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

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 26
  %8 = load i16, ptr %7, align 2, !tbaa !14
  switch i16 %8, label %33 [
    i16 99, label %9
    i16 133, label %9
    i16 134, label %17
    i16 135, label %17
    i16 136, label %25
    i16 137, label %25
  ]

9:                                                ; preds = %6, %6
  %10 = getelementptr inbounds i8, ptr %5, i64 72
  %11 = load i32, ptr %10, align 8, !tbaa !16
  %.not22 = icmp eq i32 %11, 0
  br i1 %.not22, label %12, label %33

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %5, i64 84
  %14 = load i32, ptr %13, align 4, !tbaa !16
  %.not23 = icmp eq i32 %14, 0
  br i1 %.not23, label %15, label %33

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %5, i64 224
  store ptr @.str, ptr %16, align 8, !tbaa !17
  tail call void @S_StartSound(ptr noundef null, i32 noundef 34) #2
  br label %35

17:                                               ; preds = %6, %6
  %18 = getelementptr inbounds i8, ptr %5, i64 80
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %.not20 = icmp eq i32 %19, 0
  br i1 %.not20, label %20, label %33

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %5, i64 92
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %.not21 = icmp eq i32 %22, 0
  br i1 %.not21, label %23, label %33

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %5, i64 224
  store ptr @.str.1, ptr %24, align 8, !tbaa !17
  tail call void @S_StartSound(ptr noundef null, i32 noundef 34) #2
  br label %35

25:                                               ; preds = %6, %6
  %26 = getelementptr inbounds i8, ptr %5, i64 76
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %.not18 = icmp eq i32 %27, 0
  br i1 %.not18, label %28, label %33

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %5, i64 88
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %.not19 = icmp eq i32 %30, 0
  br i1 %.not19, label %31, label %33

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %5, i64 224
  store ptr @.str.2, ptr %32, align 8, !tbaa !17
  tail call void @S_StartSound(ptr noundef null, i32 noundef 34) #2
  br label %35

33:                                               ; preds = %25, %28, %17, %20, %9, %12, %6
  %34 = tail call i32 @EV_DoDoor(ptr noundef nonnull %0, i32 noundef %1)
  br label %35

35:                                               ; preds = %3, %33, %31, %23, %15
  %.0 = phi i32 [ %34, %33 ], [ 0, %31 ], [ 0, %23 ], [ 0, %15 ], [ 0, %3 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @EV_DoDoor(ptr noundef, i32 noundef) local_unnamed_addr #1

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}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !8, i64 224}
!18 = !{!"player_s", !8, i64 0, !11, i64 8, !19, i64 12, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !9, i64 48, !9, i64 72, !11, i64 96, !9, i64 100, !11, i64 116, !11, i64 120, !9, i64 124, !9, i64 160, !9, i64 176, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !11, i64 208, !11, i64 212, !11, i64 216, !8, i64 224, !11, i64 232, !11, i64 236, !8, i64 240, !11, i64 248, !11, i64 252, !11, i64 256, !9, i64 264, !11, i64 312}
!19 = !{!"", !9, i64 0, !9, i64 1, !13, i64 2, !13, i64 4, !9, i64 6, !9, i64 7}


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