; LLVM IR from dynexcoin/Dynex :: external/miniupnpc (minihttptestserver)

; 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"

@.str.2 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @build_content(ptr noundef, i64 noundef) #0

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

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @build_chunked_response(i64 noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = add i64 256, %12
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = lshr i64 %14, 4
  %16 = add i64 %13, %15
  store i64 %16, ptr %8, align 8, !tbaa !5
  %17 = load i64, ptr %8, align 8, !tbaa !5
  %18 = call noalias ptr @malloc(i64 noundef %17) #7
  store ptr %18, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %114

22:                                               ; preds = %2
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = load i64, ptr %8, align 8, !tbaa !5
  %25 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %23, i64 noundef %24, ptr noundef @.str.2) #6
  %26 = sext i32 %25 to i64
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  store i64 %26, ptr %27, align 8, !tbaa !5
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = call noalias ptr @malloc(i64 noundef %28) #7
  store ptr %29, ptr %7, align 8, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %34

32:                                               ; preds = %22
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %33) #6
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %114

34:                                               ; preds = %22
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load i64, ptr %4, align 8, !tbaa !5
  call void @build_content(ptr noundef %35, i64 noundef %36)
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %56, %34
  %38 = load i64, ptr %9, align 8, !tbaa !5
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %41, label %99

41:                                               ; preds = %37
  %42 = call i32 @rand() #6
  %43 = srem i32 %42, 199
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %10, align 4, !tbaa !11
  %45 = load i64, ptr %9, align 8, !tbaa !5
  %46 = load i32, ptr %10, align 4, !tbaa !11
  %47 = zext i32 %46 to i64
  %48 = add i64 %45, %47
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = icmp ugt i64 %48, %49
  br i1 %50, label %51, label %56

51:                                               ; preds = %41
  %52 = load i64, ptr %4, align 8, !tbaa !5
  %53 = load i64, ptr %9, align 8, !tbaa !5
  %54 = sub i64 %52, %53
  %55 = trunc i64 %54 to i32
  store i32 %55, ptr %10, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %51, %41
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = load i64, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  %61 = load i64, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = load i64, ptr %62, align 8, !tbaa !5
  %64 = sub i64 %61, %63
  %65 = load i32, ptr %10, align 4, !tbaa !11
  %66 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %60, i64 noundef %64, ptr noundef @.str.3, i32 noundef %65) #6
  %67 = sext i32 %66 to i64
  %68 = load ptr, ptr %5, align 8, !tbaa !9
  %69 = load i64, ptr %68, align 8, !tbaa !5
  %70 = add i64 %69, %67
  store i64 %70, ptr %68, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !9
  %72 = load ptr, ptr %5, align 8, !tbaa !9
  %73 = load i64, ptr %72, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load ptr, ptr %7, align 8, !tbaa !9
  %76 = load i64, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %75, i64 %76
  %78 = load i32, ptr %10, align 4, !tbaa !11
  %79 = zext i32 %78 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %74, ptr align 1 %77, i64 %79, i1 false)
  %80 = load i32, ptr %10, align 4, !tbaa !11
  %81 = zext i32 %80 to i64
  %82 = load ptr, ptr %5, align 8, !tbaa !9
  %83 = load i64, ptr %82, align 8, !tbaa !5
  %84 = add i64 %83, %81
  store i64 %84, ptr %82, align 8, !tbaa !5
  %85 = load i32, ptr %10, align 4, !tbaa !11
  %86 = zext i32 %85 to i64
  %87 = load i64, ptr %9, align 8, !tbaa !5
  %88 = add i64 %87, %86
  store i64 %88, ptr %9, align 8, !tbaa !5
  %89 = load ptr, ptr %6, align 8, !tbaa !9
  %90 = load ptr, ptr %5, align 8, !tbaa !9
  %91 = load i64, ptr %90, align 8, !tbaa !5
  %92 = add i64 %91, 1
  store i64 %92, ptr %90, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %89, i64 %91
  store i8 13, ptr %93, align 1, !tbaa !13
  %94 = load ptr, ptr %6, align 8, !tbaa !9
  %95 = load ptr, ptr %5, align 8, !tbaa !9
  %96 = load i64, ptr %95, align 8, !tbaa !5
  %97 = add i64 %96, 1
  store i64 %97, ptr %95, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %94, i64 %96
  store i8 10, ptr %98, align 1, !tbaa !13
  br label %37, !llvm.loop !14

