; LLVM IR from clausecker/24puzzle :: cmd (compilefsm)

; 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.fsm_state = type { i32, i32 }
%struct.path = type { i64, [256 x i8] }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @tracepath(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca %struct.fsm_state, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [768 x i8], align 16
  %13 = alloca %struct.fsm_state, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 768, ptr %12) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.path, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds [256 x i8], ptr %15, i64 0, i64 0
  %17 = load i8, ptr %16, align 8, !tbaa !11
  %18 = zext i8 %17 to i64
  %19 = call i64 @fsm_start_state(i64 noundef %18)
  store i64 %19, ptr %13, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %13, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  store i64 1, ptr %10, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %79, %4
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %82

24:                                               ; preds = %20
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.path, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = getelementptr inbounds [256 x i8], ptr %27, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = zext i8 %30 to i64
  %32 = load i64, ptr %5, align 4
  %33 = call ptr @fsm_entry_pointer(ptr noundef %25, i64 %32, i64 noundef %31)
  store ptr %33, ptr %11, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = load i32, ptr %34, align 4, !tbaa !13
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %37, label %48

37:                                               ; preds = %24
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.path, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = getelementptr inbounds [256 x i8], ptr %41, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = call i32 @addstate(ptr noundef %38, ptr noundef %39, i32 noundef %45)
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %46, ptr %47, align 4, !tbaa !13
  br label %68

48:                                               ; preds = %24
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = icmp eq i32 %50, -2
  br i1 %51, label %52, label %67

52:                                               ; preds = %48
  %53 = getelementptr inbounds [768 x i8], ptr %12, i64 0, i64 0
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  call void @path_string(ptr noundef %53, ptr noundef %54)
  %55 = load ptr, ptr @stderr, align 8, !tbaa !5
  %56 = getelementptr inbounds [768 x i8], ptr %12, i64 0, i64 0
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str, ptr noundef %56) #7
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = add i64 %58, 1
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.path, ptr %60, i32 0, i32 0
  store i64 %59, ptr %61, align 8, !tbaa !15
  %62 = getelementptr inbounds [768 x i8], ptr %12, i64 0, i64 0
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  call void @path_string(ptr noundef %62, ptr noundef %63)
  %64 = load ptr, ptr @stderr, align 8, !tbaa !5
  %65 = getelementptr inbounds [768 x i8], ptr %12, i64 0, i64 0
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef @.str.1, ptr noundef %65) #7
  call void @exit(i32 noundef 1) #8
  unreachable

67:                                               ; preds = %48
  br label %68

68:                                               ; preds = %67, %37
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.path, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %10, align 8, !tbaa !9
  %72 = getelementptr inbounds [256 x i8], ptr %70, i64 0, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = zext i8 %73 to i32
  %75 = getelementptr inbounds %struct.fsm_state, ptr %5, i32 0, i32 0
  store i32 %74, ptr %75, align 4, !tbaa !17
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = load i32, ptr %76, align 4, !tbaa !13
  %78 = getelementptr inbounds %struct.fsm_state, ptr %5, i32 0, i32 1
  store i32 %77, ptr %78, align 4, !tbaa !19
  br label %79

79:                                               ; preds = %68
  %80 = load i64, ptr %10, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %10, align 8, !tbaa !9
  br label %20, !llvm.loop !20

82:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 768, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  %83 = load i64, ptr %5, align 4
  ret i64 %83
}

; 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 @fsm_start_state(i64 noundef) #2

; 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) #3

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @addstate(ptr noundef, ptr noundef, i32 noundef) #0

declare void @path_string(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #5

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #6

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 "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 #6 = { noreturn 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 #7 = { nounwind }
attributes #8 = { noreturn 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 = !{i64 0, i64 4, !13, i64 4, i64 4, !13}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"path", !10, i64 0, !7, i64 8}
!17 = !{!18, !14, i64 0}
!18 = !{!"fsm_state", !14, i64 0, !14, i64 4}
!19 = !{!18, !14, i64 4}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @tracepath(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [768 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 768, ptr nonnull %5) #6
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load i8, ptr %6, align 8, !tbaa !5
  %8 = zext i8 %7 to i64
  %9 = tail call i64 @fsm_start_state(i64 noundef %8)
  %.sroa.020.0.extract.trunc = trunc i64 %9 to i32
  %.sroa.4.0.extract.shift = lshr i64 %9, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %10 = icmp ugt i64 %3, 1
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4, %26
  %.sroa.4.036 = phi i32 [ %27, %26 ], [ %.sroa.4.0.extract.trunc, %4 ]
  %.sroa.020.035 = phi i32 [ %29, %26 ], [ %.sroa.020.0.extract.trunc, %4 ]
  %.034 = phi i64 [ %30, %26 ], [ 1, %4 ]
  %11 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 %.034
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = zext i8 %12 to i64
  %.sroa.4.0.insert.ext = zext i32 %.sroa.4.036 to i64
  %.sroa.4.0.insert.shift = shl nuw i64 %.sroa.4.0.insert.ext, 32
  %.sroa.020.0.insert.ext = zext i32 %.sroa.020.035 to i64
  %.sroa.020.0.insert.insert = or disjoint i64 %.sroa.4.0.insert.shift, %.sroa.020.0.insert.ext
  %14 = tail call ptr @fsm_entry_pointer(ptr noundef %0, i64 %.sroa.020.0.insert.insert, i64 noundef %13)
  %15 = load i32, ptr %14, align 4, !tbaa !8
  switch i32 %15, label %26 [
    i32 -1, label %16
    i32 -2, label %20
  ]

16:                                               ; preds = %.lr.ph
  %17 = load i8, ptr %11, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = tail call i32 @addstate(ptr noundef %0, ptr noundef %1, i32 noundef %18)
  store i32 %19, ptr %14, align 4, !tbaa !8
  br label %26

20:                                               ; preds = %.lr.ph
  call void @path_string(ptr noundef nonnull %5, ptr noundef nonnull %2) #6
  %21 = load ptr, ptr @stderr, align 8, !tbaa !10
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull %5) #7
  %23 = add nuw i64 %.034, 1
  store i64 %23, ptr %2, align 8, !tbaa !12
  call void @path_string(ptr noundef nonnull %5, ptr noundef nonnull %2) #6
  %24 = load ptr, ptr @stderr, align 8, !tbaa !10
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.1, ptr noundef nonnull %5) #7
  call void @exit(i32 noundef 1) #8
  unreachable

26:                                               ; preds = %.lr.ph, %16
  %27 = phi i32 [ %15, %.lr.ph ], [ %19, %16 ]
  %28 = load i8, ptr %11, align 1, !tbaa !5
  %29 = zext i8 %28 to i32
  %30 = add nuw i64 %.034, 1
  %exitcond.not = icmp eq i64 %30, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %26, %4
  %.sroa.020.0.lcssa = phi i32 [ %.sroa.020.0.extract.trunc, %4 ], [ %29, %26 ]
  %.sroa.4.0.lcssa = phi i32 [ %.sroa.4.0.extract.trunc, %4 ], [ %27, %26 ]
  call void @llvm.lifetime.end.p0(i64 768, ptr nonnull %5) #6
  %.sroa.4.0.insert.ext26 = zext i32 %.sroa.4.0.lcssa to i64
  %.sroa.4.0.insert.shift27 = shl nuw i64 %.sroa.4.0.insert.ext26, 32
  %.sroa.020.0.insert.ext22 = zext i32 %.sroa.020.0.lcssa to i64
  %.sroa.020.0.insert.insert24 = or disjoint i64 %.sroa.4.0.insert.shift27, %.sroa.020.0.insert.ext22
  ret i64 %.sroa.020.0.insert.insert24
}

; Function Attrs: mustprogress 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 @fsm_start_state(i64 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @addstate(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @path_string(ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

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 = { mustprogress 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 = { "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 = { noreturn 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 #6 = { nounwind }
attributes #7 = { cold nounwind }
attributes #8 = { noreturn 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 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"path", !14, i64 0, !6, i64 8}
!14 = !{!"long", !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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