; LLVM IR from Aeternum-Veritas/Merry :: test (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 [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@__const.main.c = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [2 x i32], align 4
  %8 = alloca [2 x i8], align 1
  %9 = alloca [3 x ptr], align 16
  %10 = alloca [14 x i8], align 1
  %11 = alloca i32, align 4
  %12 = alloca [14 x i8], align 1
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %14)
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 1
  br i1 %17, label %18, label %26

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %19, i64 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = call i64 @strtol(ptr noundef %21, ptr noundef null, i32 noundef 10) #5
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %24)
  br label %54

26:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %27 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %28 = call i32 @pipe(ptr noundef %27) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #5
  %29 = getelementptr inbounds [2 x i8], ptr %8, i64 0, i64 0
  %30 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %29, i64 noundef 2, ptr noundef @.str.2, i32 noundef %31) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #5
  store ptr @.str.3, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds ptr, ptr %9, i64 1
  %34 = getelementptr inbounds [2 x i8], ptr %8, i64 0, i64 0
  store ptr %34, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds ptr, ptr %9, i64 2
  store ptr null, ptr %35, align 8, !tbaa !9
  %36 = call i32 @fork() #5
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %26
  %39 = getelementptr inbounds [3 x ptr], ptr %9, i64 0, i64 0
  %40 = call i32 @execv(ptr noundef @.str.3, ptr noundef %39) #5
  br label %41

41:                                               ; preds = %38, %26
  %42 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = call i32 @close(i32 noundef %43)
  call void @llvm.lifetime.start.p0(i64 14, ptr %10) #5
  %45 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = getelementptr inbounds [14 x i8], ptr %10, i64 0, i64 0
  %48 = call i64 @read(i32 noundef %46, ptr noundef %47, i64 noundef 14)
  %49 = getelementptr inbounds [14 x i8], ptr %10, i64 0, i64 0
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %49)
  %51 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = call i32 @close(i32 noundef %52)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 14, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %60

54:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 14, ptr %12) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %12, ptr align 1 @__const.main.c, i64 14, i1 false)
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = getelementptr inbounds [14 x i8], ptr %12, i64 0, i64 0
  %57 = call i64 @write(i32 noundef %55, ptr noundef %56, i64 noundef 14)
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = call i32 @close(i32 noundef %58)
  call void @llvm.lifetime.end.p0(i64 14, ptr %12) #5
  store i32 0, ptr %11, align 4
  br label %60

60:                                               ; preds = %54, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %61 = load i32, ptr %11, align 4
  switch i32 %61, label %64 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  %63 = load i32, ptr %3, align 4
  ret i32 %63

64:                                               ; preds = %60
  unreachable
}

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

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

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

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

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

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

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

declare i32 @close(i32 noundef) #2

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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}


; 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 [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@__const.main.c = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [2 x i32], align 4
  %4 = alloca [2 x i8], align 1
  %5 = alloca [3 x ptr], align 16
  %6 = alloca [14 x i8], align 1
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %9 = icmp sgt i32 %0, 1
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call i64 @strtol(ptr nocapture noundef %12, ptr noundef null, i32 noundef 10) #7
  %14 = trunc i64 %13 to i32
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %14)
  %16 = tail call i64 @write(i32 noundef %14, ptr noundef nonnull @__const.main.c, i64 noundef 14) #7
  %17 = tail call i32 @close(i32 noundef %14) #7
  br label %37

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  %19 = call i32 @pipe(ptr noundef nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #7
  %20 = getelementptr inbounds i8, ptr %3, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %4, i64 noundef 2, ptr noundef nonnull @.str.2, i32 noundef %21) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #7
  store ptr @.str.3, ptr %5, align 16, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %4, ptr %23, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr null, ptr %24, align 16, !tbaa !5
  %25 = call i32 @fork() #7
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %18
  %28 = call i32 @execv(ptr noundef nonnull @.str.3, ptr noundef nonnull %5) #7
  br label %29

29:                                               ; preds = %27, %18
  %30 = load i32, ptr %20, align 4, !tbaa !9
  %31 = call i32 @close(i32 noundef %30) #7
  call void @llvm.lifetime.start.p0(i64 14, ptr nonnull %6) #7
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = call i64 @read(i32 noundef %32, ptr noundef nonnull %6, i64 noundef 14) #7
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef nonnull %6)
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = call i32 @close(i32 noundef %35) #7
  call void @llvm.lifetime.end.p0(i64 14, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  br label %37

37:                                               ; preds = %10, %29
  ret i32 0
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtol(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: nofree nounwind
declare i32 @execv(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @close(i32 noundef) local_unnamed_addr #5

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #6

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

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #6

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 = { 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 = { mustprogress nofree nounwind willreturn "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 = { "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 = { nofree "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 }

!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}


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