; LLVM IR from DanEngelbrecht/longtail :: cmd (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.anon = type { i32, [256 x %struct._kgflags_flag], i32, [512 x ptr], i32, [512 x %struct._kgflags_error], ptr, i32, i32, ptr, ptr }
%struct._kgflags_flag = type { ptr, ptr, %union.anon, %union.anon.0, i8, i8, i8, i32 }
%union.anon = type { ptr }
%union.anon.0 = type { ptr }
%struct._kgflags_error = type { ptr, ptr, i32 }

@_kgflags_g = external hidden global %struct.anon, align 8
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [53 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @kgflags_print_errors() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %85, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 4), align 8, !tbaa !9
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %88

8:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [512 x %struct._kgflags_error], ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 5), i64 0, i64 %10
  store ptr %11, ptr %2, align 8, !tbaa !12
  %12 = load ptr, ptr %2, align 8, !tbaa !12
  %13 = getelementptr inbounds %struct._kgflags_error, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 8, !tbaa !13
  switch i32 %14, label %83 [
    i32 1, label %15
    i32 2, label %22
    i32 3, label %29
    i32 4, label %36
    i32 5, label %46
    i32 6, label %56
    i32 7, label %59
    i32 8, label %62
    i32 9, label %69
    i32 10, label %76
  ]

15:                                               ; preds = %8
  %16 = load ptr, ptr @stderr, align 8, !tbaa !12
  %17 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %18 = load ptr, ptr %2, align 8, !tbaa !12
  %19 = getelementptr inbounds %struct._kgflags_error, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.2, ptr noundef %17, ptr noundef %20) #3
  br label %84

22:                                               ; preds = %8
  %23 = load ptr, ptr @stderr, align 8, !tbaa !12
  %24 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %25 = load ptr, ptr %2, align 8, !tbaa !12
  %26 = getelementptr inbounds %struct._kgflags_error, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.3, ptr noundef %24, ptr noundef %27) #3
  br label %84

29:                                               ; preds = %8
  %30 = load ptr, ptr @stderr, align 8, !tbaa !12
  %31 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %32 = load ptr, ptr %2, align 8, !tbaa !12
  %33 = getelementptr inbounds %struct._kgflags_error, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.4, ptr noundef %31, ptr noundef %34) #3
  br label %84

36:                                               ; preds = %8
  %37 = load ptr, ptr @stderr, align 8, !tbaa !12
  %38 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %39 = load ptr, ptr %2, align 8, !tbaa !12
  %40 = getelementptr inbounds %struct._kgflags_error, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = load ptr, ptr %2, align 8, !tbaa !12
  %43 = getelementptr inbounds %struct._kgflags_error, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str.5, ptr noundef %38, ptr noundef %41, ptr noundef %44) #3
  br label %84

46:                                               ; preds = %8
  %47 = load ptr, ptr @stderr, align 8, !tbaa !12
  %48 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %49 = load ptr, ptr %2, align 8, !tbaa !12
  %50 = getelementptr inbounds %struct._kgflags_error, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load ptr, ptr %2, align 8, !tbaa !12
  %53 = getelementptr inbounds %struct._kgflags_error, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str.6, ptr noundef %48, ptr noundef %51, ptr noundef %54) #3
  br label %84

56:                                               ; preds = %8
  %57 = load ptr, ptr @stderr, align 8, !tbaa !12
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str.7) #3
  br label %84

59:                                               ; preds = %8
  %60 = load ptr, ptr @stderr, align 8, !tbaa !12
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.8) #3
  br label %84

62:                                               ; preds = %8
  %63 = load ptr, ptr @stderr, align 8, !tbaa !12
  %64 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %65 = load ptr, ptr %2, align 8, !tbaa !12
  %66 = getelementptr inbounds %struct._kgflags_error, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %63, ptr noundef @.str.9, ptr noundef %64, ptr noundef %67) #3
  br label %84

69:                                               ; preds = %8
  %70 = load ptr, ptr @stderr, align 8, !tbaa !12
  %71 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %72 = load ptr, ptr %2, align 8, !tbaa !12
  %73 = getelementptr inbounds %struct._kgflags_error, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !16
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.10, ptr noundef %71, ptr noundef %74) #3
  br label %84

76:                                               ; preds = %8
  %77 = load ptr, ptr @stderr, align 8, !tbaa !12
  %78 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @_kgflags_g, i32 0, i32 6), align 8, !tbaa !15
  %79 = load ptr, ptr %2, align 8, !tbaa !12
  %80 = getelementptr inbounds %struct._kgflags_error, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !16
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef @.str.11, ptr noundef %78, ptr noundef %81) #3
  br label %84

83:                                               ; preds = %8
  br label %84

84:                                               ; preds = %83, %76, %69, %62, %59, %56, %46, %36, %29, %22, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %1, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !18

88:                                               ; preds = %7
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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, !6, i64 14352}
!10 = !{!"", !6, i64 0, !7, i64 8, !6, i64 10248, !7, i64 10256, !6, i64 14352, !7, i64 14360, !11, i64 26648, !6, i64 26656, !6, i64 26660, !11, i64 26664, !11, i64 26672}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_kgflags_error", !11, i64 0, !11, i64 8, !6, i64 16}
!15 = !{!10, !11, i64 26648}
!16 = !{!14, !11, i64 0}
!17 = !{!14, !11, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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.anon = type { i32, [256 x %struct._kgflags_flag], i32, [512 x ptr], i32, [512 x %struct._kgflags_error], ptr, i32, i32, ptr, ptr }
%struct._kgflags_flag = type { ptr, ptr, %union.anon, %union.anon.0, i8, i8, i8, i32 }
%union.anon = type { ptr }
%union.anon.0 = type { ptr }
%struct._kgflags_error = type { ptr, ptr, i32 }

@_kgflags_g = external hidden local_unnamed_addr global %struct.anon, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @kgflags_print_errors() local_unnamed_addr #0 {
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 14352), align 8, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %56, %0
  ret void

.lr.ph:                                           ; preds = %0, %56
  %indvars.iv = phi i64 [ %indvars.iv.next, %56 ], [ 0, %0 ]
  %3 = getelementptr inbounds [512 x %struct._kgflags_error], ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 14360), i64 0, i64 %indvars.iv
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !11
  switch i32 %5, label %56 [
    i32 1, label %6
    i32 2, label %11
    i32 3, label %16
    i32 4, label %21
    i32 5, label %28
    i32 6, label %35
    i32 7, label %38
    i32 8, label %41
    i32 9, label %46
    i32 10, label %51
  ]

6:                                                ; preds = %.lr.ph
  %7 = load ptr, ptr @stderr, align 8, !tbaa !13
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %9 = load ptr, ptr %3, align 8, !tbaa !15
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.2, ptr noundef %8, ptr noundef %9) #2
  br label %56

11:                                               ; preds = %.lr.ph
  %12 = load ptr, ptr @stderr, align 8, !tbaa !13
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %14 = load ptr, ptr %3, align 8, !tbaa !15
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.3, ptr noundef %13, ptr noundef %14) #2
  br label %56

16:                                               ; preds = %.lr.ph
  %17 = load ptr, ptr @stderr, align 8, !tbaa !13
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %19 = load ptr, ptr %3, align 8, !tbaa !15
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.4, ptr noundef %18, ptr noundef %19) #2
  br label %56

21:                                               ; preds = %.lr.ph
  %22 = load ptr, ptr @stderr, align 8, !tbaa !13
  %23 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %24 = load ptr, ptr %3, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %3, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.5, ptr noundef %23, ptr noundef %24, ptr noundef %26) #2
  br label %56

28:                                               ; preds = %.lr.ph
  %29 = load ptr, ptr @stderr, align 8, !tbaa !13
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %31 = load ptr, ptr %3, align 8, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %3, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.6, ptr noundef %30, ptr noundef %31, ptr noundef %33) #2
  br label %56

35:                                               ; preds = %.lr.ph
  %36 = load ptr, ptr @stderr, align 8, !tbaa !13
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.7) #2
  br label %56

38:                                               ; preds = %.lr.ph
  %39 = load ptr, ptr @stderr, align 8, !tbaa !13
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str.8) #2
  br label %56

41:                                               ; preds = %.lr.ph
  %42 = load ptr, ptr @stderr, align 8, !tbaa !13
  %43 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %44 = load ptr, ptr %3, align 8, !tbaa !15
  %45 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull @.str.9, ptr noundef %43, ptr noundef %44) #2
  br label %56

46:                                               ; preds = %.lr.ph
  %47 = load ptr, ptr @stderr, align 8, !tbaa !13
  %48 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %49 = load ptr, ptr %3, align 8, !tbaa !15
  %50 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.10, ptr noundef %48, ptr noundef %49) #2
  br label %56

51:                                               ; preds = %.lr.ph
  %52 = load ptr, ptr @stderr, align 8, !tbaa !13
  %53 = load ptr, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 26648), align 8, !tbaa !14
  %54 = load ptr, ptr %3, align 8, !tbaa !15
  %55 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef nonnull @.str.11, ptr noundef %53, ptr noundef %54) #2
  br label %56

56:                                               ; preds = %.lr.ph, %51, %46, %41, %38, %35, %28, %21, %16, %11, %6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %57 = load i32, ptr getelementptr inbounds (i8, ptr @_kgflags_g, i64 14352), align 8, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = icmp slt i64 %indvars.iv.next, %58
  br i1 %59, label %.lr.ph, label %._crit_edge, !llvm.loop !17
}

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

attributes #0 = { nofree 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 = { 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 #2 = { cold 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 14352}
!6 = !{!"", !7, i64 0, !8, i64 8, !7, i64 10248, !8, i64 10256, !7, i64 14352, !8, i64 14360, !10, i64 26648, !7, i64 26656, !7, i64 26660, !10, i64 26664, !10, i64 26672}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 16}
!12 = !{!"_kgflags_error", !10, i64 0, !10, i64 8, !7, i64 16}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 26648}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass