; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (10-at-a-time)

; 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.CURLMsg = type { i32, ptr, %union.anon }
%union.anon = type { ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 -1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  %10 = call i32 @curl_global_init(i64 noundef 3)
  %11 = call ptr @curl_multi_init()
  store ptr %11, ptr %2, align 8, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !9
  %13 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %12, i32 noundef 6, i64 noundef 10)
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %26, %0
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp ult i32 %15, 10
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = icmp ult i64 %19, 47
  br label %21

21:                                               ; preds = %17, %14
  %22 = phi i1 [ false, %14 ], [ %20, %17 ]
  br i1 %22, label %23, label %29

23:                                               ; preds = %21
  %24 = load ptr, ptr %2, align 8, !tbaa !9
  %25 = load i32, ptr %4, align 4, !tbaa !5
  call void @add_transfer(ptr noundef %24, i32 noundef %25, ptr noundef %6)
  br label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !11

29:                                               ; preds = %21
  br label %30

30:                                               ; preds = %88, %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !9
  %32 = call i32 @curl_multi_perform(ptr noundef %31, ptr noundef %7)
  br label %33

33:                                               ; preds = %80, %30
  %34 = load ptr, ptr %2, align 8, !tbaa !9
  %35 = call ptr @curl_multi_info_read(ptr noundef %34, ptr noundef %5)
  store ptr %35, ptr %3, align 8, !tbaa !9
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %81

37:                                               ; preds = %33
  %38 = load ptr, ptr %3, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.CURLMsg, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !13
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %66

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %43 = load ptr, ptr %3, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.CURLMsg, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  store ptr %45, ptr %9, align 8, !tbaa !9
  %46 = load ptr, ptr %3, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.CURLMsg, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = call i32 (ptr, i32, ...) @curl_easy_getinfo(ptr noundef %48, i32 noundef 1048597, ptr noundef %8)
  %50 = load ptr, ptr @stderr, align 8, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.CURLMsg, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !16
  %54 = load ptr, ptr %3, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.CURLMsg, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !16
  %57 = call ptr @curl_easy_strerror(i32 noundef %56)
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str, i32 noundef %53, ptr noundef %57, ptr noundef %58) #4
  %60 = load ptr, ptr %2, align 8, !tbaa !9
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = call i32 @curl_multi_remove_handle(ptr noundef %60, ptr noundef %61)
  %63 = load ptr, ptr %9, align 8, !tbaa !9
  call void @curl_easy_cleanup(ptr noundef %63)
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, -1
  store i32 %65, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %72

66:                                               ; preds = %37
  %67 = load ptr, ptr @stderr, align 8, !tbaa !9
  %68 = load ptr, ptr %3, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.CURLMsg, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !13
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.1, i32 noundef %70) #4
  br label %72

72:                                               ; preds = %66, %42
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = zext i32 %73 to i64
  %75 = icmp ult i64 %74, 47
  br i1 %75, label %76, label %80

76:                                               ; preds = %72
  %77 = load ptr, ptr %2, align 8, !tbaa !9
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = add i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !5
  call void @add_transfer(ptr noundef %77, i32 noundef %78, ptr noundef %6)
  br label %80

80:                                               ; preds = %76, %72
  br label %33, !llvm.loop !17

81:                                               ; preds = %33
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %87

84:                                               ; preds = %81
  %85 = load ptr, ptr %2, align 8, !tbaa !9
  %86 = call i32 @curl_multi_wait(ptr noundef %85, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null)
  br label %87

87:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %30, label %91, !llvm.loop !18

91:                                               ; preds = %88
  %92 = load ptr, ptr %2, align 8, !tbaa !9
  %93 = call i32 @curl_multi_cleanup(ptr noundef %92)
  call void @curl_global_cleanup()
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

declare i32 @curl_global_init(i64 noundef) #2

declare ptr @curl_multi_init() #2

declare i32 @curl_multi_setopt(ptr noundef, i32 noundef, ...) #2

; Function Attrs: nounwind uwtable
declare hidden void @add_transfer(ptr noundef, i32 noundef, ptr noundef) #0

declare i32 @curl_multi_perform(ptr noundef, ptr noundef) #2

declare ptr @curl_multi_info_read(ptr noundef, ptr noundef) #2

declare i32 @curl_easy_getinfo(ptr noundef, i32 noundef, ...) #2

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

declare ptr @curl_easy_strerror(i32 noundef) #2

declare i32 @curl_multi_remove_handle(ptr noundef, ptr noundef) #2

declare void @curl_easy_cleanup(ptr noundef) #2

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

declare i32 @curl_multi_wait(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #2

declare i32 @curl_multi_cleanup(ptr noundef) #2

declare void @curl_global_cleanup() #2

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 = { "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 = { 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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"CURLMsg", !6, i64 0, !10, i64 8, !7, i64 16}
!15 = !{!14, !10, i64 8}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !12}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader.preheader:
  %0 = alloca i32, align 4
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #4
  store i32 -1, ptr %0, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  %4 = tail call i32 @curl_global_init(i64 noundef 3) #4
  %5 = tail call ptr @curl_multi_init() #4
  %6 = tail call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %5, i32 noundef 6, i64 noundef 10) #4
  call void @add_transfer(ptr noundef %5, i32 noundef 0, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 1, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 2, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 3, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 4, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 5, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 6, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 7, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 8, ptr noundef nonnull %1)
  call void @add_transfer(ptr noundef %5, i32 noundef 9, ptr noundef nonnull %1)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %35
  %.1 = phi i32 [ %.2.lcssa, %35 ], [ 10, %.preheader.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  %7 = call i32 @curl_multi_perform(ptr noundef %5, ptr noundef nonnull %2) #4
  %8 = call ptr @curl_multi_info_read(ptr noundef %5, ptr noundef nonnull %0) #4
  %.not27 = icmp eq ptr %8, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %32
  %9 = phi ptr [ %33, %32 ], [ %8, %.preheader ]
  %.228 = phi i32 [ %.3, %32 ], [ %.1, %.preheader ]
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %25

12:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %13 = getelementptr inbounds i8, ptr %9, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = call i32 (ptr, i32, ...) @curl_easy_getinfo(ptr noundef %14, i32 noundef 1048597, ptr noundef nonnull %3) #4
  %16 = load ptr, ptr @stderr, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %9, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = call ptr @curl_easy_strerror(i32 noundef %18) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !13
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, i32 noundef %18, ptr noundef %19, ptr noundef %20) #5
  %22 = call i32 @curl_multi_remove_handle(ptr noundef %5, ptr noundef %14) #4
  call void @curl_easy_cleanup(ptr noundef %14) #4
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  br label %28

25:                                               ; preds = %.lr.ph
  %26 = load ptr, ptr @stderr, align 8, !tbaa !13
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.1, i32 noundef %10) #5
  br label %28

28:                                               ; preds = %25, %12
  %29 = icmp ult i32 %.228, 47
  br i1 %29, label %30, label %32

30:                                               ; preds = %28
  %31 = add nuw nsw i32 %.228, 1
  call void @add_transfer(ptr noundef %5, i32 noundef %.228, ptr noundef nonnull %1)
  br label %32

32:                                               ; preds = %30, %28
  %.3 = phi i32 [ %31, %30 ], [ %.228, %28 ]
  %33 = call ptr @curl_multi_info_read(ptr noundef %5, ptr noundef nonnull %0) #4
  %.not = icmp eq ptr %33, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %32, %.preheader
  %.2.lcssa = phi i32 [ %.1, %.preheader ], [ %.3, %32 ]
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %.not23 = icmp eq i32 %34, 0
  br i1 %.not23, label %.thread, label %35

.thread:                                          ; preds = %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %.loopexit

35:                                               ; preds = %._crit_edge
  %36 = call i32 @curl_multi_wait(ptr noundef %5, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null) #4
  %.pr = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  %.not24 = icmp eq i32 %.pr, 0
  br i1 %.not24, label %.loopexit, label %.preheader, !llvm.loop !17

.loopexit:                                        ; preds = %35, %.thread
  %37 = call i32 @curl_multi_cleanup(ptr noundef %5) #4
  call void @curl_global_cleanup() #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #4
  ret i32 0
}

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

declare i32 @curl_global_init(i64 noundef) local_unnamed_addr #2

declare ptr @curl_multi_init() local_unnamed_addr #2

declare i32 @curl_multi_setopt(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @add_transfer(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare i32 @curl_multi_perform(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @curl_multi_info_read(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @curl_easy_getinfo(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare ptr @curl_easy_strerror(i32 noundef) local_unnamed_addr #2

declare i32 @curl_multi_remove_handle(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @curl_easy_cleanup(ptr noundef) local_unnamed_addr #2

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

declare i32 @curl_multi_wait(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @curl_multi_cleanup(ptr noundef) local_unnamed_addr #2

declare void @curl_global_cleanup() local_unnamed_addr #2

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


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