; LLVM IR from Aeternum-Veritas/Merry :: merry (merry)

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

@stdout = external global ptr, align 8
@.str = external hidden unnamed_addr constant [49 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @merry_parse_options(i32 noundef %0, ptr noundef %1, i8 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.MerryStateMachine, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i8 %2, ptr %7, align 1, !tbaa !11
  %11 = load ptr, ptr @stdout, align 8, !tbaa !9
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef @.str, ptr noundef null) #5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 2
  br i1 %14, label %15, label %18

15:                                               ; preds = %3
  %16 = load ptr, ptr @stderr, align 8, !tbaa !9
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.1) #5
  store ptr null, ptr %4, align 8
  br label %71

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %19 = call noalias ptr @malloc(i64 noundef 64) #6
  store ptr %19, ptr %8, align 8, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %25, label %22

22:                                               ; preds = %18
  %23 = load ptr, ptr @stderr, align 8, !tbaa !9
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.2) #5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %70

25:                                               ; preds = %18
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 8 %26, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #5
  %27 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 0, ptr %27, align 8, !tbaa !12
  %28 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 1
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %29, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 2
  %31 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %31, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 3
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %33, ptr %32, align 8, !tbaa !16
  %34 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 4
  store i32 1, ptr %34, align 8, !tbaa !17
  %35 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 5
  %36 = load i8, ptr %7, align 1, !tbaa !11
  store i8 %36, ptr %35, align 4, !tbaa !18
  br label %37

37:                                               ; preds = %67, %25
  %38 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !12
  %40 = icmp ne i32 %39, 8
  br i1 %40, label %41, label %68

41:                                               ; preds = %37
  %42 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !12
  switch i32 %43, label %65 [
    i32 0, label %44
    i32 1, label %47
    i32 2, label %50
    i32 3, label %53
    i32 4, label %56
    i32 5, label %59
    i32 7, label %62
  ]

44:                                               ; preds = %41
  %45 = call i32 @handle_start(ptr noundef %10)
  %46 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 %45, ptr %46, align 8, !tbaa !12
  br label %67

47:                                               ; preds = %41
  %48 = call i32 @handle_help(ptr noundef %10)
  %49 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 %48, ptr %49, align 8, !tbaa !12
  br label %67

50:                                               ; preds = %41
  %51 = call i32 @handle_version(ptr noundef %10)
  %52 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 %51, ptr %52, align 8, !tbaa !12
  br label %67

53:                                               ; preds = %41
  %54 = call i32 @handle_input_file(ptr noundef %10)
  %55 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 %54, ptr %55, align 8, !tbaa !12
  br label %67

56:                                               ; preds = %41
  %57 = call i32 @handle_dump_file(ptr noundef %10)
  %58 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 %57, ptr %58, align 8, !tbaa !12
  br label %67

59:                                               ; preds = %41
  %60 = call i32 @handle_freeze(ptr noundef %10)
  %61 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 %60, ptr %61, align 8, !tbaa !12
  br label %67

62:                                               ; preds = %41
  %63 = call i32 @handle_unknown(ptr noundef %10)
  %64 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 %63, ptr %64, align 8, !tbaa !12
  br label %67

65:                                               ; preds = %41
  %66 = getelementptr inbounds %struct.MerryStateMachine, ptr %10, i32 0, i32 0
  store i32 8, ptr %66, align 8, !tbaa !12
  br label %67

67:                                               ; preds = %65, %62, %59, %56, %53, %50, %47, %44
  br label %37, !llvm.loop !19

68:                                               ; preds = %37
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %69, ptr %4, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #5
  br label %70

70:                                               ; preds = %68, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %71

71:                                               ; preds = %70, %15
  %72 = load ptr, ptr %4, align 8
  ret ptr %72
}

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @handle_unknown(ptr 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 = { 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 allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"MerryStateMachine", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !7, i64 36}
!14 = !{!13, !10, i64 8}
!15 = !{!13, !6, i64 16}
!16 = !{!13, !10, i64 24}
!17 = !{!13, !6, i64 32}
!18 = !{!13, !7, i64 36}
!19 = distinct !{!19, !20}
!20 = !{!"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.MerryStateMachine = type { i32, ptr, i32, ptr, i32, i8 }

@stdout = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [49 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @merry_parse_options(i32 noundef %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca %struct.MerryStateMachine, align 8
  %5 = load ptr, ptr @stdout, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef null) #4
  %7 = icmp slt i32 %0, 2
  br i1 %7, label %8, label %11

8:                                                ; preds = %3
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.1) #5
  br label %39

11:                                               ; preds = %3
  %calloc = tail call dereferenceable_or_null(64) ptr @calloc(i64 1, i64 64)
  %.not = icmp eq ptr %calloc, null
  br i1 %.not, label %12, label %15

12:                                               ; preds = %11
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.2) #5
  br label %39

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #4
  store i32 0, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %calloc, ptr %16, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 %0, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %1, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 1, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %4, i64 36
  store i8 %2, ptr %20, align 4, !tbaa !16
  br label %21

21:                                               ; preds = %.backedge, %15
  %22 = phi i32 [ 0, %15 ], [ %.be, %.backedge ]
  switch i32 %22, label %37 [
    i32 8, label %38
    i32 0, label %23
    i32 1, label %25
    i32 2, label %27
    i32 3, label %29
    i32 4, label %31
    i32 5, label %33
    i32 7, label %35
  ]

23:                                               ; preds = %21
  %24 = call i32 @handle_start(ptr noundef nonnull %4)
  store i32 %24, ptr %4, align 8, !tbaa !9
  br label %.backedge

25:                                               ; preds = %21
  %26 = call i32 @handle_help(ptr noundef nonnull %4)
  store i32 %26, ptr %4, align 8, !tbaa !9
  br label %.backedge

27:                                               ; preds = %21
  %28 = call i32 @handle_version(ptr noundef nonnull %4)
  store i32 %28, ptr %4, align 8, !tbaa !9
  br label %.backedge

29:                                               ; preds = %21
  %30 = call i32 @handle_input_file(ptr noundef nonnull %4)
  store i32 %30, ptr %4, align 8, !tbaa !9
  br label %.backedge

31:                                               ; preds = %21
  %32 = call i32 @handle_dump_file(ptr noundef nonnull %4)
  store i32 %32, ptr %4, align 8, !tbaa !9
  br label %.backedge

33:                                               ; preds = %21
  %34 = call i32 @handle_freeze(ptr noundef nonnull %4)
  store i32 %34, ptr %4, align 8, !tbaa !9
  br label %.backedge

35:                                               ; preds = %21
  %36 = call i32 @handle_unknown(ptr noundef nonnull %4)
  store i32 %36, ptr %4, align 8, !tbaa !9
  br label %.backedge

37:                                               ; preds = %21
  store i32 8, ptr %4, align 8, !tbaa !9
  br label %.backedge

.backedge:                                        ; preds = %37, %35, %33, %31, %29, %27, %25, %23
  %.be = phi i32 [ 8, %37 ], [ %36, %35 ], [ %34, %33 ], [ %32, %31 ], [ %30, %29 ], [ %28, %27 ], [ %26, %25 ], [ %24, %23 ]
  br label %21, !llvm.loop !17

38:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #4
  br label %39

39:                                               ; preds = %12, %38, %8
  %.1 = phi ptr [ null, %8 ], [ %calloc, %38 ], [ null, %12 ]
  ret ptr %.1
}

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

; 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 @handle_start(ptr noundef) local_unnamed_addr #0

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

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

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

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

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

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

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #4 = { nounwind }
attributes #5 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"MerryStateMachine", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !7, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !11, i64 32}
!16 = !{!10, !7, i64 36}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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