; LLVM IR from aap/pdp6 :: tools (mkpty)

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

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @raw(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @reset(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @readwrite(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; 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 i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr null, ptr %8, align 8, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 1
  br i1 %11, label %12, label %16

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds ptr, ptr %13, i64 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %15, ptr %8, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %12, %2
  %17 = call i32 @posix_openpt(i32 noundef 2)
  store i32 %17, ptr %6, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

21:                                               ; preds = %16
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = call i32 @grantpt(i32 noundef %22) #5
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i32 2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

26:                                               ; preds = %21
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = call i32 @unlockpt(i32 noundef %27) #5
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  store i32 3, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

31:                                               ; preds = %26
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %49

34:                                               ; preds = %31
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = call i32 @unlink(ptr noundef %35) #5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = call ptr @ptsname(i32 noundef %37) #5
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = call i32 @symlink(ptr noundef %38, ptr noundef %39) #5
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %42, label %48

42:                                               ; preds = %34
  %43 = load ptr, ptr @stderr, align 8, !tbaa !9
  %44 = call ptr @__errno_location() #6
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = call ptr @strerror(i32 noundef %45) #5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.1, ptr noundef %46) #5
  br label %48

48:                                               ; preds = %42, %34
  br label %49

49:                                               ; preds = %48, %31
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = call ptr @ptsname(i32 noundef %50) #5
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %51)
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = call ptr @ptsname(i32 noundef %53) #5
  %55 = call i32 (ptr, i32, ...) @open(ptr noundef %54, i32 noundef 2)
  store i32 %55, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = icmp slt i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %49
  store i32 4, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

59:                                               ; preds = %49
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = call i32 @raw(i32 noundef %60)
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = call i32 @close(i32 noundef %62)
  %64 = call i32 @raw(i32 noundef 0)
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !5
  call void @readwrite(i32 noundef 0, i32 noundef 1, i32 noundef %65, i32 noundef %66)
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = call i32 @close(i32 noundef %67)
  %69 = call i32 @reset(i32 noundef 0)
  %70 = load ptr, ptr %8, align 8, !tbaa !9
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %75

72:                                               ; preds = %59
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  %74 = call i32 @unlink(ptr noundef %73) #5
  br label %75

75:                                               ; preds = %72, %59
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

76:                                               ; preds = %75, %58, %30, %25, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %77 = load i32, ptr %3, align 4
  ret i32 %77
}

declare i32 @posix_openpt(i32 noundef) #2

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

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

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

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

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

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

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

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

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

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

declare i32 @close(i32 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 = { 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 #5 = { nounwind }
attributes #6 = { 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}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @raw(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @reset(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @readwrite(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 5) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 1
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %4, %2
  %.0 = phi ptr [ %6, %4 ], [ null, %2 ]
  %8 = tail call i32 @posix_openpt(i32 noundef 2) #6
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %42, label %10

10:                                               ; preds = %7
  %11 = tail call i32 @grantpt(i32 noundef %8) #6
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %42, label %13

13:                                               ; preds = %10
  %14 = tail call i32 @unlockpt(i32 noundef %8) #6
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %42, label %16

16:                                               ; preds = %13
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %28, label %17

17:                                               ; preds = %16
  %18 = tail call i32 @unlink(ptr noundef nonnull %.0) #6
  %19 = tail call ptr @ptsname(i32 noundef %8) #6
  %20 = tail call i32 @symlink(ptr noundef %19, ptr noundef nonnull %.0) #6
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %17
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = tail call ptr @__errno_location() #7
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = tail call ptr @strerror(i32 noundef %25) #6
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.1, ptr noundef %26) #8
  br label %28

28:                                               ; preds = %17, %22, %16
  %29 = tail call ptr @ptsname(i32 noundef %8) #6
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %29)
  %31 = tail call ptr @ptsname(i32 noundef %8) #6
  %32 = tail call i32 (ptr, i32, ...) @open(ptr noundef %31, i32 noundef 2) #6
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %42, label %34

34:                                               ; preds = %28
  %35 = tail call i32 @raw(i32 noundef %32)
  %36 = tail call i32 @close(i32 noundef %32) #6
  %37 = tail call i32 @raw(i32 noundef 0)
  tail call void @readwrite(i32 noundef 0, i32 noundef 1, i32 noundef %8, i32 noundef %8)
  %38 = tail call i32 @close(i32 noundef %8) #6
  %39 = tail call i32 @reset(i32 noundef 0)
  br i1 %.not, label %42, label %40

40:                                               ; preds = %34
  %41 = tail call i32 @unlink(ptr noundef nonnull %.0) #6
  br label %42

42:                                               ; preds = %34, %40, %28, %13, %10, %7
  %.019 = phi i32 [ 1, %7 ], [ 2, %10 ], [ 3, %13 ], [ 4, %28 ], [ 0, %40 ], [ 0, %34 ]
  ret i32 %.019
}

declare i32 @posix_openpt(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @grantpt(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @unlockpt(i32 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind
declare ptr @ptsname(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #5

declare i32 @close(i32 noundef) local_unnamed_addr #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 = { "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 "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 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { cold 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass