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

; 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: 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 @puzzle_parse(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 64, i1 false)
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.puzzle, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [25 x i8], ptr %11, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %12, i8 -1, i64 25, i1 false)
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %74, %2
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ult i64 %14, 25
  br i1 %15, label %16, label %77

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i64 @strtol(ptr noundef %17, ptr noundef %5, i32 noundef 10) #5
  store i64 %18, ptr %7, align 8, !tbaa !9
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %24, label %21

21:                                               ; preds = %16
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp sge i64 %22, 25
  br i1 %23, label %24, label %25

24:                                               ; preds = %21, %16
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

25:                                               ; preds = %21
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.puzzle, ptr %26, i32 0, i32 0
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds [25 x i8], ptr %27, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = icmp ne i32 %31, 255
  br i1 %32, label %33, label %34

33:                                               ; preds = %25
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

34:                                               ; preds = %25
  br label %35

35:                                               ; preds = %47, %34
  %36 = call ptr @__ctype_b_loc() #6
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i16, ptr %37, i64 %41
  %43 = load i16, ptr %42, align 2, !tbaa !12
  %44 = zext i16 %43 to i32
  %45 = and i32 %44, 8192
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %35
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %5, align 8, !tbaa !5
  br label %35, !llvm.loop !14

50:                                               ; preds = %35
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = icmp ne i32 %53, 44
  br i1 %54, label %55, label %59

55:                                               ; preds = %50
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = icmp ult i64 %56, 24
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

59:                                               ; preds = %55, %50
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = trunc i64 %60 to i8
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.puzzle, ptr %62, i32 0, i32 2
  %64 = load i64, ptr %6, align 8, !tbaa !9
  %65 = getelementptr inbounds [25 x i8], ptr %63, i64 0, i64 %64
  store i8 %61, ptr %65, align 1, !tbaa !11
  %66 = load i64, ptr %6, align 8, !tbaa !9
  %67 = trunc i64 %66 to i8
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.puzzle, ptr %68, i32 0, i32 0
  %70 = load i64, ptr %7, align 8, !tbaa !9
  %71 = getelementptr inbounds [25 x i8], ptr %69, i64 0, i64 %70
  store i8 %67, ptr %71, align 1, !tbaa !11
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i32 1
  store ptr %73, ptr %5, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %59
  %75 = load i64, ptr %6, align 8, !tbaa !9
  %76 = add i64 %75, 1
  store i64 %76, ptr %6, align 8, !tbaa !9
  br label %13, !llvm.loop !16

77:                                               ; preds = %13
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

78:                                               ; preds = %77, %58, %33, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind
declare i64 @strtol(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind "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 #4 = { nounwind willreturn memory(none) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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: nofree nounwind uwtable
define dso_local range(i32 -1, 1) i32 @puzzle_parse(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %4, i8 0, i64 40, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(25) %0, i8 -1, i64 25, i1 false)
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  br label %6

6:                                                ; preds = %2, %25
  %7 = phi ptr [ %1, %2 ], [ %21, %25 ]
  %.01823 = phi i64 [ 0, %2 ], [ %29, %25 ]
  %8 = call i64 @strtol(ptr noundef %7, ptr noundef nonnull %3, i32 noundef 10) #4
  %or.cond = icmp ugt i64 %8, 24
  br i1 %or.cond, label %30, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds [25 x i8], ptr %0, i64 0, i64 %8
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %.not = icmp eq i8 %11, -1
  br i1 %.not, label %.preheader, label %30

.preheader:                                       ; preds = %9
  %12 = tail call ptr @__ctype_b_loc() #5
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %.promoted = load ptr, ptr %3, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %14, %.preheader
  %15 = phi ptr [ %.promoted, %.preheader ], [ %21, %14 ]
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i64
  %18 = getelementptr inbounds i16, ptr %13, i64 %17
  %19 = load i16, ptr %18, align 2, !tbaa !10
  %20 = and i16 %19, 8192
  %.not20 = icmp eq i16 %20, 0
  %21 = getelementptr inbounds i8, ptr %15, i64 1
  br i1 %.not20, label %22, label %14, !llvm.loop !12

22:                                               ; preds = %14
  %23 = icmp ne i8 %16, 44
  %24 = icmp ne i64 %.01823, 24
  %or.cond3 = and i1 %24, %23
  br i1 %or.cond3, label %30, label %25

25:                                               ; preds = %22
  %26 = trunc nuw nsw i64 %8 to i8
  %27 = getelementptr inbounds [25 x i8], ptr %5, i64 0, i64 %.01823
  store i8 %26, ptr %27, align 1, !tbaa !9
  %28 = trunc nuw nsw i64 %.01823 to i8
  store i8 %28, ptr %10, align 1, !tbaa !9
  store ptr %21, ptr %3, align 8, !tbaa !5
  %29 = add nuw nsw i64 %.01823, 1
  %exitcond.not = icmp eq i64 %29, 25
  br i1 %exitcond.not, label %30, label %6, !llvm.loop !14

30:                                               ; preds = %25, %22, %9, %6
  %.0 = phi i32 [ -1, %6 ], [ -1, %9 ], [ -1, %22 ], [ 0, %25 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtol(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #3

attributes #0 = { nofree 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nofree nounwind willreturn "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass