; LLVM IR from clausecker/24puzzle :: test (indextest)

; 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] }
%struct.index = type { i32, i32, i32 }
%struct.index_aux = type { [32 x i8], [16 x i8], i32, i32, i32, i32, i32, ptr, [16 x i8] }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [20 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 i64, align 8
  %8 = alloca %struct.puzzle, align 8
  %9 = alloca %struct.index, align 4
  %10 = alloca %struct.index_aux, align 32
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 10000, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 64, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 96, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 254, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  br label %14

14:                                               ; preds = %40, %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = call i32 @__posix_getopt(i32 noundef %15, ptr noundef %16, ptr noundef @.str) #5
  store i32 %17, ptr %12, align 4, !tbaa !5
  %18 = load i32, ptr %12, align 4, !tbaa !5
  %19 = icmp ne i32 %18, -1
  br i1 %19, label %20, label %41

20:                                               ; preds = %14
  %21 = load i32, ptr %12, align 4, !tbaa !5
  switch i32 %21, label %36 [
    i32 105, label %22
    i32 116, label %25
  ]

22:                                               ; preds = %20
  %23 = load ptr, ptr @optarg, align 8, !tbaa !9
  %24 = call i64 @atol(ptr noundef %23) #6
  store i64 %24, ptr %7, align 8, !tbaa !11
  br label %40

25:                                               ; preds = %20
  %26 = load ptr, ptr @optarg, align 8, !tbaa !9
  %27 = call i32 @tileset_parse(ptr noundef %11, ptr noundef %26)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %35

29:                                               ; preds = %25
  %30 = load ptr, ptr @optarg, align 8, !tbaa !9
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %30)
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds ptr, ptr %32, i64 0
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  call void @usage(ptr noundef %34)
  br label %35

35:                                               ; preds = %29, %25
  br label %40

36:                                               ; preds = %20
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = getelementptr inbounds ptr, ptr %37, i64 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  call void @usage(ptr noundef %39)
  br label %40

40:                                               ; preds = %36, %35, %22
  br label %14, !llvm.loop !13

41:                                               ; preds = %14
  %42 = call i64 @time(ptr noundef null) #5
  call void @set_seed(i64 noundef %42)
  %43 = load i32, ptr %11, align 4, !tbaa !5
  call void @make_index_aux(ptr noundef %10, i32 noundef %43)
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %53, %41
  %45 = load i64, ptr %6, align 8, !tbaa !11
  %46 = load i64, ptr %7, align 8, !tbaa !11
  %47 = icmp ult i64 %45, %46
  br i1 %47, label %48, label %56

48:                                               ; preds = %44
  call void @random_puzzle(ptr noundef %8)
  %49 = call i32 @test_puzzle(ptr noundef %10, ptr noundef %8)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  store i32 1, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %70

52:                                               ; preds = %48
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %6, align 8, !tbaa !11
  %55 = add i64 %54, 1
  store i64 %55, ptr %6, align 8, !tbaa !11
  br label %44, !llvm.loop !15

56:                                               ; preds = %44
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %66, %56
  %58 = load i64, ptr %6, align 8, !tbaa !11
  %59 = load i64, ptr %7, align 8, !tbaa !11
  %60 = icmp ult i64 %58, %59
  br i1 %60, label %61, label %69

61:                                               ; preds = %57
  call void @random_index(ptr noundef %10, ptr noundef %9)
  %62 = call i32 @test_index(ptr noundef %10, ptr noundef %9)
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  store i32 1, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %70

65:                                               ; preds = %61
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %6, align 8, !tbaa !11
  %68 = add i64 %67, 1
  store i64 %68, ptr %6, align 8, !tbaa !11
  br label %57, !llvm.loop !16

69:                                               ; preds = %57
  store i32 0, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %70

70:                                               ; preds = %69, %64, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 96, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

; 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 @__posix_getopt(i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i64 @atol(ptr noundef nonnull) #3

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

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

; Function Attrs: nounwind uwtable
declare hidden void @usage(ptr noundef) #0

declare void @set_seed(i64 noundef) #4

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #2

declare void @make_index_aux(ptr noundef, i32 noundef) #4

declare void @random_puzzle(ptr noundef) #4

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

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

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

; 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 = { 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 = { 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 #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 }
attributes #6 = { 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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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.puzzle = type { [25 x i8], [7 x i8], [25 x i8], [7 x i8] }
%struct.index = type { i32, i32, i32 }
%struct.index_aux = type { [32 x i8], [16 x i8], i32, i32, i32, i32, i32, ptr, [16 x i8] }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.puzzle, align 8
  %4 = alloca %struct.index, align 4
  %5 = alloca %struct.index_aux, align 32
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  store i32 254, ptr %6, align 4, !tbaa !5
  br label %.outer

.outer:                                           ; preds = %9, %2
  %.012.ph = phi i64 [ %11, %9 ], [ 10000, %2 ]
  br label %7

7:                                                ; preds = %.backedge, %.outer
  %8 = call i32 @__posix_getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #6
  switch i32 %8, label %19 [
    i32 -1, label %21
    i32 105, label %9
    i32 116, label %12
  ]

9:                                                ; preds = %7
  %10 = load ptr, ptr @optarg, align 8, !tbaa !9
  %11 = call i64 @atol(ptr nocapture noundef %10) #7
  br label %.outer, !llvm.loop !11

12:                                               ; preds = %7
  %13 = load ptr, ptr @optarg, align 8, !tbaa !9
  %14 = call i32 @tileset_parse(ptr noundef nonnull %6, ptr noundef %13) #6
  %.not18 = icmp eq i32 %14, 0
  br i1 %.not18, label %.backedge, label %15

.backedge:                                        ; preds = %12, %15, %19
  br label %7, !llvm.loop !11

15:                                               ; preds = %12
  %16 = load ptr, ptr @optarg, align 8, !tbaa !9
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %16)
  %18 = load ptr, ptr %1, align 8, !tbaa !9
  call void @usage(ptr noundef %18)
  br label %.backedge

19:                                               ; preds = %7
  %20 = load ptr, ptr %1, align 8, !tbaa !9
  call void @usage(ptr noundef %20)
  br label %.backedge

21:                                               ; preds = %7
  %22 = call i64 @time(ptr noundef null) #6
  call void @set_seed(i64 noundef %22) #6
  %23 = load i32, ptr %6, align 4, !tbaa !5
  call void @make_index_aux(ptr noundef nonnull %5, i32 noundef %23) #6
  %.not = icmp eq i64 %.012.ph, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

24:                                               ; preds = %.lr.ph
  %25 = add nuw i64 %.01320, 1
  %exitcond.not = icmp eq i64 %25, %.012.ph
  br i1 %exitcond.not, label %.lr.ph22, label %.lr.ph, !llvm.loop !13

.lr.ph:                                           ; preds = %21, %24
  %.01320 = phi i64 [ %25, %24 ], [ 0, %21 ]
  call void @random_puzzle(ptr noundef nonnull %3) #6
  %26 = call i32 @test_puzzle(ptr noundef nonnull %5, ptr noundef nonnull %3)
  %.not17 = icmp eq i32 %26, 0
  br i1 %.not17, label %.loopexit, label %24

27:                                               ; preds = %.lr.ph22
  %28 = add nuw i64 %.11421, 1
  %exitcond27.not = icmp eq i64 %28, %.012.ph
  br i1 %exitcond27.not, label %.loopexit, label %.lr.ph22, !llvm.loop !14

.lr.ph22:                                         ; preds = %24, %27
  %.11421 = phi i64 [ %28, %27 ], [ 0, %24 ]
  call void @random_index(ptr noundef nonnull %5, ptr noundef nonnull %4) #6
  %29 = call i32 @test_index(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %.not16 = icmp eq i32 %29, 0
  br i1 %.not16, label %.loopexit, label %27

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph22, %27, %21
  %.0 = phi i32 [ 0, %21 ], [ 1, %.lr.ph22 ], [ 0, %27 ], [ 1, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #6
  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: nounwind
declare i32 @__posix_getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i64 @atol(ptr nocapture noundef nonnull) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
declare hidden void @usage(ptr noundef) local_unnamed_addr #0

declare void @set_seed(i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #2

declare void @make_index_aux(ptr noundef, i32 noundef) local_unnamed_addr #4

declare void @random_puzzle(ptr noundef) local_unnamed_addr #4

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

declare void @random_index(ptr noundef, ptr noundef) local_unnamed_addr #4

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

; 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 = { 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 = { 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 #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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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