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

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

@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; 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
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @puzzle_visualization(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %46, %2
  %7 = load i64, ptr %5, align 8, !tbaa !9
  %8 = icmp ult i64 %7, 25
  br i1 %8, label %9, label %49

9:                                                ; preds = %6
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.puzzle, ptr %10, i32 0, i32 2
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = getelementptr inbounds [25 x i8], ptr %11, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = zext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %28

17:                                               ; preds = %9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = urem i64 %19, 5
  %21 = icmp eq i64 %20, 4
  %22 = zext i1 %21 to i64
  %23 = select i1 %21, i32 10, i32 32
  %24 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %18, ptr noundef @.str.1, i32 noundef %23) #3
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %45

28:                                               ; preds = %9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.puzzle, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds [25 x i8], ptr %31, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = urem i64 %36, 5
  %38 = icmp eq i64 %37, 4
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 10, i32 32
  %41 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %29, ptr noundef @.str.2, i32 noundef %35, i32 noundef %40) #3
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  store ptr %44, ptr %3, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %28, %17
  br label %46

46:                                               ; preds = %45
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = add i64 %47, 1
  store i64 %48, ptr %5, align 8, !tbaa !9
  br label %6, !llvm.loop !12

49:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @puzzle_visualization(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 32
  br label %4

4:                                                ; preds = %2, %19
  %.016 = phi i64 [ 0, %2 ], [ %20, %19 ]
  %.01115 = phi ptr [ %0, %2 ], [ %.1, %19 ]
  %5 = getelementptr inbounds [25 x i8], ptr %3, i64 0, i64 %.016
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = icmp eq i8 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %4
  %.lhs.trunc = trunc nuw i64 %.016 to i8
  %9 = urem i8 %.lhs.trunc, 5
  %10 = icmp eq i8 %9, 4
  %11 = select i1 %10, i32 10, i32 32
  %12 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %.01115, ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %11) #2
  br label %19

13:                                               ; preds = %4
  %14 = zext i8 %6 to i32
  %.lhs.trunc13 = trunc nuw i64 %.016 to i8
  %15 = urem i8 %.lhs.trunc13, 5
  %16 = icmp eq i8 %15, 4
  %17 = select i1 %16, i32 10, i32 32
  %18 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %.01115, ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %14, i32 noundef %17) #2
  br label %19

19:                                               ; preds = %8, %13
  %.pn.in = phi i32 [ %12, %8 ], [ %18, %13 ]
  %.pn = sext i32 %.pn.in to i64
  %.1 = getelementptr inbounds i8, ptr %.01115, i64 %.pn
  %20 = add nuw nsw i64 %.016, 1
  %exitcond.not = icmp eq i64 %20, 25
  br i1 %exitcond.not, label %21, label %4, !llvm.loop !8

21:                                               ; preds = %19
  ret void
}

attributes #0 = { nofree 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 #1 = { 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 #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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass