; LLVM IR from kala13x/libxutils :: tools (xhttp)

; 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.xhttp_args_ = type { i32, %struct.xcli_bar_, ptr, %struct.XTime, i8, i8, i8, i8, i8, i64, i64, i64, %struct.XByteBuffer, [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8] }
%struct.xcli_bar_ = type { %struct.xcli_size_, i64, i64, i32, i32, i8, i8, i8, i8, double, i32, i8, i8, i8, i8, i8, i8, [256 x i8], [256 x i8], [256 x i8] }
%struct.xcli_size_ = type { i64, i64 }
%struct.XTime = type { i16, i8, i8, i8, i8, i8, i8 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.xhttp_ = type { ptr, i16, ptr, i32, %struct.XByteBuffer, i32, %struct.XMap, i16, i16, i64, i64, i64, i64, i64, i8, i8, i8, [256 x i8], [128 x i8], [2048 x i8] }
%struct.XMap = type { ptr, ptr, ptr, i64, i64, i32 }
%struct.XArray_ = type { ptr, ptr, i32, ptr, i8, i8, i8, i64, i64 }

@.str.29 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [22 x i8], align 1

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

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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XHTTPApp_AppendArgHeaders(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  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) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.xhttp_args_, ptr %16, i32 0, i32 15
  %18 = getelementptr inbounds [2048 x i8], ptr %17, i64 0, i64 0
  %19 = call ptr @xstrsplit(ptr noundef %18, ptr noundef @.str.29)
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %91

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xhttp_, ptr %24, i32 0, i32 14
  store i8 1, ptr %25, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XArray_, ptr %26, i32 0, i32 8
  %28 = load i64, ptr %27, align 8, !tbaa !16
  store i64 %28, ptr %9, align 8, !tbaa !18
  store i64 0, ptr %8, align 8, !tbaa !18
  br label %29

29:                                               ; preds = %85, %23
  %30 = load i64, ptr %8, align 8, !tbaa !18
  %31 = load i64, ptr %9, align 8, !tbaa !18
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %33, label %88

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %8, align 8, !tbaa !18
  %36 = call ptr @XArray_GetData(ptr noundef %34, i64 noundef %35)
  store ptr %36, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %40

39:                                               ; preds = %33
  store i32 4, ptr %7, align 4
  br label %82

40:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = call ptr @xstrtok(ptr noundef %41, ptr noundef @.str.30, ptr noundef %11)
  store ptr %42, ptr %12, align 8, !tbaa !5
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %47

45:                                               ; preds = %40
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XArray_Destroy(ptr noundef %46)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %81

47:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %48 = call ptr @xstrtok(ptr noundef null, ptr noundef @.str.30, ptr noundef %11)
  store ptr %48, ptr %13, align 8, !tbaa !5
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %53

51:                                               ; preds = %47
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XArray_Destroy(ptr noundef %52)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %80

53:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %54, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %55, ptr %15, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %61, %53
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = load i8, ptr %57, align 1, !tbaa !19
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 32
  br i1 %60, label %61, label %64

61:                                               ; preds = %56
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i32 1
  store ptr %63, ptr %14, align 8, !tbaa !5
  br label %56, !llvm.loop !20

64:                                               ; preds = %56
  br label %65

65:                                               ; preds = %70, %64
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  %67 = load i8, ptr %66, align 1, !tbaa !19
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 32
  br i1 %69, label %70, label %73

70:                                               ; preds = %65
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i32 1
  store ptr %72, ptr %15, align 8, !tbaa !5
  br label %65, !llvm.loop !22

73:                                               ; preds = %65
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  %76 = load ptr, ptr %15, align 8, !tbaa !5
  %77 = call i32 (ptr, ptr, ptr, ...) @XHTTP_AddHeader(ptr noundef %74, ptr noundef %75, ptr noundef @.str.31, ptr noundef %76)
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  %79 = load ptr, ptr %15, align 8, !tbaa !5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef @.str.32, ptr noundef %78, ptr noundef %79)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  store i32 0, ptr %7, align 4
  br label %80

80:                                               ; preds = %73, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %81

81:                                               ; preds = %80, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %82

82:                                               ; preds = %81, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %83 = load i32, ptr %7, align 4
  switch i32 %83, label %90 [
    i32 0, label %84
    i32 4, label %85
  ]

84:                                               ; preds = %82
  br label %85

85:                                               ; preds = %84, %82
  %86 = load i64, ptr %8, align 8, !tbaa !18
  %87 = add i64 %86, 1
  store i64 %87, ptr %8, align 8, !tbaa !18
  br label %29, !llvm.loop !23

88:                                               ; preds = %29
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XArray_Destroy(ptr noundef %89)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %90

90:                                               ; preds = %88, %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %91

91:                                               ; preds = %90, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %92 = load i32, ptr %3, align 4
  ret i32 %92
}

declare ptr @xstrsplit(ptr noundef, ptr noundef) #1

declare ptr @XArray_GetData(ptr noundef, i64 noundef) #1

declare ptr @xstrtok(ptr noundef, ptr noundef, ptr noundef) #1

declare void @XArray_Destroy(ptr noundef) #1

