; LLVM IR from clausecker/24puzzle :: puzzle (puzzle_parity)

; 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.puzzle = type { [25 x i8], [7 x i8], [25 x i8], [7 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @puzzle_parity(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 33554431, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call i64 @zero_location(ptr noundef %7)
  %9 = xor i64 %8, 1
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %6, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %36, %1
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = call i32 @tileset_empty(i32 noundef %12)
  %14 = icmp ne i32 %13, 0
  %15 = xor i1 %14, true
  br i1 %15, label %16, label %37

16:                                               ; preds = %11
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = xor i32 %17, 1
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = call i32 @tileset_get_least(i32 noundef %19)
  store i32 %20, ptr %4, align 4, !tbaa !9
  store i32 %20, ptr %5, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %32, %16
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = call i32 @tileset_remove(i32 noundef %22, i32 noundef %23)
  store i32 %24, ptr %3, align 4, !tbaa !9
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.puzzle, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [25 x i8], ptr %26, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  store i32 %31, ptr %4, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %21
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = icmp ne i32 %33, %34
  br i1 %35, label %21, label %36, !llvm.loop !12

36:                                               ; preds = %32
  br label %11, !llvm.loop !14

37:                                               ; preds = %11
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = and i32 %38, 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %39
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @zero_location(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_empty(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_get_least(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_remove(i32 noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @puzzle_parity(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @zero_location(ptr noundef %0)
  %3 = trunc i64 %2 to i32
  %.013 = xor i32 %3, 1
  %4 = tail call i32 @tileset_empty(i32 noundef 33554431)
  %.not14 = icmp eq i32 %4, 0
  br i1 %.not14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  br label %6

6:                                                ; preds = %.lr.ph, %14
  %.016 = phi i32 [ %.013, %.lr.ph ], [ %.0, %14 ]
  %.01015 = phi i32 [ 33554431, %.lr.ph ], [ %9, %14 ]
  %7 = tail call i32 @tileset_get_least(i32 noundef %.01015)
  br label %8

8:                                                ; preds = %8, %6
  %.011 = phi i32 [ %7, %6 ], [ %13, %8 ]
  %.1 = phi i32 [ %.01015, %6 ], [ %9, %8 ]
  %9 = tail call i32 @tileset_remove(i32 noundef %.1, i32 noundef %.011)
  %10 = sext i32 %.011 to i64
  %11 = getelementptr inbounds [25 x i8], ptr %5, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = zext i8 %12 to i32
  %.not12 = icmp eq i32 %7, %13
  br i1 %.not12, label %14, label %8, !llvm.loop !8

14:                                               ; preds = %8
  %.0 = xor i32 %.016, 1
  %15 = tail call i32 @tileset_empty(i32 noundef %9)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %6, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %14, %1
  %.0.lcssa = phi i32 [ %.013, %1 ], [ %.0, %14 ]
  %16 = and i32 %.0.lcssa, 1
  ret i32 %16
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @zero_location(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_empty(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_get_least(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_remove(i32 noundef, i32 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 = { inlinehint 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" }

!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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass