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

; 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
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @kftp_parse_url(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 ptr, align 8
  %8 = alloca i32, align 4
  %9 = 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) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call ptr @strstr(ptr noundef %10, ptr noundef @.str.3) #6
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %102

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 6
  store ptr %17, ptr %7, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %31, %15
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp ne i32 %26, 47
  br label %28

28:                                               ; preds = %23, %18
  %29 = phi i1 [ false, %18 ], [ %27, %23 ]
  br i1 %29, label %30, label %34

30:                                               ; preds = %28
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i32 1
  store ptr %33, ptr %7, align 8, !tbaa !5
  br label %18, !llvm.loop !10

34:                                               ; preds = %28
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = sext i8 %36 to i32
  %38 = icmp ne i32 %37, 47
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %102

40:                                               ; preds = %34
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = ptrtoint ptr %41 to i64
  %44 = ptrtoint ptr %42 to i64
  %45 = sub i64 %43, %44
  %46 = sub nsw i64 %45, 6
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr %8, align 4, !tbaa !12
  %48 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 128) #7
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.knetFile_s, ptr %49, i32 0, i32 0
  store i32 2, ptr %50, align 8, !tbaa !14
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.knetFile_s, ptr %51, i32 0, i32 1
  store i32 -1, ptr %52, align 4, !tbaa !17
  %53 = call noalias ptr @strdup(ptr noundef @.str.4) #5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.knetFile_s, ptr %54, i32 0, i32 4
  store ptr %53, ptr %55, align 8, !tbaa !18
  %56 = load i32, ptr %8, align 4, !tbaa !12
  %57 = add nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = call noalias ptr @calloc(i64 noundef %58, i64 noundef 1) #7
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.knetFile_s, ptr %60, i32 0, i32 3
  store ptr %59, ptr %61, align 8, !tbaa !19
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = call ptr @strchr(ptr noundef %62, i32 noundef 99) #6
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %68

65:                                               ; preds = %40
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.knetFile_s, ptr %66, i32 0, i32 9
  store i32 1, ptr %67, align 4, !tbaa !20
  br label %68

68:                                               ; preds = %65, %40
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.knetFile_s, ptr %69, i32 0, i32 3
  %71 = load ptr, ptr %70, align 8, !tbaa !19
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 6
  %74 = load i32, ptr %8, align 4, !tbaa !12
  %75 = sext i32 %74 to i64
  %76 = call ptr @strncpy(ptr noundef %71, ptr noundef %73, i64 noundef %75) #5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = call i64 @strlen(ptr noundef %77) #6
  %79 = add i64 %78, 8
  %80 = call noalias ptr @calloc(i64 noundef %79, i64 noundef 1) #7
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.knetFile_s, ptr %81, i32 0, i32 12
  store ptr %80, ptr %82, align 8, !tbaa !21
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.knetFile_s, ptr %83, i32 0, i32 12
  %85 = load ptr, ptr %84, align 8, !tbaa !21
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %85, ptr noundef @.str.5, ptr noundef %86) #5
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = call i64 @strlen(ptr noundef %88) #6
  %90 = add i64 %89, 8
  %91 = call noalias ptr @calloc(i64 noundef %90, i64 noundef 1) #7
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.knetFile_s, ptr %92, i32 0, i32 13
  store ptr %91, ptr %93, align 8, !tbaa !22
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.knetFile_s, ptr %94, i32 0, i32 13
  %96 = load ptr, ptr %95, align 8, !tbaa !22
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %96, ptr noundef @.str.6, ptr noundef %97) #5
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.knetFile_s, ptr %99, i32 0, i32 14
  store i64 0, ptr %100, align 8, !tbaa !23
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %101, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %102

102:                                              ; preds = %68, %39, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %103 = load ptr, ptr %3, align 8
  ret ptr %103
}

; 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: nounwind
declare noalias ptr @strdup(ptr noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

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

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

; 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 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 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"knetFile_s", !13, i64 0, !13, i64 4, !16, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !7, i64 36, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !16, i64 96, !16, i64 104, !6, i64 112, !6, i64 120}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !13, i64 4}
!18 = !{!15, !6, i64 24}
!19 = !{!15, !6, i64 16}
!20 = !{!15, !13, i64 60}
!21 = !{!15, !6, i64 80}
!22 = !{!15, !6, i64 88}
!23 = !{!15, !16, i64 96}


; 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
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noalias noundef ptr @kftp_parse_url(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %strlen = tail call i64 @strlen(ptr nonnull dereferenceable(1) @.str.3)
  %strncmp = tail call i32 @strncmp(ptr %0, ptr nonnull @.str.3, i64 %strlen)
  %cmp.not = icmp eq i32 %strncmp, 0
  br i1 %cmp.not, label %3, label %.loopexit

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 6
  br label %5

5:                                                ; preds = %7, %3
  %.029 = phi ptr [ %4, %3 ], [ %8, %7 ]
  %6 = load i8, ptr %.029, align 1, !tbaa !5
  switch i8 %6, label %7 [
    i8 47, label %9
    i8 0, label %.loopexit
  ]

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %.029, i64 1
  br label %5, !llvm.loop !8

9:                                                ; preds = %5
  %10 = ptrtoint ptr %.029 to i64
  %11 = ptrtoint ptr %0 to i64
  %12 = sub i64 %10, %11
  %13 = tail call noalias dereferenceable_or_null(128) ptr @calloc(i64 noundef 1, i64 noundef 128) #7
  store i32 2, ptr %13, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  store i32 -1, ptr %14, align 4, !tbaa !15
  %15 = tail call noalias ptr @strdup(ptr noundef nonnull @.str.4) #8
  %16 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %15, ptr %16, align 8, !tbaa !16
  %17 = shl i64 %12, 32
  %sext = add i64 %17, -21474836480
  %18 = ashr exact i64 %sext, 32
  %19 = tail call noalias ptr @calloc(i64 noundef %18, i64 noundef 1) #7
  %20 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %19, ptr %20, align 8, !tbaa !17
  %21 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %1, i32 noundef 99) #9
  %.not34 = icmp eq ptr %21, null
  br i1 %.not34, label %24, label %22

22:                                               ; preds = %9
  %23 = getelementptr inbounds i8, ptr %13, i64 60
  store i32 1, ptr %23, align 4, !tbaa !18
  br label %24

24:                                               ; preds = %22, %9
  %sext35 = add i64 %17, -25769803776
  %25 = ashr exact i64 %sext35, 32
  %26 = tail call ptr @strncpy(ptr noundef %19, ptr noundef nonnull %4, i64 noundef %25) #8
  %27 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.029) #9
  %28 = add i64 %27, 8
  %29 = tail call noalias ptr @calloc(i64 noundef %28, i64 noundef 1) #7
  %30 = getelementptr inbounds i8, ptr %13, i64 80
  store ptr %29, ptr %30, align 8, !tbaa !19
  %31 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %29, ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef nonnull %.029) #8
  %32 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.029) #9
  %33 = add i64 %32, 8
  %34 = tail call noalias ptr @calloc(i64 noundef %33, i64 noundef 1) #7
  %35 = getelementptr inbounds i8, ptr %13, i64 88
  store ptr %34, ptr %35, align 8, !tbaa !20
  %36 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %34, ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %.029) #8
  br label %.loopexit

.loopexit:                                        ; preds = %5, %2, %24
  %.0 = phi ptr [ %13, %24 ], [ null, %2 ], [ null, %5 ]
  ret ptr %.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: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

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

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

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

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass