; LLVM IR from kostya/crystal-benchmarks-game :: meteor (meteor)

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

@board = external dso_local global i64, align 8
@bad_even_triple = external dso_local global [32768 x i32], align 16
@bad_odd_triple = external dso_local global [32768 x i32], align 16

; 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 i32 @boardHasIslands(i8 noundef signext %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  %6 = load i8, ptr %3, align 1, !tbaa !5
  %7 = sext i8 %6 to i32
  %8 = icmp sge i32 %7, 40
  br i1 %8, label %9, label %10

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

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %11 = load i64, ptr @board, align 8, !tbaa !8
  %12 = load i8, ptr %3, align 1, !tbaa !5
  %13 = sext i8 %12 to i32
  %14 = sdiv i32 %13, 5
  %15 = mul nsw i32 %14, 5
  %16 = zext i32 %15 to i64
  %17 = lshr i64 %11, %16
  %18 = and i64 %17, 32767
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %4, align 4, !tbaa !10
  %20 = load i8, ptr %3, align 1, !tbaa !5
  %21 = sext i8 %20 to i32
  %22 = sdiv i32 %21, 5
  %23 = srem i32 %22, 2
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %10
  %26 = load i32, ptr %4, align 4, !tbaa !10
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [32768 x i32], ptr @bad_odd_triple, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !10
  store i32 %29, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %35

30:                                               ; preds = %10
  %31 = load i32, ptr %4, align 4, !tbaa !10
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [32768 x i32], ptr @bad_even_triple, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !10
  store i32 %34, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %35

35:                                               ; preds = %30, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %36

36:                                               ; preds = %35, %9
  %37 = load i32, ptr %2, align 4
  ret i32 %37
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, 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"

@board = external dso_local local_unnamed_addr global i64, align 8
@bad_even_triple = external dso_local local_unnamed_addr global [32768 x i32], align 16
@bad_odd_triple = external dso_local local_unnamed_addr global [32768 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @boardHasIslands(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = icmp sgt i8 %0, 39
  br i1 %2, label %14, label %3

3:                                                ; preds = %1
  %4 = load i64, ptr @board, align 8, !tbaa !5
  %5 = sdiv i8 %0, 5
  %6 = sext i8 %5 to i32
  %7 = mul nsw i32 %6, 5
  %8 = zext nneg i32 %7 to i64
  %9 = lshr i64 %4, %8
  %10 = and i32 %6, 1
  %.not = icmp eq i32 %10, 0
  %11 = and i64 %9, 32767
  %12 = getelementptr inbounds [32768 x i32], ptr @bad_odd_triple, i64 0, i64 %11
  %13 = getelementptr inbounds [32768 x i32], ptr @bad_even_triple, i64 0, i64 %11
  %.0.in = select i1 %.not, ptr %13, ptr %12
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %1, %3
  %.1 = phi i32 [ %.0, %3 ], [ 0, %1 ]
  ret i32 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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