; LLVM IR from totte174/minesolve :: src (main)

; 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.argp = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.timespec = type { i64, i64 }
%struct.Arguments = type { [2048 x i8], i32, i32, i32, i32, i32, i32, i8, i8, i8, i8 }

@argp = external hidden global %struct.argp, align 8
@stdin = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [19 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 %struct.timespec, align 8
  %7 = alloca %struct.Arguments, align 4
  %8 = alloca i32, align 4
  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 16, ptr %6) #6
  %9 = call i32 @timespec_get(ptr noundef %6, i32 noundef 1) #6
  %10 = getelementptr inbounds %struct.timespec, ptr %6, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = trunc i64 %11 to i32
  call void @srand(i32 noundef %12) #6
  call void @llvm.lifetime.start.p0(i64 2076, ptr %7) #6
  call void @llvm.memset.p0.i64(ptr align 4 %7, i8 0, i64 2076, i1 false)
  %13 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 2
  store i32 30, ptr %13, align 4
  %14 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 3
  store i32 16, ptr %14, align 4
  %15 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 4
  store i32 99, ptr %15, align 4
  %16 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 6
  store i32 1, ptr %16, align 4
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = call i32 @argp_parse(ptr noundef @argp, i32 noundef %17, ptr noundef %18, i32 noundef 0, ptr noundef null, ptr noundef %7)
  %20 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %39

23:                                               ; preds = %2
  %24 = load ptr, ptr @stdin, align 8, !tbaa !9
  %25 = call i32 @fileno(ptr noundef %24) #6
  %26 = call i32 @isatty(i32 noundef %25) #6
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %39, label %28

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %29 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 0
  %30 = getelementptr inbounds [2048 x i8], ptr %29, i64 0, i64 0
  %31 = call i64 @read(i32 noundef 0, ptr noundef %30, i64 noundef 2048)
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %28
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 1
  store i32 %36, ptr %37, align 4, !tbaa !14
  br label %38

38:                                               ; preds = %35, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %39

39:                                               ; preds = %38, %23, %2
  %40 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 5
  %41 = load i32, ptr %40, align 4, !tbaa !17
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  call void @simulate(ptr noundef %7)
  br label %65

44:                                               ; preds = %39
  %45 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = icmp sgt i32 %46, 0
  br i1 %47, label %48, label %61

48:                                               ; preds = %44
  %49 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 9
  %50 = load i8, ptr %49, align 2, !tbaa !18, !range !19, !noundef !20
  %51 = trunc i8 %50 to i1
  br i1 %51, label %52, label %53

52:                                               ; preds = %48
  call void @show_board(ptr noundef %7)
  br label %60

53:                                               ; preds = %48
  %54 = getelementptr inbounds %struct.Arguments, ptr %7, i32 0, i32 10
  %55 = load i8, ptr %54, align 1, !tbaa !21, !range !19, !noundef !20
  %56 = trunc i8 %55 to i1
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  call void @show_probability(ptr noundef %7)
  br label %59

58:                                               ; preds = %53
  call void @solve_board(ptr noundef %7)
  br label %59

59:                                               ; preds = %58, %57
  br label %60

60:                                               ; preds = %59, %52
  br label %64

61:                                               ; preds = %44
  %62 = load ptr, ptr @stderr, align 8, !tbaa !9
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.2) #6
  br label %64

64:                                               ; preds = %61, %60
  br label %65

65:                                               ; preds = %64, %43
  call void @exit(i32 noundef 0) #7
  unreachable
}

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

; Function Attrs: nounwind
declare i32 @timespec_get(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind
declare void @srand(i32 noundef) #2

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

declare i32 @argp_parse(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) #2

; Function Attrs: nounwind
declare i32 @fileno(ptr noundef) #2

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #4

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

declare void @simulate(ptr noundef) #4

declare void @show_board(ptr noundef) #4

declare void @show_probability(ptr noundef) #4

declare void @solve_board(ptr noundef) #4

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 = { 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 = !{!"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, !13, i64 8}
!12 = !{!"timespec", !13, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 2048}
!15 = !{!"Arguments", !7, i64 0, !6, i64 2048, !6, i64 2052, !6, i64 2056, !6, i64 2060, !6, i64 2064, !6, i64 2068, !16, i64 2072, !16, i64 2073, !16, i64 2074, !16, i64 2075}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!15, !6, i64 2064}
!18 = !{!15, !16, i64 2074}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!15, !16, i64 2075}


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

%struct.argp = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.timespec = type { i64, i64 }
%struct.Arguments = type { [2048 x i8], i32, i32, i32, i32, i32, i32, i8, i8, i8, i8 }

@argp = external hidden global %struct.argp, align 8
@stdin = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.timespec, align 8
  %4 = alloca %struct.Arguments, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #8
  %5 = call i32 @timespec_get(ptr noundef nonnull %3, i32 noundef 1) #8
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = trunc i64 %7 to i32
  call void @srand(i32 noundef %8) #8
  call void @llvm.lifetime.start.p0(i64 2076, ptr nonnull %4) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(2076) %4, i8 0, i64 2076, i1 false)
  %9 = getelementptr inbounds i8, ptr %4, i64 2052
  store i32 30, ptr %9, align 4
  %10 = getelementptr inbounds i8, ptr %4, i64 2056
  store i32 16, ptr %10, align 4
  %11 = getelementptr inbounds i8, ptr %4, i64 2060
  store i32 99, ptr %11, align 4
  %12 = getelementptr inbounds i8, ptr %4, i64 2068
  store i32 1, ptr %12, align 4
  %13 = call i32 @argp_parse(ptr noundef nonnull @argp, i32 noundef %0, ptr noundef %1, i32 noundef 0, ptr noundef null, ptr noundef nonnull %4) #8
  %14 = getelementptr inbounds i8, ptr %4, i64 2048
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %26

17:                                               ; preds = %2
  %18 = load ptr, ptr @stdin, align 8, !tbaa !14
  %19 = call i32 @fileno(ptr noundef %18) #8
  %20 = call i32 @isatty(i32 noundef %19) #8
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %21, label %26

21:                                               ; preds = %17
  %22 = call i64 @read(i32 noundef 0, ptr noundef nonnull %4, i64 noundef 2048) #8
  %23 = trunc i64 %22 to i32
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i32 %23, ptr %14, align 4, !tbaa !10
  br label %26

26:                                               ; preds = %21, %25, %17, %2
  %27 = getelementptr inbounds i8, ptr %4, i64 2064
  %28 = load i32, ptr %27, align 4, !tbaa !16
  %.not3 = icmp eq i32 %28, 0
  br i1 %.not3, label %30, label %29

29:                                               ; preds = %26
  call void @simulate(ptr noundef nonnull %4) #8
  br label %47

30:                                               ; preds = %26
  %31 = load i32, ptr %14, align 4, !tbaa !10
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %44

33:                                               ; preds = %30
  %34 = getelementptr inbounds i8, ptr %4, i64 2074
  %35 = load i8, ptr %34, align 2, !tbaa !17, !range !18, !noundef !19
  %36 = trunc nuw i8 %35 to i1
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  call void @show_board(ptr noundef nonnull %4) #8
  br label %47

38:                                               ; preds = %33
  %39 = getelementptr inbounds i8, ptr %4, i64 2075
  %40 = load i8, ptr %39, align 1, !tbaa !20, !range !18, !noundef !19
  %41 = trunc nuw i8 %40 to i1
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  call void @show_probability(ptr noundef nonnull %4) #8
  br label %47

43:                                               ; preds = %38
  call void @solve_board(ptr noundef nonnull %4) #8
  br label %47

44:                                               ; preds = %30
  %45 = load ptr, ptr @stderr, align 8, !tbaa !14
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef nonnull @.str.2) #9
  br label %47

47:                                               ; preds = %44, %42, %43, %37, %29
  call void @exit(i32 noundef 0) #10
  unreachable
}

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

; Function Attrs: nounwind
declare i32 @timespec_get(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #2

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

declare i32 @argp_parse(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fileno(ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #6

declare void @simulate(ptr noundef) local_unnamed_addr #4

declare void @show_board(ptr noundef) local_unnamed_addr #4

declare void @show_probability(ptr noundef) local_unnamed_addr #4

declare void @solve_board(ptr noundef) local_unnamed_addr #4

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

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

attributes #0 = { noreturn 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 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #6 = { nofree "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 = { 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 #8 = { nounwind }
attributes #9 = { cold nounwind }
attributes #10 = { 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, !7, i64 8}
!6 = !{!"timespec", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 2048}
!11 = !{!"Arguments", !8, i64 0, !12, i64 2048, !12, i64 2052, !12, i64 2056, !12, i64 2060, !12, i64 2064, !12, i64 2068, !13, i64 2072, !13, i64 2073, !13, i64 2074, !13, i64 2075}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!11, !12, i64 2064}
!17 = !{!11, !13, i64 2074}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!11, !13, i64 2075}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass