; LLVM IR from t-dillon/tdoku :: example (solve)

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

@stdin = external global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [81 x i8], align 16
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %14, label %19

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call i64 @atoll(ptr noundef %17) #7
  br label %20

19:                                               ; preds = %2
  br label %20

20:                                               ; preds = %19, %14
  %21 = phi i64 [ %18, %14 ], [ 10000, %19 ]
  store i64 %21, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store ptr null, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 81, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  br label %22

22:                                               ; preds = %52, %36, %20
  %23 = load ptr, ptr @stdin, align 8, !tbaa !9
  %24 = call i64 @getline(ptr noundef %7, ptr noundef %9, ptr noundef %23)
  %25 = icmp ne i64 %24, -1
  br i1 %25, label %26, label %57

26:                                               ; preds = %22
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  %28 = call i64 @strlen(ptr noundef %27) #7
  %29 = icmp ult i64 %28, 81
  br i1 %29, label %36, label %30

30:                                               ; preds = %26
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i64 0
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 35
  br i1 %35, label %36, label %37

36:                                               ; preds = %30, %26
  br label %22, !llvm.loop !14

37:                                               ; preds = %30
  %38 = getelementptr inbounds [81 x i8], ptr %8, i64 0, i64 0
  store i8 0, ptr %38, align 16, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = load i64, ptr %6, align 8, !tbaa !11
  %41 = getelementptr inbounds [81 x i8], ptr %8, i64 0, i64 0
  %42 = call i64 @SolveSudoku(ptr noundef %39, i64 noundef %40, i32 noundef 0, ptr noundef %41, ptr noundef %10)
  store i64 %42, ptr %11, align 8, !tbaa !11
  %43 = load i64, ptr %6, align 8, !tbaa !11
  %44 = icmp ugt i64 %43, 1
  br i1 %44, label %45, label %52

45:                                               ; preds = %37
  %46 = load i64, ptr %11, align 8, !tbaa !11
  %47 = icmp eq i64 %46, 1
  br i1 %47, label %48, label %52

48:                                               ; preds = %45
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  %50 = getelementptr inbounds [81 x i8], ptr %8, i64 0, i64 0
  %51 = call i64 @SolveSudoku(ptr noundef %49, i64 noundef 1, i32 noundef 0, ptr noundef %50, ptr noundef %10)
  br label %52

52:                                               ; preds = %48, %45, %37
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = load i64, ptr %11, align 8, !tbaa !11
  %55 = getelementptr inbounds [81 x i8], ptr %8, i64 0, i64 0
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %53, i64 noundef %54, ptr noundef %55)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %22, !llvm.loop !14

57:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 81, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %58 = load i32, ptr %3, align 4
  ret i32 %58
}

; 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 willreturn memory(read) uwtable
declare i64 @atoll(ptr noundef nonnull) #2

declare i64 @getline(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @SolveSudoku(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) #5

declare i32 @printf(ptr noundef, ...) #3

; 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 willreturn memory(read) 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 = { nounwind willreturn memory(read) "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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !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"

@stdin = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %4 = alloca [81 x i8], align 16
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = icmp sgt i32 %0, 1
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call i64 @atoll(ptr nocapture noundef %10) #7
  %12 = freeze i64 %11
  br label %13

13:                                               ; preds = %2, %8
  %.fr8 = phi i64 [ %12, %8 ], [ 10000, %2 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #8
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 81, ptr nonnull %4) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #8
  %14 = load ptr, ptr @stdin, align 8, !tbaa !5
  %15 = call i64 @getline(ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef %14) #8
  %.not7 = icmp eq i64 %15, -1
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13
  %16 = icmp ugt i64 %.fr8, 1
  br i1 %16, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.backedge.us
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %17) #7
  %19 = icmp ult i64 %18, 81
  br i1 %19, label %.backedge.us, label %20

20:                                               ; preds = %.lr.ph.split.us
  %21 = load i8, ptr %17, align 1, !tbaa !9
  %22 = icmp eq i8 %21, 35
  br i1 %22, label %.backedge.us, label %23

23:                                               ; preds = %20
  store i8 0, ptr %4, align 16, !tbaa !9
  %24 = call i64 @SolveSudoku(ptr noundef nonnull %17, i64 noundef %.fr8, i32 noundef 0, ptr noundef nonnull %4, ptr noundef nonnull %6)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %25, i64 noundef %24, ptr noundef nonnull %4)
  br label %.backedge.us

.backedge.us:                                     ; preds = %.lr.ph.split.us, %20, %23
  %27 = load ptr, ptr @stdin, align 8, !tbaa !5
  %28 = call i64 @getline(ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef %27) #8
  %.not.us = icmp eq i64 %28, -1
  br i1 %.not.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !10

.lr.ph.split:                                     ; preds = %.lr.ph, %.backedge
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %29) #7
  %31 = icmp ult i64 %30, 81
  br i1 %31, label %.backedge, label %32

32:                                               ; preds = %.lr.ph.split
  %33 = load i8, ptr %29, align 1, !tbaa !9
  %34 = icmp eq i8 %33, 35
  br i1 %34, label %.backedge, label %37

.backedge:                                        ; preds = %.lr.ph.split, %32, %43
  %35 = load ptr, ptr @stdin, align 8, !tbaa !5
  %36 = call i64 @getline(ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef %35) #8
  %.not = icmp eq i64 %36, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !10

37:                                               ; preds = %32
  store i8 0, ptr %4, align 16, !tbaa !9
  %38 = call i64 @SolveSudoku(ptr noundef nonnull %29, i64 noundef %.fr8, i32 noundef 0, ptr noundef nonnull %4, ptr noundef nonnull %6)
  %39 = icmp eq i64 %38, 1
  br i1 %39, label %40, label %43

40:                                               ; preds = %37
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = call i64 @SolveSudoku(ptr noundef %41, i64 noundef 1, i32 noundef 0, ptr noundef nonnull %4, ptr noundef nonnull %6)
  br label %43

43:                                               ; preds = %40, %37
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %44, i64 noundef %38, ptr noundef nonnull %4)
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge.us, %.backedge, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #8
  call void @llvm.lifetime.end.p0(i64 81, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  ret i32 0
}

; 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 mustprogress nofree nounwind willreturn memory(read) uwtable
declare i64 @atoll(ptr nocapture noundef nonnull) local_unnamed_addr #2

declare i64 @getline(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @SolveSudoku(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #6 = { 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 #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass