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

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

@nofit = external dso_local global i32, align 4
@crushchange = external dso_local global i32, align 4
@leveltime = external global i32, align 4

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

declare void @P_DamageMobj(ptr noundef, ptr noundef, 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

declare i32 @P_Random() #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @P_ThingHeightClip(ptr noundef) #2

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

9:                                                ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mobj_s, ptr %11, i32 0, i32 25
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = icmp sle i32 %13, 0
  br i1 %14, label %15, label %26

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i32 @P_SetMobjState(ptr noundef %16, i32 noundef 895)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.mobj_s, ptr %18, i32 0, i32 24
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = and i32 %20, -3
  store i32 %21, ptr %19, align 8, !tbaa !15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mobj_s, ptr %22, i32 0, i32 15
  store i32 0, ptr %23, align 4, !tbaa !16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mobj_s, ptr %24, i32 0, i32 14
  store i32 0, ptr %25, align 8, !tbaa !17
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

26:                                               ; preds = %10
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mobj_s, ptr %27, i32 0, i32 24
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = and i32 %29, 131072
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %26
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void @P_RemoveMobj(ptr noundef %33)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

34:                                               ; preds = %26
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mobj_s, ptr %35, i32 0, i32 24
  %37 = load i32, ptr %36, align 8, !tbaa !15
  %38 = and i32 %37, 4
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

41:                                               ; preds = %34
  store i32 1, ptr @nofit, align 4, !tbaa !18
  %42 = load i32, ptr @crushchange, align 4, !tbaa !18
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %77

44:                                               ; preds = %41
  %45 = load i32, ptr @leveltime, align 4, !tbaa !18
  %46 = and i32 %45, 3
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %77, label %48

48:                                               ; preds = %44
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  call void @P_DamageMobj(ptr noundef %49, ptr noundef null, ptr noundef null, i32 noundef 10)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mobj_s, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 8, !tbaa !19
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mobj_s, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 4, !tbaa !20
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mobj_s, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 8, !tbaa !21
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.mobj_s, ptr %59, i32 0, i32 15
  %61 = load i32, ptr %60, align 4, !tbaa !16
  %62 = sdiv i32 %61, 2
  %63 = add nsw i32 %58, %62
  %64 = call ptr @P_SpawnMobj(i32 noundef %52, i32 noundef %55, i32 noundef %63, i32 noundef 38)
  store ptr %64, ptr %4, align 8, !tbaa !5
  %65 = call i32 @P_Random()
  %66 = call i32 @P_Random()
  %67 = sub nsw i32 %65, %66
  %68 = shl i32 %67, 12
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mobj_s, ptr %69, i32 0, i32 16
  store i32 %68, ptr %70, align 8, !tbaa !22
  %71 = call i32 @P_Random()
  %72 = call i32 @P_Random()
  %73 = sub nsw i32 %71, %72
  %74 = shl i32 %73, 12
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.mobj_s, ptr %75, i32 0, i32 17
  store i32 %74, ptr %76, align 4, !tbaa !23
  br label %77

77:                                               ; preds = %48, %44, %41
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

78:                                               ; preds = %77, %40, %32, %15, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %79 = load i32, ptr %2, align 4
  ret i32 %79
}

declare void @P_RemoveMobj(ptr noundef) #1

declare ptr @P_SpawnMobj(i32 noundef, i32 noundef, i32 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, !12, i64 164}
!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 = !{!10, !12, i64 160}
!16 = !{!10, !12, i64 108}
!17 = !{!10, !12, i64 104}
!18 = !{!12, !12, i64 0}
!19 = !{!10, !12, i64 24}
!20 = !{!10, !12, i64 28}
!21 = !{!10, !12, i64 32}
!22 = !{!10, !12, i64 112}
!23 = !{!10, !12, i64 116}


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

@nofit = external dso_local local_unnamed_addr global i32, align 4
@crushchange = external dso_local local_unnamed_addr global i32, align 4
@leveltime = external local_unnamed_addr global i32, align 4

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

declare i32 @P_Random() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @PIT_ChangeSector(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @P_ThingHeightClip(ptr noundef %0)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %48

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 164
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 1
  br i1 %6, label %7, label %14

7:                                                ; preds = %3
  %8 = tail call i32 @P_SetMobjState(ptr noundef nonnull %0, i32 noundef 895) #2
  %9 = getelementptr inbounds i8, ptr %0, i64 160
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = and i32 %10, -3
  store i32 %11, ptr %9, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 108
  store i32 0, ptr %12, align 4, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 104
  store i32 0, ptr %13, align 8, !tbaa !16
  br label %48

14:                                               ; preds = %3
  %15 = getelementptr inbounds i8, ptr %0, i64 160
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = and i32 %16, 131072
  %.not16 = icmp eq i32 %17, 0
  br i1 %.not16, label %19, label %18

18:                                               ; preds = %14
  tail call void @P_RemoveMobj(ptr noundef nonnull %0) #2
  br label %48

19:                                               ; preds = %14
  %20 = and i32 %16, 4
  %.not17 = icmp eq i32 %20, 0
  br i1 %.not17, label %48, label %21

21:                                               ; preds = %19
  store i32 1, ptr @nofit, align 4, !tbaa !17
  %22 = load i32, ptr @crushchange, align 4, !tbaa !17
  %.not18 = icmp eq i32 %22, 0
  br i1 %.not18, label %48, label %23

23:                                               ; preds = %21
  %24 = load i32, ptr @leveltime, align 4, !tbaa !17
  %25 = and i32 %24, 3
  %.not19 = icmp eq i32 %25, 0
  br i1 %.not19, label %26, label %48

26:                                               ; preds = %23
  tail call void @P_DamageMobj(ptr noundef nonnull %0, ptr noundef null, ptr noundef null, i32 noundef 10) #2
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load i32, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %0, i64 28
  %30 = load i32, ptr %29, align 4, !tbaa !19
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  %32 = load i32, ptr %31, align 8, !tbaa !20
  %33 = getelementptr inbounds i8, ptr %0, i64 108
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = sdiv i32 %34, 2
  %36 = add nsw i32 %35, %32
  %37 = tail call ptr @P_SpawnMobj(i32 noundef %28, i32 noundef %30, i32 noundef %36, i32 noundef 38) #2
  %38 = tail call i32 @P_Random() #2
  %39 = tail call i32 @P_Random() #2
  %40 = sub nsw i32 %38, %39
  %41 = shl i32 %40, 12
  %42 = getelementptr inbounds i8, ptr %37, i64 112
  store i32 %41, ptr %42, align 8, !tbaa !21
  %43 = tail call i32 @P_Random() #2
  %44 = tail call i32 @P_Random() #2
  %45 = sub nsw i32 %43, %44
  %46 = shl i32 %45, 12
  %47 = getelementptr inbounds i8, ptr %37, i64 116
  store i32 %46, ptr %47, align 4, !tbaa !22
  br label %48

48:                                               ; preds = %21, %23, %26, %19, %1, %18, %7
  ret i32 1
}

declare void @P_RemoveMobj(ptr noundef) local_unnamed_addr #0

declare ptr @P_SpawnMobj(i32 noundef, i32 noundef, i32 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, !11, i64 164}
!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 = !{!6, !11, i64 160}
!15 = !{!6, !11, i64 108}
!16 = !{!6, !11, i64 104}
!17 = !{!11, !11, i64 0}
!18 = !{!6, !11, i64 24}
!19 = !{!6, !11, i64 28}
!20 = !{!6, !11, i64 32}
!21 = !{!6, !11, i64 112}
!22 = !{!6, !11, i64 116}


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