; LLVM IR from PaulBatchelor/sndkit :: worgle (parg)

; 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.parg_state = type { ptr, i32, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__.parg_reorder = external hidden unnamed_addr constant [73 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @parg_init(ptr noundef) #0

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @parg_reorder(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.parg_state, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  br label %19

18:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 322, ptr noundef @__PRETTY_FUNCTION__.parg_reorder) #4
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  br label %24

23:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 323, ptr noundef @__PRETTY_FUNCTION__.parg_reorder) #4
  unreachable

24:                                               ; preds = %22
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 2
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %28 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %28, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %77

29:                                               ; preds = %24
  call void @parg_init(ptr noundef %10)
  br label %30

30:                                               ; preds = %53, %29
  %31 = getelementptr inbounds %struct.parg_state, ptr %10, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !11
  store i32 %32, ptr %11, align 4, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  %37 = call i32 @parg_getopt_long(ptr noundef %10, i32 noundef %33, ptr noundef %34, ptr noundef %35, ptr noundef %36, ptr noundef null)
  store i32 %37, ptr %13, align 4, !tbaa !5
  %38 = load i32, ptr %13, align 4, !tbaa !5
  %39 = icmp eq i32 %38, 63
  br i1 %39, label %43, label %40

40:                                               ; preds = %30
  %41 = load i32, ptr %13, align 4, !tbaa !5
  %42 = icmp eq i32 %41, 58
  br i1 %42, label %43, label %52

43:                                               ; preds = %40, %30
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = call i32 @is_argv_end(ptr noundef %10, i32 noundef %44, ptr noundef %45)
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %52

48:                                               ; preds = %43
  %49 = getelementptr inbounds %struct.parg_state, ptr %10, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !11
  %51 = sub nsw i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !5
  br label %56

52:                                               ; preds = %43, %40
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %13, align 4, !tbaa !5
  %55 = icmp ne i32 %54, -1
  br i1 %55, label %30, label %56, !llvm.loop !13

56:                                               ; preds = %53, %48
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = load ptr, ptr %9, align 8, !tbaa !9
  %61 = call i32 @parg_reorder_simple(i32 noundef %57, ptr noundef %58, ptr noundef %59, ptr noundef %60)
  store i32 %61, ptr %12, align 4, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %65, label %75

65:                                               ; preds = %56
  %66 = load ptr, ptr %7, align 8, !tbaa !9
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = load i32, ptr %11, align 4, !tbaa !5
  call void @reverse(ptr noundef %66, i32 noundef %67, i32 noundef %68)
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = load i32, ptr %12, align 4, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  call void @reverse(ptr noundef %69, i32 noundef %70, i32 noundef %72)
  %73 = load i32, ptr %12, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %12, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %65, %56
  %76 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %76, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %77

77:                                               ; preds = %75, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #3
  %78 = load i32, ptr %5, align 4
  ret i32 %78
}

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

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

; Function Attrs: nounwind uwtable
declare hidden void @reverse(ptr 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) #2

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { 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, !6, i64 8}
!12 = !{!"parg_state", !10, i64 0, !6, i64 8, !6, i64 12, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct.parg_state = type { ptr, i32, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__.parg_reorder = external hidden unnamed_addr constant [73 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @parg_reorder(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.parg_state, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %6, label %7

6:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 322, ptr noundef nonnull @__PRETTY_FUNCTION__.parg_reorder) #4
  unreachable

7:                                                ; preds = %4
  %.not33 = icmp eq ptr %2, null
  br i1 %.not33, label %8, label %9

8:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 323, ptr noundef nonnull @__PRETTY_FUNCTION__.parg_reorder) #4
  unreachable

9:                                                ; preds = %7
  %10 = icmp slt i32 %0, 2
  br i1 %10, label %25, label %11

11:                                               ; preds = %9
  call void @parg_init(ptr noundef nonnull %5)
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  br label %.backedge

.backedge:                                        ; preds = %.backedge.backedge, %11
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = call i32 @parg_getopt_long(ptr noundef nonnull %5, i32 noundef %0, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef %3, ptr noundef null)
  switch i32 %14, label %.backedge.backedge [
    i32 63, label %15
    i32 58, label %15
    i32 -1, label %.loopexit
  ]

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

15:                                               ; preds = %.backedge, %.backedge
  %16 = call i32 @is_argv_end(ptr noundef nonnull %5, i32 noundef %0, ptr noundef nonnull %1)
  %.not34 = icmp eq i32 %16, 0
  br i1 %.not34, label %.backedge.backedge, label %17

17:                                               ; preds = %15
  %18 = load i32, ptr %12, align 8, !tbaa !5
  %19 = add nsw i32 %18, -1
  br label %.loopexit

.loopexit:                                        ; preds = %.backedge, %17
  %.029 = phi i32 [ %19, %17 ], [ %13, %.backedge ]
  %20 = call i32 @parg_reorder_simple(i32 noundef %.029, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef %3)
  %21 = icmp slt i32 %.029, %0
  br i1 %21, label %22, label %25

22:                                               ; preds = %.loopexit
  call void @reverse(ptr noundef nonnull %1, i32 noundef %20, i32 noundef %.029)
  %23 = add nsw i32 %.029, 1
  call void @reverse(ptr noundef nonnull %1, i32 noundef %20, i32 noundef %23)
  %24 = add nsw i32 %20, 1
  br label %25

25:                                               ; preds = %.loopexit, %22, %9
  %.0 = phi i32 [ %0, %9 ], [ %24, %22 ], [ %20, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  ret i32 %.0
}

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

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

; Function Attrs: nounwind uwtable
declare hidden void @reverse(ptr noundef, i32 noundef, i32 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) #2

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { 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, !10, i64 8}
!6 = !{!"parg_state", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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