; 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.31 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [9 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 zeroext i8 @xstrused(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XHTTP_SetAuthBasic(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca [1024 x i8], align 16
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call zeroext i8 @xstrused(ptr noundef %14)
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call zeroext i8 @xstrused(ptr noundef %18)
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %17, %3
  store i32 0, ptr %4, align 4
  br label %47

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.xhttp_, ptr %23, i32 0, i32 14
  %25 = load i8, ptr %24, align 8, !tbaa !9
  store i8 %25, ptr %8, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %26 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %26, i64 noundef 1024, ptr noundef @.str.31, ptr noundef %27, ptr noundef %28)
  store i64 %29, ptr %11, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %30 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %31 = call ptr @XBase64_Encrypt(ptr noundef %30, ptr noundef %11)
  store ptr %31, ptr %12, align 8, !tbaa !5
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %22
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %46

35:                                               ; preds = %22
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.xhttp_, ptr %36, i32 0, i32 14
  store i8 1, ptr %37, align 8, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = call i32 (ptr, ptr, ptr, ...) @XHTTP_AddHeader(ptr noundef %38, ptr noundef @.str.32, ptr noundef @.str.33, ptr noundef %39)
  store i32 %40, ptr %10, align 4, !tbaa !17
  %41 = load i8, ptr %8, align 1, !tbaa !16
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.xhttp_, ptr %42, i32 0, i32 14
  store i8 %41, ptr %43, align 8, !tbaa !9
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %44) #4
  %45 = load i32, ptr %10, align 4, !tbaa !17
  store i32 %45, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %46

46:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  br label %47

47:                                               ; preds = %46, %21
  %48 = load i32, ptr %4, align 4
  ret i32 %48
}

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 "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 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 #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, !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 = !{!7, !7, i64 0}
!17 = !{!12, !12, i64 0}
!18 = !{!14, !14, i64 0}


; 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.31 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [9 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 zeroext i8 @xstrused(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @XHTTP_AddHeader(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #3

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XHTTP_SetAuthBasic(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca [1024 x i8], align 16
  %5 = alloca i64, align 8
  %6 = tail call zeroext i8 @xstrused(ptr noundef %1) #4
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %18, label %7

7:                                                ; preds = %3
  %8 = tail call zeroext i8 @xstrused(ptr noundef %2) #4
  %.not14 = icmp eq i8 %8, 0
  br i1 %.not14, label %18, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 168
  %11 = load i8, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %12 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %4, i64 noundef 1024, ptr noundef nonnull @.str.31, ptr noundef %1, ptr noundef %2) #4
  store i64 %12, ptr %5, align 8, !tbaa !15
  %13 = call ptr @XBase64_Encrypt(ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %14 = icmp eq ptr %13, null
  br i1 %14, label %17, label %15

15:                                               ; preds = %9
  store i8 1, ptr %10, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ptr, ...) @XHTTP_AddHeader(ptr noundef nonnull %0, ptr noundef nonnull @.str.32, ptr noundef nonnull @.str.33, ptr noundef nonnull %13)
  store i8 %11, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef nonnull %13) #4
  br label %17

17:                                               ; preds = %9, %15
  %.0 = phi i32 [ %16, %15 ], [ -1, %9 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %4) #4
  br label %18

18:                                               ; preds = %3, %7, %17
  %.1 = phi i32 [ %.0, %17 ], [ 0, %7 ], [ 0, %3 ]
  ret i32 %.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 = { mustprogress nounwind willreturn allockind("free") 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 = { 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 #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, !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 = !{!13, !13, i64 0}


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