; LLVM IR from ohler55/agoo :: ext/agoo (response)

; 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._agooResponse = type { i32, ptr, i32, ptr }
%struct._agooHeader = type { ptr, i32, [8 x i8] }

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

declare ptr @agoo_http_code_message(i32 noundef) #1

; 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
define dso_local void @agoo_response_fill(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._agooResponse, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = call ptr @agoo_http_code_message(i32 noundef %9)
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._agooResponse, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._agooResponse, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !12
  %19 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %11, ptr noundef @.str, i32 noundef %14, ptr noundef %15, i32 noundef %18) #5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  store ptr %22, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._agooResponse, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  store ptr %25, ptr %5, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %45, %2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = icmp ne ptr null, %27
  br i1 %28, label %29, label %49

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._agooHeader, ptr %31, i32 0, i32 2
  %33 = getelementptr inbounds [8 x i8], ptr %32, i64 0, i64 0
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._agooHeader, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !14
  %37 = sext i32 %36 to i64
  %38 = call ptr @strncpy(ptr noundef %30, ptr noundef %33, i64 noundef %37) #5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._agooHeader, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !14
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  store ptr %44, ptr %4, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %29
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._agooHeader, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  store ptr %48, ptr %5, align 8, !tbaa !5
  br label %26, !llvm.loop !17

49:                                               ; preds = %26
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %4, align 8, !tbaa !5
  store i8 13, ptr %50, align 1, !tbaa !19
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i32 1
  store ptr %53, ptr %4, align 8, !tbaa !5
  store i8 10, ptr %52, align 1, !tbaa !19
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._agooResponse, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !20
  %57 = icmp ne ptr null, %56
  br i1 %57, label %58, label %73

58:                                               ; preds = %49
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._agooResponse, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._agooResponse, ptr %63, i32 0, i32 2
  %65 = load i32, ptr %64, align 8, !tbaa !12
  %66 = sext i32 %65 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %59, ptr align 1 %62, i64 %66, i1 false)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._agooResponse, ptr %67, i32 0, i32 2
  %69 = load i32, ptr %68, align 8, !tbaa !12
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds i8, ptr %70, i64 %71
  store ptr %72, ptr %4, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %58, %49
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 0, ptr %74, align 1, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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 "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !11, i64 0}
!10 = !{!"_agooResponse", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !11, i64 8}
!15 = !{!"_agooHeader", !6, i64 0, !11, i64 8, !7, i64 12}
!16 = !{!15, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!7, !7, i64 0}
!20 = !{!10, !6, i64 24}


; 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 = external hidden unnamed_addr constant [37 x i8], align 1

declare ptr @agoo_http_code_message(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @agoo_response_fill(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = tail call ptr @agoo_http_code_message(i32 noundef %3) #5
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %5, ptr noundef %4, i32 noundef %7) #5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %1, i64 %9
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %.02326 = load ptr, ptr %11, align 8, !tbaa !12
  %.not27 = icmp eq ptr %.02326, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.02329 = phi ptr [ %.023, %.lr.ph ], [ %.02326, %2 ]
  %.028 = phi ptr [ %19, %.lr.ph ], [ %10, %2 ]
  %12 = getelementptr inbounds i8, ptr %.02329, i64 12
  %13 = getelementptr inbounds i8, ptr %.02329, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = sext i32 %14 to i64
  %16 = tail call ptr @strncpy(ptr noundef %.028, ptr noundef nonnull %12, i64 noundef %15) #5
  %17 = load i32, ptr %13, align 8, !tbaa !13
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %.028, i64 %18
  %.023 = load ptr, ptr %.02329, align 8, !tbaa !12
  %.not = icmp eq ptr %.023, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.0.lcssa = phi ptr [ %10, %2 ], [ %19, %.lr.ph ]
  %20 = getelementptr inbounds i8, ptr %.0.lcssa, i64 1
  store i8 13, ptr %.0.lcssa, align 1, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %.0.lcssa, i64 2
  store i8 10, ptr %20, align 1, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %.not25 = icmp eq ptr %23, null
  br i1 %.not25, label %30, label %24

24:                                               ; preds = %._crit_edge
  %25 = load i32, ptr %6, align 8, !tbaa !11
  %26 = sext i32 %25 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %21, ptr nonnull align 1 %23, i64 %26, i1 false)
  %27 = load i32, ptr %6, align 8, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %21, i64 %28
  br label %30

30:                                               ; preds = %24, %._crit_edge
  %.1 = phi ptr [ %29, %24 ], [ %21, %._crit_edge ]
  store i8 0, ptr %.1, align 1, !tbaa !17
  ret void
}

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

; 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 #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #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 = { 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 = { 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 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !7, i64 0}
!6 = !{!"_agooResponse", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !7, i64 8}
!14 = !{!"_agooHeader", !10, i64 0, !7, i64 8, !8, i64 12}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!8, !8, i64 0}
!18 = !{!6, !10, i64 24}


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