; LLVM IR from kala13x/libxutils :: src/sys (cli)

; 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.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@stdin = external global ptr, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @XCLI_GetPass(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.termios, align 4
  %10 = alloca %struct.termios, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 60, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 60, ptr %10) #6
  %13 = load ptr, ptr @stdin, align 8, !tbaa !5
  %14 = call i32 @fileno(ptr noundef %13) #6
  %15 = call i32 @tcgetattr(i32 noundef %14, ptr noundef %9) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %9, i64 60, i1 false), !tbaa.struct !11
  %16 = getelementptr inbounds %struct.termios, ptr %10, i32 0, i32 3
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = and i32 %17, -9
  store i32 %18, ptr %16, align 4, !tbaa !15
  %19 = getelementptr inbounds %struct.termios, ptr %10, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !15
  %21 = or i32 %20, 64
  store i32 %21, ptr %19, align 4, !tbaa !15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %3
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %25)
  br label %27

27:                                               ; preds = %24, %3
  %28 = load ptr, ptr @stdin, align 8, !tbaa !5
  %29 = call i32 @fileno(ptr noundef %28) #6
  %30 = call i32 @tcsetattr(i32 noundef %29, i32 noundef 0, ptr noundef %10) #6
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %75

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = trunc i64 %35 to i32
  %37 = load ptr, ptr @stdin, align 8, !tbaa !5
  %38 = call ptr @fgets(ptr noundef %34, i32 noundef %36, ptr noundef %37)
  store ptr %38, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %44

41:                                               ; preds = %33
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i64 @strlen(ptr noundef %42) #7
  br label %45

44:                                               ; preds = %33
  br label %45

45:                                               ; preds = %44, %41
  %46 = phi i64 [ %43, %41 ], [ 0, %44 ]
  store i64 %46, ptr %8, align 8, !tbaa !9
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = icmp ugt i64 %47, 0
  br i1 %48, label %49, label %62

49:                                               ; preds = %45
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i64, ptr %8, align 8, !tbaa !9
  %52 = sub i64 %51, 1
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !14
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 10
  br i1 %56, label %57, label %62

57:                                               ; preds = %49
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = load i64, ptr %8, align 8, !tbaa !9
  %60 = add i64 %59, -1
  store i64 %60, ptr %8, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  store i8 0, ptr %61, align 1, !tbaa !14
  br label %62

62:                                               ; preds = %57, %49, %45
  %63 = load ptr, ptr @stdin, align 8, !tbaa !5
  %64 = call i32 @fileno(ptr noundef %63) #6
  %65 = call i32 @tcsetattr(i32 noundef %64, i32 noundef 0, ptr noundef %9) #6
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %62
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

68:                                               ; preds = %62
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  store i8 0, ptr %71, align 1, !tbaa !14
  %72 = load i64, ptr %8, align 8, !tbaa !9
  %73 = trunc i64 %72 to i32
  store i32 %73, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

74:                                               ; preds = %68, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %75

75:                                               ; preds = %74, %32
  call void @llvm.lifetime.end.p0(i64 60, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 60, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %76 = load i32, ptr %4, align 4
  ret i32 %76
}

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

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

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

; 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) #3

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

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

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

; 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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(read) "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(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !12, i64 16, i64 1, !14, i64 17, i64 32, !14, i64 52, i64 4, !12, i64 56, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !13, i64 12}
!16 = !{!"termios", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !7, i64 16, !7, i64 17, !13, i64 52, !13, i64 56}


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

%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XCLI_GetPass(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.termios, align 4
  %5 = alloca %struct.termios, align 4
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %5) #6
  %6 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = tail call i32 @fileno(ptr noundef %6) #6
  %8 = call i32 @tcgetattr(i32 noundef %7, ptr noundef nonnull %4) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(60) %5, ptr noundef nonnull align 4 dereferenceable(60) %4, i64 60, i1 false), !tbaa.struct !9
  %9 = getelementptr inbounds i8, ptr %5, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !13
  %11 = and i32 %10, -73
  %12 = or disjoint i32 %11, 64
  store i32 %12, ptr %9, align 4, !tbaa !13
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %15, label %13

13:                                               ; preds = %3
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %0)
  br label %15

15:                                               ; preds = %13, %3
  %16 = load ptr, ptr @stdin, align 8, !tbaa !5
  %17 = call i32 @fileno(ptr noundef %16) #6
  %18 = call i32 @tcsetattr(i32 noundef %17, i32 noundef 0, ptr noundef nonnull %5) #6
  %.not18 = icmp eq i32 %18, 0
  br i1 %.not18, label %19, label %39

19:                                               ; preds = %15
  %20 = trunc i64 %2 to i32
  %21 = load ptr, ptr @stdin, align 8, !tbaa !5
  %22 = call ptr @fgets(ptr noundef %1, i32 noundef %20, ptr noundef %21)
  %.not19 = icmp eq ptr %22, null
  br i1 %.not19, label %.thread, label %23

23:                                               ; preds = %19
  %24 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #7
  %.not20 = icmp eq i64 %24, 0
  br i1 %.not20, label %.thread, label %25

25:                                               ; preds = %23
  %26 = getelementptr i8, ptr %22, i64 %24
  %27 = getelementptr i8, ptr %26, i64 -1
  %28 = load i8, ptr %27, align 1, !tbaa !12
  %29 = icmp eq i8 %28, 10
  br i1 %29, label %30, label %.thread

30:                                               ; preds = %25
  %31 = add i64 %24, -1
  %32 = getelementptr inbounds i8, ptr %22, i64 %31
  store i8 0, ptr %32, align 1, !tbaa !12
  br label %.thread

.thread:                                          ; preds = %19, %30, %25, %23
  %.014 = phi i64 [ %31, %30 ], [ %24, %25 ], [ 0, %23 ], [ 0, %19 ]
  %33 = load ptr, ptr @stdin, align 8, !tbaa !5
  %34 = call i32 @fileno(ptr noundef %33) #6
  %35 = call i32 @tcsetattr(i32 noundef %34, i32 noundef 0, ptr noundef nonnull %4) #6
  %.not21 = icmp eq i32 %35, 0
  br i1 %.not21, label %36, label %39

36:                                               ; preds = %.thread
  %37 = getelementptr inbounds i8, ptr %1, i64 %.014
  store i8 0, ptr %37, align 1, !tbaa !12
  %38 = trunc i64 %.014 to i32
  br label %39

39:                                               ; preds = %36, %.thread, %15
  %.1 = phi i32 [ -1, %15 ], [ %38, %36 ], [ -1, %.thread ]
  call void @llvm.lifetime.end.p0(i64 60, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 60, ptr nonnull %4) #6
  ret i32 %.1
}

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

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

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

; Function Attrs: mustprogress 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

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

; 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 = { 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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(read) }

!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 = !{i64 0, i64 4, !10, i64 4, i64 4, !10, i64 8, i64 4, !10, i64 12, i64 4, !10, i64 16, i64 1, !12, i64 17, i64 32, !12, i64 52, i64 4, !10, i64 56, i64 4, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !11, i64 12}
!14 = !{!"termios", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !7, i64 16, !7, i64 17, !11, i64 52, !11, i64 56}


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