; LLVM IR from clausecker/24puzzle :: tileset (tileset_string)

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

@.str = external hidden unnamed_addr constant [5 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 uwtable
define dso_local void @tileset_string(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca [3 x i8], align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 3, ptr %6) #6
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %7, i8 32, i64 75, i1 false)
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 75
  store i8 0, ptr %9, align 1, !tbaa !11
  store i64 0, ptr %5, align 8, !tbaa !12
  br label %10

10:                                               ; preds = %39, %2
  %11 = load i64, ptr %5, align 8, !tbaa !12
  %12 = icmp ult i64 %11, 25
  br i1 %12, label %13, label %42

13:                                               ; preds = %10
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !12
  %16 = trunc i64 %15 to i32
  %17 = call i32 @tileset_has(i32 noundef %14, i32 noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %28

19:                                               ; preds = %13
  %20 = getelementptr inbounds [3 x i8], ptr %6, i64 0, i64 0
  %21 = load i64, ptr %5, align 8, !tbaa !12
  %22 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %20, ptr noundef @.str, i64 noundef %21) #6
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %5, align 8, !tbaa !12
  %25 = mul i64 3, %24
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = getelementptr inbounds [3 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %26, ptr align 1 %27, i64 2, i1 false)
  br label %28

28:                                               ; preds = %19, %13
  %29 = load i64, ptr %5, align 8, !tbaa !12
  %30 = urem i64 %29, 5
  %31 = icmp eq i64 %30, 4
  br i1 %31, label %32, label %38

32:                                               ; preds = %28
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %5, align 8, !tbaa !12
  %35 = mul i64 3, %34
  %36 = add i64 %35, 2
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  store i8 10, ptr %37, align 1, !tbaa !11
  br label %38

38:                                               ; preds = %32, %28
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %5, align 8, !tbaa !12
  %41 = add i64 %40, 1
  store i64 %41, ptr %5, align 8, !tbaa !12
  br label %10, !llvm.loop !14

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

; 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: inlinehint nounwind uwtable
declare hidden i32 @tileset_has(i32 noundef, i32 noundef) #3

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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 = { 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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: mustprogress 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 void @tileset_string(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [3 x i8], align 2
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %3) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(75) %0, i8 32, i64 75, i1 false)
  %4 = getelementptr inbounds i8, ptr %0, i64 75
  store i8 0, ptr %4, align 1, !tbaa !5
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 2
  br label %5

5:                                                ; preds = %2, %18
  %.011 = phi i64 [ 0, %2 ], [ %19, %18 ]
  %6 = trunc nuw nsw i64 %.011 to i32
  %7 = tail call i32 @tileset_has(i32 noundef %1, i32 noundef %6)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %13, label %8

8:                                                ; preds = %5
  %9 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.011) #5
  %10 = mul nuw nsw i64 %.011, 3
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  %12 = load i16, ptr %3, align 2
  store i16 %12, ptr %11, align 1
  br label %13

13:                                               ; preds = %8, %5
  %.lhs.trunc = trunc nuw i64 %.011 to i8
  %14 = urem i8 %.lhs.trunc, 5
  %15 = icmp eq i8 %14, 4
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = mul nuw nsw i64 %.011, 3
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %17
  store i8 10, ptr %gep, align 1, !tbaa !5
  br label %18

18:                                               ; preds = %13, %16
  %19 = add nuw nsw i64 %.011, 1
  %exitcond.not = icmp eq i64 %19, 25
  br i1 %exitcond.not, label %20, label %5, !llvm.loop !8

20:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %3) #5
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_has(i32 noundef, i32 noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 #5 = { 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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass