; LLVM IR from attractivechaos/klib :: knetfile (kftp_connect_file)

; 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.knetFile_s = type { i32, i32, i64, ptr, ptr, i32, [4 x i32], i32, i32, i32, i32, ptr, ptr, ptr, i64, i64, ptr, ptr }

@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@stderr = external global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_get_response(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_send_cmd(ptr noundef, ptr noundef, i32 noundef) #0

declare i32 @close(i32 noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @kftp_connect_file(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca [32 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.knetFile_s, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp ne i32 %10, -1
  br i1 %11, label %12, label %25

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.knetFile_s, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = call i32 @close(i32 noundef %15)
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.knetFile_s, ptr %17, i32 0, i32 9
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %12
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i32 @kftp_get_response(ptr noundef %22)
  br label %24

24:                                               ; preds = %21, %12
  br label %25

25:                                               ; preds = %24, %1
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call i32 @kftp_pasv_prep(ptr noundef %26)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.knetFile_s, ptr %29, i32 0, i32 13
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = call i32 @kftp_send_cmd(ptr noundef %28, ptr noundef %31, i32 noundef 1)
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.knetFile_s, ptr %33, i32 0, i32 11
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %35, ptr noundef @.str.7, ptr noundef %5) #4
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %38, label %44

38:                                               ; preds = %25
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.knetFile_s, ptr %40, i32 0, i32 11
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.8, ptr noundef %42) #4
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %88

44:                                               ; preds = %25
  %45 = load i64, ptr %5, align 8, !tbaa !16
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.knetFile_s, ptr %46, i32 0, i32 15
  store i64 %45, ptr %47, align 8, !tbaa !18
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.knetFile_s, ptr %48, i32 0, i32 2
  %50 = load i64, ptr %49, align 8, !tbaa !19
  %51 = icmp sge i64 %50, 0
  br i1 %51, label %52, label %61

52:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  %53 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.knetFile_s, ptr %54, i32 0, i32 2
  %56 = load i64, ptr %55, align 8, !tbaa !19
  %57 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %53, ptr noundef @.str.9, i64 noundef %56) #4
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %60 = call i32 @kftp_send_cmd(ptr noundef %58, ptr noundef %59, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  br label %61

61:                                               ; preds = %52, %44
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.knetFile_s, ptr %63, i32 0, i32 12
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = call i32 @kftp_send_cmd(ptr noundef %62, ptr noundef %65, i32 noundef 0)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = call i32 @kftp_pasv_connect(ptr noundef %67)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = call i32 @kftp_get_response(ptr noundef %69)
  store i32 %70, ptr %4, align 4, !tbaa !21
  %71 = load i32, ptr %4, align 4, !tbaa !21
  %72 = icmp ne i32 %71, 150
  br i1 %72, label %73, label %85

73:                                               ; preds = %61
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.knetFile_s, ptr %75, i32 0, i32 11
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str.8, ptr noundef %77) #4
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.knetFile_s, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !9
  %82 = call i32 @close(i32 noundef %81)
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.knetFile_s, ptr %83, i32 0, i32 1
  store i32 -1, ptr %84, align 4, !tbaa !9
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %88

85:                                               ; preds = %61
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.knetFile_s, ptr %86, i32 0, i32 10
  store i32 1, ptr %87, align 8, !tbaa !22
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %88

88:                                               ; preds = %85, %73, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %89 = load i32, ptr %2, align 4
  ret i32 %89
}

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_pasv_prep(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_pasv_connect(ptr noundef) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !11, i64 4}
!10 = !{!"knetFile_s", !11, i64 0, !11, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !7, i64 36, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !12, i64 96, !12, i64 104, !6, i64 112, !6, i64 120}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 60}
!14 = !{!10, !6, i64 88}
!15 = !{!10, !6, i64 72}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!10, !12, i64 104}
!19 = !{!10, !12, i64 8}
!20 = !{!10, !6, i64 80}
!21 = !{!11, !11, i64 0}
!22 = !{!10, !11, i64 64}


; 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.7 = external hidden unnamed_addr constant [9 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_get_response(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_send_cmd(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @close(i32 noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @kftp_connect_file(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, -1
  br i1 %.not, label %12, label %6

6:                                                ; preds = %1
  %7 = tail call i32 @close(i32 noundef %5) #4
  %8 = getelementptr inbounds i8, ptr %0, i64 60
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %.not23 = icmp eq i32 %9, 0
  br i1 %.not23, label %12, label %10

10:                                               ; preds = %6
  %11 = tail call i32 @kftp_get_response(ptr noundef nonnull %0)
  br label %12

12:                                               ; preds = %6, %10, %1
  %13 = tail call i32 @kftp_pasv_prep(ptr noundef nonnull %0)
  %14 = getelementptr inbounds i8, ptr %0, i64 88
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = tail call i32 @kftp_send_cmd(ptr noundef nonnull %0, ptr noundef %15, i32 noundef 1)
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %18, ptr noundef nonnull @.str.7, ptr noundef nonnull %2) #4
  %.not24 = icmp eq i32 %19, 1
  br i1 %.not24, label %24, label %20

20:                                               ; preds = %12
  %21 = load ptr, ptr @stderr, align 8, !tbaa !15
  %22 = load ptr, ptr %17, align 8, !tbaa !14
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.8, ptr noundef %22) #5
  br label %47

24:                                               ; preds = %12
  %25 = load i64, ptr %2, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 %25, ptr %26, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load i64, ptr %27, align 8, !tbaa !19
  %29 = icmp sgt i64 %28, -1
  br i1 %29, label %30, label %33

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %31 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.9, i64 noundef %28) #4
  %32 = call i32 @kftp_send_cmd(ptr noundef nonnull %0, ptr noundef nonnull %3, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br label %33

33:                                               ; preds = %30, %24
  %34 = getelementptr inbounds i8, ptr %0, i64 80
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = call i32 @kftp_send_cmd(ptr noundef nonnull %0, ptr noundef %35, i32 noundef 0)
  %37 = call i32 @kftp_pasv_connect(ptr noundef nonnull %0)
  %38 = call i32 @kftp_get_response(ptr noundef nonnull %0)
  %.not25 = icmp eq i32 %38, 150
  br i1 %.not25, label %45, label %39

39:                                               ; preds = %33
  %40 = load ptr, ptr @stderr, align 8, !tbaa !15
  %41 = load ptr, ptr %17, align 8, !tbaa !14
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.8, ptr noundef %41) #5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = call i32 @close(i32 noundef %43) #4
  store i32 -1, ptr %4, align 4, !tbaa !5
  br label %47

45:                                               ; preds = %33
  %46 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 1, ptr %46, align 8, !tbaa !21
  br label %47

47:                                               ; preds = %45, %39, %20
  %.0 = phi i32 [ -1, %20 ], [ -1, %39 ], [ 0, %45 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_pasv_prep(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @kftp_pasv_connect(ptr noundef) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #5 = { 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, !7, i64 4}
!6 = !{!"knetFile_s", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !7, i64 32, !8, i64 36, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !10, i64 96, !10, i64 104, !11, i64 112, !11, i64 120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 60}
!13 = !{!6, !11, i64 88}
!14 = !{!6, !11, i64 72}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !8, i64 0}
!18 = !{!6, !10, i64 104}
!19 = !{!6, !10, i64 8}
!20 = !{!6, !11, i64 80}
!21 = !{!6, !7, i64 64}


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