declare i32 @XHTTP_AddHeader(ptr noundef, ptr noundef, ptr noundef, ...) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { 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, !7, i64 168}
!10 = !{!"xhttp_", !6, i64 0, !11, i64 8, !6, i64 16, !12, i64 24, !13, i64 32, !12, i64 64, !15, i64 72, !11, i64 120, !11, i64 122, !14, i64 128, !14, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !7, i64 168, !7, i64 169, !7, i64 170, !7, i64 171, !7, i64 427, !7, i64 555}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"XByteBuffer", !6, i64 0, !14, i64 8, !14, i64 16, !11, i64 24, !11, i64 26, !12, i64 28}
!14 = !{!"long", !7, i64 0}
!15 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !14, i64 32, !12, i64 40}
!16 = !{!17, !14, i64 48}
!17 = !{!"XArray_", !6, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !14, i64 40, !14, i64 48}
!18 = !{!14, !14, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = distinct !{!23, !21}


; 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.29 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [22 x i8], align 1

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

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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @XHTTPApp_AppendArgHeaders(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca ptr, align 8
  %4 = getelementptr inbounds i8, ptr %1, i64 5024
  %5 = tail call ptr @xstrsplit(ptr noundef nonnull %4, ptr noundef nonnull @.str.29) #3
  %6 = icmp eq ptr %5, null
  br i1 %6, label %28, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 168
  store i8 1, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %5, i64 48
  %10 = load i64, ptr %9, align 8, !tbaa !15
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %.thread
  %.03342 = phi i64 [ %27, %.thread ], [ 0, %7 ]
  %11 = call ptr @XArray_GetData(ptr noundef nonnull %5, i64 noundef %.03342) #3
  %12 = icmp eq ptr %11, null
  br i1 %12, label %.thread, label %13

13:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store ptr null, ptr %3, align 8, !tbaa !17
  %14 = call ptr @xstrtok(ptr noundef nonnull %11, ptr noundef nonnull @.str.30, ptr noundef nonnull %3) #3
  %15 = icmp eq ptr %14, null
  br i1 %15, label %.thread39, label %16

16:                                               ; preds = %13
  %17 = call ptr @xstrtok(ptr noundef null, ptr noundef nonnull @.str.30, ptr noundef nonnull %3) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.thread39, label %.preheader41

.preheader41:                                     ; preds = %16, %.preheader41
  %.028 = phi ptr [ %21, %.preheader41 ], [ %14, %16 ]
  %19 = load i8, ptr %.028, align 1, !tbaa !18
  %20 = icmp eq i8 %19, 32
  %21 = getelementptr inbounds i8, ptr %.028, i64 1
  br i1 %20, label %.preheader41, label %.preheader, !llvm.loop !19

.preheader:                                       ; preds = %.preheader41, %.preheader
  %.0 = phi ptr [ %24, %.preheader ], [ %17, %.preheader41 ]
  %22 = load i8, ptr %.0, align 1, !tbaa !18
  %23 = icmp eq i8 %22, 32
  %24 = getelementptr inbounds i8, ptr %.0, i64 1
  br i1 %23, label %.preheader, label %25, !llvm.loop !21

.thread39:                                        ; preds = %16, %13
  call void @XArray_Destroy(ptr noundef nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %28

25:                                               ; preds = %.preheader
  %26 = call i32 (ptr, ptr, ptr, ...) @XHTTP_AddHeader(ptr noundef %0, ptr noundef nonnull %.028, ptr noundef nonnull @.str.31, ptr noundef nonnull %.0) #3
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef nonnull @.str.32, ptr noundef nonnull %.028, ptr noundef nonnull %.0) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %.thread

.thread:                                          ; preds = %.lr.ph, %25
  %27 = add nuw i64 %.03342, 1
  %exitcond.not = icmp eq i64 %27, %10
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %.thread, %7
  call void @XArray_Destroy(ptr noundef nonnull %5) #3
  br label %28

28:                                               ; preds = %.thread39, %._crit_edge, %2
  %.5 = phi i32 [ -1, %2 ], [ 1, %._crit_edge ], [ -1, %.thread39 ]
  ret i32 %.5
}

declare ptr @xstrsplit(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @XArray_GetData(ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @xstrtok(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @XArray_Destroy(ptr noundef) local_unnamed_addr #1

declare i32 @XHTTP_AddHeader(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { 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, !8, i64 168}
!6 = !{!"xhttp_", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !12, i64 32, !11, i64 64, !14, i64 72, !10, i64 120, !10, i64 122, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !8, i64 168, !8, i64 169, !8, i64 170, !8, i64 171, !8, i64 427, !8, i64 555}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"XByteBuffer", !7, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 26, !11, i64 28}
!13 = !{!"long", !8, i64 0}
!14 = !{!"XMap", !7, i64 0, !7, i64 8, !7, i64 16, !13, i64 24, !13, i64 32, !11, i64 40}
!15 = !{!16, !13, i64 48}
!16 = !{!"XArray_", !7, i64 0, !7, i64 8, !11, i64 16, !7, i64 24, !8, i64 32, !8, i64 33, !8, i64 34, !13, i64 40, !13, i64 48}
!17 = !{!7, !7, i64 0}
!18 = !{!8, !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = distinct !{!22, !20}


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