; LLVM IR from snowballstem/snowball :: compiler (generator)

; 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.generator = type { ptr, ptr, i32, i32, ptr, ptr, i32, i32, i32, ptr, i32, i32, i32, i32, [10 x ptr], [10 x ptr], [10 x i32], [5 x ptr], [5 x ptr], i32, i32, i32, i32, i32 }

; 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

declare void @str_append_ch(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
define dso_local void @write_newline(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %22, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.generator, ptr %6, i32 0, i32 4
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = call i32 @str_back(ptr noundef %8)
  store i32 %9, ptr %3, align 4, !tbaa !12
  %10 = load i32, ptr %3, align 4, !tbaa !12
  %11 = icmp ne i32 %10, 32
  br i1 %11, label %12, label %16

12:                                               ; preds = %5
  %13 = load i32, ptr %3, align 4, !tbaa !12
  %14 = icmp ne i32 %13, 9
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  store i32 3, ptr %4, align 4
  br label %20

16:                                               ; preds = %12, %5
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.generator, ptr %17, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  call void @str_pop(ptr noundef %19)
  store i32 0, ptr %4, align 4
  br label %20

20:                                               ; preds = %16, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %21 = load i32, ptr %4, align 4
  switch i32 %21, label %31 [
    i32 0, label %22
    i32 3, label %23
  ]

22:                                               ; preds = %20
  br label %5

23:                                               ; preds = %20
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.generator, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  call void @str_append_ch(ptr noundef %26, i8 noundef signext 10)
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.generator, ptr %27, i32 0, i32 19
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 8, !tbaa !13
  ret void

31:                                               ; preds = %20
  unreachable
}

declare i32 @str_back(ptr noundef) #1

declare void @str_pop(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 }

!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, !6, i64 24}
!10 = !{!"generator", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !6, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !7, i64 80, !7, i64 160, !7, i64 240, !7, i64 280, !7, i64 320, !11, i64 360, !11, i64 364, !11, i64 368, !11, i64 372, !11, i64 376}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 360}


; 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"

declare void @str_append_ch(ptr noundef, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @write_newline(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  br label %3

3:                                                ; preds = %6, %1
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = tail call i32 @str_back(ptr noundef %4) #2
  switch i32 %5, label %8 [
    i32 32, label %6
    i32 9, label %6
  ]

6:                                                ; preds = %3, %3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @str_pop(ptr noundef %7) #2
  br label %3

8:                                                ; preds = %3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @str_append_ch(ptr noundef %9, i8 noundef signext 10) #2
  %10 = getelementptr inbounds i8, ptr %0, i64 360
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %10, align 8, !tbaa !11
  ret void
}

declare i32 @str_back(ptr noundef) local_unnamed_addr #0

declare void @str_pop(ptr noundef) local_unnamed_addr #0

attributes #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 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 }

!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 24}
!6 = !{!"generator", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !7, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !8, i64 80, !8, i64 160, !8, i64 240, !8, i64 280, !8, i64 320, !10, i64 360, !10, i64 364, !10, i64 368, !10, i64 372, !10, i64 376}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 360}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass