; LLVM IR from freakout42/macrocalc :: arx/src (cur_syst)

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

@cur_redir = external global i32, align 4
@std_err = external global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @cur_syst(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  call void @cur_rest()
  %10 = call i32 @fork() #6
  store i32 %10, ptr %7, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %39

12:                                               ; preds = %3
  %13 = load i32, ptr @cur_redir, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 3
  br i1 %14, label %15, label %23

15:                                               ; preds = %12
  %16 = call i32 @close(i32 noundef 2)
  %17 = load ptr, ptr @std_err, align 8, !tbaa !5
  %18 = call i32 @fileno(ptr noundef %17) #6
  %19 = call i32 @dup(i32 noundef %18) #6
  %20 = icmp ne i32 %19, 2
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  call void @exit(i32 noundef 126) #7
  unreachable

22:                                               ; preds = %15
  br label %23

23:                                               ; preds = %22, %12
  store i32 3, ptr %8, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %30, %23
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 16
  br i1 %26, label %27, label %33

27:                                               ; preds = %24
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = call i32 @close(i32 noundef %28)
  br label %30

30:                                               ; preds = %27
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %8, align 4, !tbaa !9
  br label %24, !llvm.loop !11

33:                                               ; preds = %24
  %34 = call ptr @signal(i32 noundef 2, ptr noundef null) #6
  %35 = call ptr @signal(i32 noundef 3, ptr noundef null) #6
  %36 = call ptr @signal(i32 noundef 13, ptr noundef null) #6
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @execl(ptr noundef @.str, ptr noundef @.str.1, ptr noundef @.str.2, ptr noundef %37, ptr noundef null) #6
  call void @exit(i32 noundef 127) #7
  unreachable

39:                                               ; preds = %3
  br label %40

40:                                               ; preds = %53, %39
  %41 = call i32 @wait(ptr noundef %9)
  store i32 %41, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = icmp ne i32 %41, %42
  br i1 %43, label %44, label %51

44:                                               ; preds = %40
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = icmp ne i32 %45, -1
  br i1 %46, label %47, label %51

47:                                               ; preds = %44
  %48 = call ptr @__errno_location() #8
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 4
  br label %51

51:                                               ; preds = %47, %44, %40
  %52 = phi i1 [ false, %44 ], [ false, %40 ], [ %50, %47 ]
  br i1 %52, label %53, label %54

53:                                               ; preds = %51
  br label %40, !llvm.loop !13

54:                                               ; preds = %51
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = icmp eq i32 %55, -1
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  store i32 -1, ptr %9, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %57, %54
  call void @cur_goll()
  call void @cur_fixt()
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %65

61:                                               ; preds = %58
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call i32 @cur_getp(ptr noundef %63)
  br label %65

65:                                               ; preds = %61, %58
  %66 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  ret i32 %66
}

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

declare void @cur_rest() #2

; Function Attrs: nounwind
declare i32 @fork() #3

declare i32 @close(i32 noundef) #2

; Function Attrs: nounwind
declare i32 @dup(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @fileno(ptr noundef) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; Function Attrs: nounwind
declare ptr @signal(i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @execl(ptr noundef, ptr noundef, ...) #3

declare i32 @wait(ptr noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #5

declare void @cur_goll() #2

declare void @cur_fixt() #2

declare i32 @printf(ptr noundef, ...) #2

declare i32 @cur_getp(ptr noundef) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { noreturn 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 #5 = { nounwind willreturn memory(none) "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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind willreturn memory(none) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@cur_redir = external local_unnamed_addr global i32, align 4
@std_err = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @cur_syst(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  tail call void @cur_rest() #7
  %5 = tail call i32 @fork() #7
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %.preheader

7:                                                ; preds = %3
  %8 = load i32, ptr @cur_redir, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 2
  br i1 %9, label %10, label %16

10:                                               ; preds = %7
  %11 = tail call i32 @close(i32 noundef 2) #7
  %12 = load ptr, ptr @std_err, align 8, !tbaa !9
  %13 = tail call i32 @fileno(ptr noundef %12) #7
  %14 = tail call i32 @dup(i32 noundef %13) #7
  %.not10 = icmp eq i32 %14, 2
  br i1 %.not10, label %16, label %15

15:                                               ; preds = %10
  tail call void @exit(i32 noundef 126) #8
  unreachable

16:                                               ; preds = %10, %7
  %17 = tail call i32 @close(i32 noundef 3) #7
  %18 = tail call i32 @close(i32 noundef 4) #7
  %19 = tail call i32 @close(i32 noundef 5) #7
  %20 = tail call i32 @close(i32 noundef 6) #7
  %21 = tail call i32 @close(i32 noundef 7) #7
  %22 = tail call i32 @close(i32 noundef 8) #7
  %23 = tail call i32 @close(i32 noundef 9) #7
  %24 = tail call i32 @close(i32 noundef 10) #7
  %25 = tail call i32 @close(i32 noundef 11) #7
  %26 = tail call i32 @close(i32 noundef 12) #7
  %27 = tail call i32 @close(i32 noundef 13) #7
  %28 = tail call i32 @close(i32 noundef 14) #7
  %29 = tail call i32 @close(i32 noundef 15) #7
  %30 = tail call ptr @signal(i32 noundef 2, ptr noundef null) #7
  %31 = tail call ptr @signal(i32 noundef 3, ptr noundef null) #7
  %32 = tail call ptr @signal(i32 noundef 13, ptr noundef null) #7
  %33 = tail call i32 (ptr, ptr, ...) @execl(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, ptr noundef %1, ptr noundef null) #7
  tail call void @exit(i32 noundef 127) #8
  unreachable

.preheader:                                       ; preds = %3, %37
  %34 = call i32 @wait(ptr noundef nonnull %4) #7
  %35 = icmp ne i32 %34, %5
  %36 = icmp ne i32 %34, -1
  %or.cond = and i1 %35, %36
  br i1 %or.cond, label %37, label %.critedge

37:                                               ; preds = %.preheader
  %38 = tail call ptr @__errno_location() #9
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %.not = icmp eq i32 %39, 4
  br i1 %.not, label %.critedge.thread, label %.preheader, !llvm.loop !11

.critedge:                                        ; preds = %.preheader
  %40 = icmp eq i32 %34, -1
  br i1 %40, label %41, label %.critedge.thread

41:                                               ; preds = %.critedge
  store i32 -1, ptr %4, align 4, !tbaa !5
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %37, %41, %.critedge
  call void @cur_goll() #7
  call void @cur_fixt() #7
  %.not9 = icmp eq i32 %2, 0
  br i1 %.not9, label %45, label %42

42:                                               ; preds = %.critedge.thread
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %44 = call i32 @cur_getp(ptr noundef %0) #7
  br label %45

45:                                               ; preds = %42, %.critedge.thread
  %46 = load i32, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #7
  ret i32 %46
}

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

declare void @cur_rest() local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare i32 @fork() local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @dup(i32 noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fileno(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind
declare ptr @signal(i32 noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare i32 @execl(ptr noundef, ptr noundef, ...) local_unnamed_addr #3

declare i32 @wait(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #6

declare void @cur_goll() local_unnamed_addr #2

declare void @cur_fixt() local_unnamed_addr #2

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

declare i32 @cur_getp(ptr noundef) local_unnamed_addr #2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 #5 = { noreturn 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 #6 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #7 = { nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind willreturn memory(none) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass