; LLVM IR from aap/pdp6 :: emu (emu)

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

@tasks = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 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: nounwind uwtable
define dso_local ptr @simthread(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @threadname(ptr noundef @.str.3)
  %4 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %5

5:                                                ; preds = %36, %1
  %6 = load ptr, ptr @tasks, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %32, %5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %36

10:                                               ; preds = %7
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.Task, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Task, ptr %15, i32 0, i32 4
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Task, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = icmp eq i32 %17, %20
  br i1 %21, label %22, label %31

22:                                               ; preds = %10
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Task, ptr %23, i32 0, i32 4
  store i32 0, ptr %24, align 4, !tbaa !9
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Task, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Task, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  call void %27(ptr noundef %30)
  br label %31

31:                                               ; preds = %22, %10
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Task, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  store ptr %35, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !16

36:                                               ; preds = %7
  br label %5
}

declare void @threadname(ptr noundef) #2

declare i32 @printf(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 = { "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, !11, i64 28}
!10 = !{!"Task", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 24}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@tasks = external dso_local local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef ptr @simthread(ptr nocapture noundef readnone %0) local_unnamed_addr #0 {
  tail call void @threadname(ptr noundef nonnull @.str.3) #3
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %3 = load ptr, ptr @tasks, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.loopexit.us, label %.split

.loopexit.us:                                     ; preds = %1, %.loopexit.us
  br label %.loopexit.us

.loopexit.loopexit:                               ; preds = %16
  %.08.pre.pre = load ptr, ptr @tasks, align 8, !tbaa !5
  br label %.split.backedge

.split.backedge:                                  ; preds = %.loopexit.loopexit, %.split
  %.08.pre12.be = phi ptr [ %.08.pre.pre, %.loopexit.loopexit ], [ null, %.split ]
  br label %.split, !llvm.loop !9

.split:                                           ; preds = %1, %.split.backedge
  %.08.pre12 = phi ptr [ %.08.pre12.be, %.split.backedge ], [ %3, %1 ]
  %.not9 = icmp eq ptr %.08.pre12, null
  br i1 %.not9, label %.split.backedge, label %.lr.ph

.lr.ph:                                           ; preds = %.split, %16
  %.010 = phi ptr [ %.0, %16 ], [ %.08.pre12, %.split ]
  %5 = getelementptr inbounds i8, ptr %.010, i64 28
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr %5, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %.010, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = icmp eq i32 %7, %9
  br i1 %10, label %11, label %16

11:                                               ; preds = %.lr.ph
  store i32 0, ptr %5, align 4, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %.010, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %.010, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  tail call void %13(ptr noundef %15) #3
  br label %16

16:                                               ; preds = %.lr.ph, %11
  %.0 = load ptr, ptr %.010, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit.loopexit, label %.lr.ph, !llvm.loop !17
}

declare void @threadname(ptr noundef) local_unnamed_addr #1

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

attributes #0 = { noreturn 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 = { "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 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unswitch.partial.disable"}
!11 = !{!12, !13, i64 28}
!12 = !{!"Task", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 24}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass