; LLVM IR from kala13x/libxutils :: src/net (http)

; 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_ = 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.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.XMap = type { ptr, ptr, ptr, i64, i64, i32 }

@.str.29 = external hidden unnamed_addr constant [4 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XHTTP_Init(ptr noundef, i32 noundef, i64 noundef) #1

declare i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @XHTTP_InitResponse(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i32 @XHTTP_Init(ptr noundef %11, i32 noundef 0, i64 noundef 4096)
  store i32 %12, ptr %8, align 4, !tbaa !11
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = icmp sle i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %35

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  br label %22

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21, %19
  %23 = phi ptr [ %20, %19 ], [ @.str.29, %21 ]
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xhttp_, ptr %24, i32 0, i32 18
  %26 = getelementptr inbounds [128 x i8], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = call i64 @xstrncpy(ptr noundef %26, i64 noundef 128, ptr noundef %27)
  %29 = load i16, ptr %6, align 2, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.xhttp_, ptr %30, i32 0, i32 8
  store i16 %29, ptr %31, align 2, !tbaa !13
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.xhttp_, ptr %32, i32 0, i32 5
  store i32 2, ptr %33, align 8, !tbaa !18
  %34 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %34, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %35

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 122}
!14 = !{!"xhttp_", !6, i64 0, !10, i64 8, !6, i64 16, !12, i64 24, !15, i64 32, !12, i64 64, !17, i64 72, !10, i64 120, !10, i64 122, !16, i64 128, !16, i64 136, !16, i64 144, !16, i64 152, !16, i64 160, !7, i64 168, !7, i64 169, !7, i64 170, !7, i64 171, !7, i64 427, !7, i64 555}
!15 = !{!"XByteBuffer", !6, i64 0, !16, i64 8, !16, i64 16, !10, i64 24, !10, i64 26, !12, i64 28}
!16 = !{!"long", !7, i64 0}
!17 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !16, i64 24, !16, i64 32, !12, i64 40}
!18 = !{!14, !12, 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.29 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @XHTTP_InitResponse(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @XHTTP_Init(ptr noundef %0, i32 noundef 0, i64 noundef 4096)
  %5 = icmp slt i32 %4, 1
  br i1 %5, label %12, label %6

6:                                                ; preds = %3
  %.not = icmp eq ptr %2, null
  %7 = select i1 %.not, ptr @.str.29, ptr %2
  %8 = getelementptr inbounds i8, ptr %0, i64 427
  %9 = tail call i64 @xstrncpy(ptr noundef nonnull %8, i64 noundef 128, ptr noundef nonnull %7) #2
  %10 = getelementptr inbounds i8, ptr %0, i64 122
  store i16 %1, ptr %10, align 2, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 2, ptr %11, align 8, !tbaa !15
  br label %12

12:                                               ; preds = %3, %6
  %.0 = phi i32 [ %4, %6 ], [ -1, %3 ]
  ret i32 %.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 = { 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, !10, i64 122}
!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 = !{!6, !11, i64 64}


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