99:                                               ; preds = %37
  %100 = load ptr, ptr %6, align 8, !tbaa !9
  %101 = load ptr, ptr %5, align 8, !tbaa !9
  %102 = load i64, ptr %101, align 8, !tbaa !5
  %103 = getelementptr inbounds i8, ptr %100, i64 %102
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %103, ptr align 1 @.str.4, i64 5, i1 false)
  %104 = load ptr, ptr %5, align 8, !tbaa !9
  %105 = load i64, ptr %104, align 8, !tbaa !5
  %106 = add i64 %105, 5
  store i64 %106, ptr %104, align 8, !tbaa !5
  %107 = load ptr, ptr %7, align 8, !tbaa !9
  call void @free(ptr noundef %107) #6
  %108 = load ptr, ptr %5, align 8, !tbaa !9
  %109 = load i64, ptr %108, align 8, !tbaa !5
  %110 = load i64, ptr %8, align 8, !tbaa !5
  %111 = load i64, ptr %4, align 8, !tbaa !5
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i64 noundef %109, i64 noundef %110, i64 noundef %111)
  %113 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %113, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %114

114:                                              ; preds = %99, %32, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %115 = load ptr, ptr %3, align 8
  ret ptr %115
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

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

; Function Attrs: nounwind
declare i32 @rand() #2

declare i32 @printf(ptr noundef, ...) #5

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 "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(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 #5 = { "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 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

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

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

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @build_chunked_response(i64 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = add i64 %0, 256
  %4 = lshr i64 %0, 4
  %5 = add i64 %3, %4
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #6
  %7 = icmp eq ptr %6, null
  br i1 %7, label %42, label %8

8:                                                ; preds = %2
  %9 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %6, i64 noundef %5, ptr noundef nonnull @.str.2) #7
  %10 = sext i32 %9 to i64
  store i64 %10, ptr %1, align 8, !tbaa !5
  %11 = tail call noalias ptr @malloc(i64 noundef %0) #6
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  tail call void @free(ptr noundef nonnull %6) #7
  br label %42

14:                                               ; preds = %8
  tail call void @build_content(ptr noundef nonnull %11, i64 noundef %0)
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %.._crit_edge_crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %14
  %invariant.gep = getelementptr i8, ptr %6, i64 1
  br label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %14
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.04651 = phi i64 [ %34, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %15 = tail call i32 @rand() #7
  %16 = srem i32 %15, 199
  %17 = add nsw i32 %16, 1
  %18 = zext i32 %17 to i64
  %19 = add i64 %.04651, %18
  %20 = icmp ugt i64 %19, %0
  %21 = sub i64 %0, %.04651
  %22 = trunc i64 %21 to i32
  %.0 = select i1 %20, i32 %22, i32 %17
  %23 = load i64, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %6, i64 %23
  %25 = sub i64 %5, %23
  %26 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %24, i64 noundef %25, ptr noundef nonnull @.str.3, i32 noundef %.0) #7
  %27 = sext i32 %26 to i64
  %28 = load i64, ptr %1, align 8, !tbaa !5
  %29 = add i64 %28, %27
  %30 = getelementptr inbounds i8, ptr %6, i64 %29
  %31 = getelementptr inbounds i8, ptr %11, i64 %.04651
  %32 = zext i32 %.0 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %30, ptr nonnull align 1 %31, i64 %32, i1 false)
  %33 = add i64 %29, %32
  %34 = add i64 %.04651, %32
  %35 = getelementptr inbounds i8, ptr %6, i64 %33
  store i8 13, ptr %35, align 1, !tbaa !9
  %36 = add i64 %33, 2
  store i64 %36, ptr %1, align 8, !tbaa !5
  %gep = getelementptr i8, ptr %invariant.gep, i64 %33
  store i8 10, ptr %gep, align 1, !tbaa !9
  %37 = icmp ult i64 %34, %0
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %38 = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %36, %.lr.ph ]
  %39 = getelementptr inbounds i8, ptr %6, i64 %38
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %39, ptr noundef nonnull align 1 dereferenceable(5) @.str.4, i64 5, i1 false)
  %40 = add i64 %38, 5
  store i64 %40, ptr %1, align 8, !tbaa !5
  tail call void @free(ptr noundef %11) #7
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i64 noundef %40, i64 noundef %5, i64 noundef %0)
  br label %42

42:                                               ; preds = %2, %._crit_edge, %13
  %.047 = phi ptr [ null, %13 ], [ %6, %._crit_edge ], [ null, %2 ]
  ret ptr %.047
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) 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 #4 = { 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 #5 = { 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 = { nounwind allocsize(0) }
attributes #7 = { 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 = !{!"long", !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"}


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