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

; 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.floormove_t = type { %struct.thinker_s, i32, i32, ptr, i32, i32, i16, i32, i32 }
%struct.thinker_s = type { ptr, ptr, %union.actionf_t }
%union.actionf_t = type { ptr }
%struct.sector_t = type { i32, i32, i16, i16, i16, i16, i16, i32, ptr, [4 x i32], %struct.degenmobj_t, i32, ptr, ptr, i32, ptr }
%struct.degenmobj_t = type { %struct.thinker_s, i32, i32, i32 }

@leveltime = external global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @T_MovePlane(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @T_MoveFloor(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.floormove_t, ptr %4, i32 0, i32 3
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.floormove_t, ptr %7, i32 0, i32 8
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.floormove_t, ptr %10, i32 0, i32 7
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.floormove_t, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !16
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.floormove_t, ptr %16, i32 0, i32 4
  %18 = load i32, ptr %17, align 8, !tbaa !17
  %19 = call i32 @T_MovePlane(ptr noundef %6, i32 noundef %9, i32 noundef %12, i32 noundef %15, i32 noundef 0, i32 noundef %18)
  store i32 %19, ptr %3, align 4, !tbaa !18
  %20 = load i32, ptr @leveltime, align 4, !tbaa !18
  %21 = and i32 %20, 7
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %28, label %23

23:                                               ; preds = %1
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.floormove_t, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.sector_t, ptr %26, i32 0, i32 10
  call void @S_StartSound(ptr noundef %27, i32 noundef 22)
  br label %28

28:                                               ; preds = %23, %1
  %29 = load i32, ptr %3, align 4, !tbaa !18
  %30 = icmp eq i32 %29, 2
  br i1 %30, label %31, label %97

31:                                               ; preds = %28
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.floormove_t, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.sector_t, ptr %34, i32 0, i32 13
  store ptr null, ptr %35, align 8, !tbaa !19
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.floormove_t, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %37, align 8, !tbaa !17
  %39 = icmp eq i32 %38, 1
  br i1 %39, label %40, label %62

40:                                               ; preds = %31
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.floormove_t, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !22
  switch i32 %43, label %60 [
    i32 11, label %44
  ]

44:                                               ; preds = %40
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.floormove_t, ptr %45, i32 0, i32 5
  %47 = load i32, ptr %46, align 4, !tbaa !23
  %48 = trunc i32 %47 to i16
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.floormove_t, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.sector_t, ptr %51, i32 0, i32 5
  store i16 %48, ptr %52, align 2, !tbaa !24
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.floormove_t, ptr %53, i32 0, i32 6
  %55 = load i16, ptr %54, align 8, !tbaa !25
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.floormove_t, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.sector_t, ptr %58, i32 0, i32 2
  store i16 %55, ptr %59, align 8, !tbaa !26
  br label %60

60:                                               ; preds = %44, %40
  br label %61

61:                                               ; preds = %60
  br label %90

62:                                               ; preds = %31
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.floormove_t, ptr %63, i32 0, i32 4
  %65 = load i32, ptr %64, align 8, !tbaa !17
  %66 = icmp eq i32 %65, -1
  br i1 %66, label %67, label %89

67:                                               ; preds = %62
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.floormove_t, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 8, !tbaa !22
  switch i32 %70, label %87 [
    i32 6, label %71
  ]

71:                                               ; preds = %67
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.floormove_t, ptr %72, i32 0, i32 5
  %74 = load i32, ptr %73, align 4, !tbaa !23
  %75 = trunc i32 %74 to i16
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.floormove_t, ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.sector_t, ptr %78, i32 0, i32 5
  store i16 %75, ptr %79, align 2, !tbaa !24
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.floormove_t, ptr %80, i32 0, i32 6
  %82 = load i16, ptr %81, align 8, !tbaa !25
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.floormove_t, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.sector_t, ptr %85, i32 0, i32 2
  store i16 %82, ptr %86, align 8, !tbaa !26
  br label %87

87:                                               ; preds = %71, %67
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88, %62
  br label %90

90:                                               ; preds = %89, %61
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.floormove_t, ptr %91, i32 0, i32 0
  call void @P_RemoveThinker(ptr noundef %92)
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.floormove_t, ptr %93, i32 0, i32 3
  %95 = load ptr, ptr %94, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.sector_t, ptr %95, i32 0, i32 10
  call void @S_StartSound(ptr noundef %96, i32 noundef 19)
  br label %97

97:                                               ; preds = %90, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

declare void @P_RemoveThinker(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 32}
!10 = !{!"", !11, i64 0, !12, i64 24, !12, i64 28, !6, i64 32, !12, i64 40, !12, i64 44, !13, i64 48, !12, i64 52, !12, i64 56}
!11 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !12, i64 56}
!15 = !{!10, !12, i64 52}
!16 = !{!10, !12, i64 28}
!17 = !{!10, !12, i64 40}
!18 = !{!12, !12, i64 0}
!19 = !{!20, !6, i64 104}
!20 = !{!"", !12, i64 0, !12, i64 4, !13, i64 8, !13, i64 10, !13, i64 12, !13, i64 14, !13, i64 16, !12, i64 20, !6, i64 24, !7, i64 32, !21, i64 48, !12, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !6, i64 120}
!21 = !{!"", !11, i64 0, !12, i64 24, !12, i64 28, !12, i64 32}
!22 = !{!10, !12, i64 24}
!23 = !{!10, !12, i64 44}
!24 = !{!20, !13, i64 14}
!25 = !{!10, !13, i64 48}
!26 = !{!20, !13, i64 8}


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

@leveltime = external local_unnamed_addr global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local void @T_MoveFloor(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load i32, ptr %4, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %0, i64 52
  %7 = load i32, ptr %6, align 4, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 28
  %9 = load i32, ptr %8, align 4, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load i32, ptr %10, align 8, !tbaa !16
  %12 = tail call i32 @T_MovePlane(ptr noundef %3, i32 noundef %5, i32 noundef %7, i32 noundef %9, i32 noundef 0, i32 noundef %11)
  %13 = load i32, ptr @leveltime, align 4, !tbaa !17
  %14 = and i32 %13, 7
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %18

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 48
  tail call void @S_StartSound(ptr noundef nonnull %17, i32 noundef 22) #2
  br label %18

18:                                               ; preds = %15, %1
  %19 = icmp eq i32 %12, 2
  br i1 %19, label %20, label %40

20:                                               ; preds = %18
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 104
  store ptr null, ptr %22, align 8, !tbaa !18
  %23 = load i32, ptr %10, align 8, !tbaa !16
  switch i32 %23, label %37 [
    i32 1, label %24
    i32 -1, label %27
  ]

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  %26 = load i32, ptr %25, align 8, !tbaa !21
  %cond1 = icmp eq i32 %26, 11
  br i1 %cond1, label %.sink.split, label %37

27:                                               ; preds = %20
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load i32, ptr %28, align 8, !tbaa !21
  %cond = icmp eq i32 %29, 6
  br i1 %cond, label %.sink.split, label %37

.sink.split:                                      ; preds = %27, %24
  %30 = getelementptr inbounds i8, ptr %0, i64 44
  %31 = load i32, ptr %30, align 4, !tbaa !22
  %32 = trunc i32 %31 to i16
  %33 = getelementptr inbounds i8, ptr %21, i64 14
  store i16 %32, ptr %33, align 2, !tbaa !23
  %34 = getelementptr inbounds i8, ptr %0, i64 48
  %35 = load i16, ptr %34, align 8, !tbaa !24
  %36 = getelementptr inbounds i8, ptr %21, i64 8
  store i16 %35, ptr %36, align 8, !tbaa !25
  br label %37

37:                                               ; preds = %.sink.split, %20, %27, %24
  tail call void @P_RemoveThinker(ptr noundef nonnull %0) #2
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 48
  tail call void @S_StartSound(ptr noundef nonnull %39, i32 noundef 19) #2
  br label %40

40:                                               ; preds = %37, %18
  ret void
}

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

declare void @P_RemoveThinker(ptr noundef) local_unnamed_addr #1

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 = { 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 32}
!6 = !{!"", !7, i64 0, !11, i64 24, !11, i64 28, !8, i64 32, !11, i64 40, !11, i64 44, !12, i64 48, !11, i64 52, !11, i64 56}
!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 = !{!"short", !9, i64 0}
!13 = !{!6, !11, i64 56}
!14 = !{!6, !11, i64 52}
!15 = !{!6, !11, i64 28}
!16 = !{!6, !11, i64 40}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !8, i64 104}
!19 = !{!"", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 10, !12, i64 12, !12, i64 14, !12, i64 16, !11, i64 20, !8, i64 24, !9, i64 32, !20, i64 48, !11, i64 88, !8, i64 96, !8, i64 104, !11, i64 112, !8, i64 120}
!20 = !{!"", !7, i64 0, !11, i64 24, !11, i64 28, !11, i64 32}
!21 = !{!6, !11, i64 24}
!22 = !{!6, !11, i64 44}
!23 = !{!19, !12, i64 14}
!24 = !{!6, !12, i64 48}
!25 = !{!19, !12, i64 8}


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