; LLVM IR from jordan4ibanez/tinyphysicsengine :: old/test.ll (TPE_bodyUpdateAntivibration)

; 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.TPE_Body = type { i8, [3 x i32], [2 x ptr], i8, i32, %struct.TPE_Vec4, %struct.TPE_Vec4, %struct.TPE_RotationState, i32, i8 }
%struct.TPE_Vec4 = type { i32, i32, i32, i32 }
%struct.TPE_RotationState = type { %struct.TPE_Vec4, %struct.TPE_Vec4, i32 }

; 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 zeroext i8 @_TPE_bodyUpdateAntivibration(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.TPE_Body, ptr %4, i32 0, i32 9
  %6 = load i8, ptr %5, align 8, !tbaa !9
  %7 = zext i8 %6 to i32
  %8 = and i32 %7, 127
  %9 = trunc i32 %8 to i8
  store i8 %9, ptr %3, align 1, !tbaa !14
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.TPE_Body, ptr %10, i32 0, i32 9
  %12 = load i8, ptr %11, align 8, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = and i32 %13, 128
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %39

16:                                               ; preds = %1
  %17 = load i8, ptr %3, align 1, !tbaa !14
  %18 = zext i8 %17 to i32
  %19 = icmp slt i32 %18, 107
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = load i8, ptr %3, align 1, !tbaa !14
  %22 = zext i8 %21 to i32
  %23 = add nsw i32 %22, 20
  br label %25

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %24, %20
  %26 = phi i32 [ %23, %20 ], [ 127, %24 ]
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %3, align 1, !tbaa !14
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TPE_Body, ptr %28, i32 0, i32 9
  %30 = load i8, ptr %29, align 8, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 128
  %33 = load i8, ptr %3, align 1, !tbaa !14
  %34 = zext i8 %33 to i32
  %35 = or i32 %32, %34
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TPE_Body, ptr %37, i32 0, i32 9
  store i8 %36, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %25, %1
  %40 = load i8, ptr %3, align 1, !tbaa !14
  %41 = zext i8 %40 to i32
  %42 = icmp sle i32 %41, 100
  %43 = zext i1 %42 to i32
  %44 = trunc i32 %43 to i8
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i8 %44
}

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 = { 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, !7, i64 112}
!10 = !{!"", !7, i64 0, !7, i64 4, !7, i64 16, !7, i64 32, !11, i64 36, !12, i64 40, !12, i64 56, !13, i64 72, !11, i64 108, !7, i64 112}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!13 = !{!"", !12, i64 0, !12, i64 16, !11, i64 32}
!14 = !{!7, !7, i64 0}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local zeroext range(i8 0, 2) i8 @_TPE_bodyUpdateAntivibration(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = load i8, ptr %2, align 8, !tbaa !5
  %4 = and i8 %3, 127
  %.not = icmp sgt i8 %3, -1
  br i1 %.not, label %8, label %5

5:                                                ; preds = %1
  %6 = icmp ult i8 %4, 107
  %narrow = add nuw i8 %4, 20
  %narrow8 = select i1 %6, i8 %narrow, i8 127
  %7 = or i8 %narrow8, -128
  store i8 %7, ptr %2, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %5, %1
  %.0 = phi i8 [ %narrow8, %5 ], [ %4, %1 ]
  %9 = icmp ult i8 %.0, 101
  %10 = zext i1 %9 to i8
  ret i8 %10
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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" }

!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, !7, i64 112}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 16, !7, i64 32, !9, i64 36, !10, i64 40, !10, i64 56, !11, i64 72, !9, i64 108, !7, i64 112}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12}
!11 = !{!"", !10, i64 0, !10, i64 16, !9, i64 32}


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