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

; 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 [4 x i8], align 1
@optind = external global i32, align 4

; 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 i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = 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 4, ptr %6) #4
  store i32 6, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %26, %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = call i32 @__posix_getopt(i32 noundef %12, ptr noundef %13, ptr noundef @.str) #4
  store i32 %14, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = icmp ne i32 %15, -1
  br i1 %16, label %17, label %27

17:                                               ; preds = %11
  %18 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %18, label %26 [
    i32 97, label %19
    i32 122, label %20
    i32 112, label %21
    i32 58, label %22
    i32 63, label %22
  ]

19:                                               ; preds = %17
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %26

20:                                               ; preds = %17
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %26

21:                                               ; preds = %17
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %26

22:                                               ; preds = %17, %17
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds ptr, ptr %23, i64 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  call void @usage(ptr noundef %25)
  br label %26

26:                                               ; preds = %22, %21, %20, %19, %17
  br label %11, !llvm.loop !11

27:                                               ; preds = %11
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr @optind, align 4, !tbaa !5
  %30 = sub nsw i32 %28, %29
  switch i32 %30, label %38 [
    i32 0, label %42
    i32 1, label %31
  ]

31:                                               ; preds = %27
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load i32, ptr @optind, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %32, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = call i32 @atoi(ptr noundef %36) #5
  store i32 %37, ptr %6, align 4, !tbaa !5
  br label %42

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

42:                                               ; preds = %38, %31, %27
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !5
  call void @count_pdbs(i32 noundef %46, i32 noundef 0, i32 noundef %47)
  br label %48

48:                                               ; preds = %45, %42
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  call void @count_pdbs(i32 noundef %52, i32 noundef 1, i32 noundef %53)
  br label %54

54:                                               ; preds = %51, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret i32 0
}

; 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: nounwind uwtable
declare hidden void @usage(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @count_pdbs(i32 noundef, i32 noundef, i32 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 = { nounwind }
attributes #5 = { 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"}


; 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 [4 x i8], align 1
@optind = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  br label %.outer

.outer:                                           ; preds = %6, %2
  %.015.ph = phi i32 [ 1, %6 ], [ 0, %2 ]
  %.013.ph = phi i32 [ %.013.ph22, %6 ], [ 1, %2 ]
  %.0.ph = phi i32 [ %.0.ph25, %6 ], [ 1, %2 ]
  br label %.outer21

.outer21:                                         ; preds = %.outer, %5
  %.013.ph22 = phi i32 [ %.013.ph, %.outer ], [ 0, %5 ]
  %.0.ph23 = phi i32 [ %.0.ph, %.outer ], [ %.0.ph25, %5 ]
  br label %.outer24

.outer24:                                         ; preds = %3, %.outer21
  %.0.ph25 = phi i32 [ %.0.ph23, %.outer21 ], [ 0, %3 ]
  br label %3

3:                                                ; preds = %.backedge, %.outer24
  %4 = tail call i32 @__posix_getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #3
  switch i32 %4, label %.backedge [
    i32 -1, label %9
    i32 97, label %.outer24
    i32 122, label %5
    i32 112, label %6
    i32 58, label %7
    i32 63, label %7
  ], !llvm.loop !5

.backedge:                                        ; preds = %3, %7
  br label %3, !llvm.loop !5

5:                                                ; preds = %3
  br label %.outer21, !llvm.loop !5

6:                                                ; preds = %3
  br label %.outer, !llvm.loop !5

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

9:                                                ; preds = %3
  %10 = load i32, ptr @optind, align 4, !tbaa !11
  %11 = sub nsw i32 %0, %10
  switch i32 %11, label %17 [
    i32 0, label %19
    i32 1, label %12
  ]

12:                                               ; preds = %9
  %13 = sext i32 %10 to i64
  %14 = getelementptr inbounds ptr, ptr %1, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !7
  %16 = tail call i32 @atoi(ptr nocapture noundef %15) #4
  br label %19

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

19:                                               ; preds = %17, %12, %9
  %.017 = phi i32 [ 6, %17 ], [ %16, %12 ], [ 6, %9 ]
  %.not19 = icmp eq i32 %.013.ph22, 0
  br i1 %.not19, label %21, label %20

20:                                               ; preds = %19
  tail call void @count_pdbs(i32 noundef %.017, i32 noundef 0, i32 noundef %.015.ph)
  br label %21

21:                                               ; preds = %20, %19
  %.not20 = icmp eq i32 %.0.ph25, 0
  br i1 %.not20, label %23, label %22

22:                                               ; preds = %21
  tail call void @count_pdbs(i32 noundef %.017, i32 noundef 1, i32 noundef %.015.ph)
  br label %23

23:                                               ; preds = %22, %21
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @__posix_getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #2

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

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 = { 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 #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 = { nounwind }
attributes #4 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass