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

; 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.3 = external hidden unnamed_addr constant [7 x i8], align 1
@stderr = external global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @kftp_parse_url(ptr noundef, ptr 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: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #3

; 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 @kftp_connect_file(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @khttp_parse_url(ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @knet_open(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store ptr null, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 0
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp ne i32 %12, 114
  br i1 %13, label %14, label %17

14:                                               ; preds = %2
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.19) #6
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %86

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call ptr @strstr(ptr noundef %18, ptr noundef @.str.3) #7
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = icmp eq ptr %19, %20
  br i1 %21, label %22, label %39

22:                                               ; preds = %17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call ptr @kftp_parse_url(ptr noundef %23, ptr noundef %24)
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %86

29:                                               ; preds = %22
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i32 @kftp_connect(ptr noundef %30)
  %32 = icmp eq i32 %31, -1
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i32 @knet_close(ptr noundef %34)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %86

36:                                               ; preds = %29
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call i32 @kftp_connect_file(ptr noundef %37)
  br label %73

39:                                               ; preds = %17
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = call ptr @strstr(ptr noundef %40, ptr noundef @.str.10) #7
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = icmp eq ptr %41, %42
  br i1 %43, label %44, label %54

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call ptr @khttp_parse_url(ptr noundef %45, ptr noundef %46)
  store ptr %47, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %44
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %86

51:                                               ; preds = %44
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = call i32 @khttp_connect_file(ptr noundef %52)
  br label %72

54:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = call i32 (ptr, i32, ...) @open(ptr noundef %55, i32 noundef 0)
  store i32 %56, ptr %8, align 4, !tbaa !10
  %57 = load i32, ptr %8, align 4, !tbaa !10
  %58 = icmp eq i32 %57, -1
  br i1 %58, label %59, label %60

59:                                               ; preds = %54
  call void @perror(ptr noundef @.str.20)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %69

60:                                               ; preds = %54
  %61 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 128) #8
  store ptr %61, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.knetFile_s, ptr %62, i32 0, i32 0
  store i32 1, ptr %63, align 8, !tbaa !12
  %64 = load i32, ptr %8, align 4, !tbaa !10
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.knetFile_s, ptr %65, i32 0, i32 1
  store i32 %64, ptr %66, align 4, !tbaa !15
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.knetFile_s, ptr %67, i32 0, i32 5
  store i32 -1, ptr %68, align 8, !tbaa !16
  store i32 0, ptr %7, align 4
  br label %69

69:                                               ; preds = %60, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %70 = load i32, ptr %7, align 4
  switch i32 %70, label %86 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71, %51
  br label %73

73:                                               ; preds = %72, %36
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %84

76:                                               ; preds = %73
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.knetFile_s, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !15
  %80 = icmp eq i32 %79, -1
  br i1 %80, label %81, label %84

81:                                               ; preds = %76
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = call i32 @knet_close(ptr noundef %82)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %86

84:                                               ; preds = %76, %73
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %85, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %86

86:                                               ; preds = %84, %81, %69, %50, %33, %28, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %87 = load ptr, ptr %3, align 8
  ret ptr %87
}

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

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

declare void @perror(ptr noundef) #5

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 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 #3 = { nounwind allocsize(0,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 #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 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind allocsize(0,1) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"knetFile_s", !11, i64 0, !11, i64 4, !14, 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, !14, i64 96, !14, i64 104, !6, i64 112, !6, i64 120}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !11, i64 4}
!16 = !{!13, !11, i64 32}


; 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.3 = external hidden unnamed_addr constant [7 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @kftp_parse_url(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @khttp_parse_url(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @knet_open(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  %.not = icmp eq i8 %3, 114
  br i1 %.not, label %7, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !8
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.19) #5
  br label %36

7:                                                ; preds = %2
  %strlen = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.3)
  %strncmp = tail call i32 @strncmp(ptr %0, ptr nonnull @.str.3, i64 %strlen)
  %cmp = icmp eq i32 %strncmp, 0
  br i1 %cmp, label %8, label %18

8:                                                ; preds = %7
  %9 = tail call ptr @kftp_parse_url(ptr noundef %0, ptr noundef nonnull %1)
  %10 = icmp eq ptr %9, null
  br i1 %10, label %36, label %11

11:                                               ; preds = %8
  %12 = tail call i32 @kftp_connect(ptr noundef nonnull %9)
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = tail call i32 @knet_close(ptr noundef nonnull %9)
  br label %36

16:                                               ; preds = %11
  %17 = tail call i32 @kftp_connect_file(ptr noundef nonnull %9)
  br label %30

18:                                               ; preds = %7
  %strlen33 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.10)
  %strncmp34 = tail call i32 @strncmp(ptr %0, ptr nonnull @.str.10, i64 %strlen33)
  %cmp35 = icmp eq i32 %strncmp34, 0
  br i1 %cmp35, label %19, label %24

19:                                               ; preds = %18
  %20 = tail call ptr @khttp_parse_url(ptr noundef %0, ptr noundef nonnull %1)
  %21 = icmp eq ptr %20, null
  br i1 %21, label %36, label %22

22:                                               ; preds = %19
  %23 = tail call i32 @khttp_connect_file(ptr noundef nonnull %20)
  br label %30

24:                                               ; preds = %18
  %25 = tail call i32 (ptr, i32, ...) @open(ptr noundef %0, i32 noundef 0) #6
  %.not36 = icmp eq i32 %25, -1
  br i1 %.not36, label %.thread, label %26

.thread:                                          ; preds = %24
  tail call void @perror(ptr noundef nonnull @.str.20) #7
  br label %36

26:                                               ; preds = %24
  %27 = tail call noalias dereferenceable_or_null(128) ptr @calloc(i64 noundef 1, i64 noundef 128) #8
  store i32 1, ptr %27, align 8, !tbaa !10
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  store i32 %25, ptr %28, align 4, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %27, i64 32
  store i32 -1, ptr %29, align 8, !tbaa !15
  br label %30

30:                                               ; preds = %16, %22, %26
  %.128 = phi ptr [ %9, %16 ], [ %20, %22 ], [ %27, %26 ]
  %31 = getelementptr inbounds i8, ptr %.128, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %36

34:                                               ; preds = %30
  %35 = tail call i32 @knet_close(ptr noundef nonnull %.128)
  br label %36

36:                                               ; preds = %.thread, %30, %19, %8, %34, %14, %4
  %.1 = phi ptr [ null, %4 ], [ null, %14 ], [ null, %34 ], [ null, %8 ], [ null, %19 ], [ %.128, %30 ], [ null, %.thread ]
  ret ptr %.1
}

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

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

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #4

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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { 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 #4 = { nofree nounwind willreturn memory(argmem: read) }
attributes #5 = { cold nounwind }
attributes #6 = { nounwind }
attributes #7 = { cold }
attributes #8 = { nounwind allocsize(0,1) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"knetFile_s", !12, i64 0, !12, i64 4, !13, i64 8, !9, i64 16, !9, i64 24, !12, i64 32, !6, i64 36, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !13, i64 96, !13, i64 104, !9, i64 112, !9, i64 120}
!12 = !{!"int", !6, i64 0}
!13 = !{!"long", !6, i64 0}
!14 = !{!11, !12, i64 4}
!15 = !{!11, !12, i64 32}


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