; LLVM IR from asllop/AppOS :: app (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"

@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 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

declare ptr @core_malloc(i64 noundef) #1

declare void @console_put_string(i8 noundef zeroext, ptr noundef, i32 noundef, i32 noundef) #1

declare ptr @itoa(i64 noundef, ptr noundef, i32 noundef) #1

declare void @core_free(ptr noundef) #1

; 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
declare dso_local void @cnt0_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @cnt1_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @cnt2_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @event_receiver_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @showUsedMem() #2

; Function Attrs: nounwind uwtable
define dso_local void @main(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca [20 x i8], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 20, ptr %5) #3
  call void @console_put_data(i32 noundef 27, i8 noundef signext -80, i32 noundef 2000, i32 noundef 0)
  %10 = call i32 @core_create(ptr noundef @cnt0_task, i32 noundef 0, i64 noundef 1024)
  %11 = call i32 @core_create(ptr noundef @cnt1_task, i32 noundef 2, i64 noundef 1024)
  %12 = call i32 @core_create(ptr noundef @cnt2_task, i32 noundef 5, i64 noundef 1024)
  %13 = call i32 @core_create(ptr noundef @event_receiver_task, i32 noundef 0, i64 noundef 1024)
  call void @console_put_string(i8 noundef zeroext 79, ptr noundef @.str.4, i32 noundef 34, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 5, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %47, %2
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = load i32, ptr %6, align 4, !tbaa !5
  call void @console_put_string(i8 noundef zeroext 79, ptr noundef @.str, i32 noundef 2, i32 noundef %18)
  br label %19

19:                                               ; preds = %17, %14
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [20 x i8], ptr %5, i64 0, i64 0
  %23 = call ptr @itoa(i64 noundef %21, ptr noundef %22, i32 noundef 10)
  %24 = load i32, ptr %6, align 4, !tbaa !5
  call void @console_put_string(i8 noundef zeroext 79, ptr noundef %23, i32 noundef 2, i32 noundef %24)
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = urem i32 %25, 100
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %46

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 8, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %29 = load i64, ptr %8, align 8, !tbaa !11
  %30 = call ptr @core_malloc(i64 noundef %29)
  store ptr %30, ptr %9, align 8, !tbaa !9
  %31 = load ptr, ptr %9, align 8, !tbaa !9
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  br label %45

34:                                               ; preds = %28
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = zext i32 %35 to i64
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 %36, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = load i64, ptr %8, align 8, !tbaa !11
  %40 = call i32 @event_produce(i8 noundef zeroext 0, ptr noundef %38, i64 noundef %39)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %34
  %43 = load ptr, ptr %9, align 8, !tbaa !9
  call void @core_free(ptr noundef %43)
  br label %44

44:                                               ; preds = %42, %34
  br label %45

45:                                               ; preds = %44, %33
  call void @showUsedMem()
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %46

46:                                               ; preds = %45, %19
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = add i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !5
  br label %14
}

declare void @console_put_data(i32 noundef, i8 noundef signext, i32 noundef, i32 noundef) #1

declare i32 @core_create(ptr noundef, i32 noundef, i64 noundef) #1

declare i32 @event_produce(i8 noundef zeroext, ptr noundef, i64 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 = !{!"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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}


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

@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1

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

declare ptr @core_malloc(i64 noundef) local_unnamed_addr #1

declare void @console_put_string(i8 noundef zeroext, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare ptr @itoa(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @core_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @cnt0_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @cnt1_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @cnt2_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @event_receiver_task() #2

; Function Attrs: nounwind uwtable
declare dso_local void @showUsedMem() local_unnamed_addr #2

; Function Attrs: noreturn nounwind uwtable
define dso_local void @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #3 {
  %3 = alloca [20 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %3) #4
  tail call void @console_put_data(i32 noundef 27, i8 noundef signext -80, i32 noundef 2000, i32 noundef 0) #4
  %4 = tail call i32 @core_create(ptr noundef nonnull @cnt0_task, i32 noundef 0, i64 noundef 1024) #4
  %5 = tail call i32 @core_create(ptr noundef nonnull @cnt1_task, i32 noundef 2, i64 noundef 1024) #4
  %6 = tail call i32 @core_create(ptr noundef nonnull @cnt2_task, i32 noundef 5, i64 noundef 1024) #4
  %7 = tail call i32 @core_create(ptr noundef nonnull @event_receiver_task, i32 noundef 0, i64 noundef 1024) #4
  tail call void @console_put_string(i8 noundef zeroext 79, ptr noundef nonnull @.str.4, i32 noundef 34, i32 noundef 1) #4
  br label %8

8:                                                ; preds = %22, %2
  %.0 = phi i32 [ 0, %2 ], [ %23, %22 ]
  %9 = icmp eq i32 %.0, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  call void @console_put_string(i8 noundef zeroext 79, ptr noundef nonnull @.str, i32 noundef 2, i32 noundef 5) #4
  br label %11

11:                                               ; preds = %10, %8
  %12 = zext i32 %.0 to i64
  %13 = call ptr @itoa(i64 noundef %12, ptr noundef nonnull %3, i32 noundef 10) #4
  call void @console_put_string(i8 noundef zeroext 79, ptr noundef %13, i32 noundef 2, i32 noundef 5) #4
  %14 = urem i32 %.0, 100
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %22

16:                                               ; preds = %11
  %17 = call ptr @core_malloc(i64 noundef 8) #4
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %21, label %18

18:                                               ; preds = %16
  store i64 %12, ptr %17, align 8, !tbaa !5
  %19 = call i32 @event_produce(i8 noundef zeroext 0, ptr noundef nonnull %17, i64 noundef 8) #4
  %.not13 = icmp eq i32 %19, 0
  br i1 %.not13, label %21, label %20

20:                                               ; preds = %18
  call void @core_free(ptr noundef nonnull %17) #4
  br label %21

21:                                               ; preds = %18, %20, %16
  call void @showUsedMem()
  br label %22

22:                                               ; preds = %11, %21
  %23 = add i32 %.0, 1
  br label %8
}

declare void @console_put_data(i32 noundef, i8 noundef signext, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @core_create(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

declare i32 @event_produce(i8 noundef zeroext, ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { 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 #4 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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