; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (multithread)

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

@urls = external dso_local constant [4 x ptr], align 16
@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [4 x i64], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %9 = call i32 @curl_global_init(i64 noundef 3)
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %38, %2
  %11 = load i32, ptr %7, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 4
  br i1 %12, label %13, label %41

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 %15
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4 x ptr], ptr @urls, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = call i32 @pthread_create(ptr noundef %16, ptr noundef null, ptr noundef @pull_one_url, ptr noundef %20) #4
  store i32 %21, ptr %8, align 4, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = icmp ne i32 0, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %13
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.4, i32 noundef %26, i32 noundef %27) #4
  br label %37

29:                                               ; preds = %13
  %30 = load ptr, ptr @stderr, align 8, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [4 x ptr], ptr @urls, i64 0, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.5, i32 noundef %31, ptr noundef %35) #4
  br label %37

37:                                               ; preds = %29, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !5
  br label %10, !llvm.loop !11

41:                                               ; preds = %10
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %54, %41
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = icmp slt i32 %43, 4
  br i1 %44, label %45, label %57

45:                                               ; preds = %42
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = call i32 @pthread_join(i64 noundef %49, ptr noundef null)
  %51 = load ptr, ptr @stderr, align 8, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str.6, i32 noundef %52) #4
  br label %54

54:                                               ; preds = %45
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %7, align 4, !tbaa !5
  br label %42, !llvm.loop !15

57:                                               ; preds = %42
  call void @curl_global_cleanup()
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @pull_one_url(ptr noundef) #0

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

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

declare i32 @pthread_join(i64 noundef, 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, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !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"

@urls = external dso_local local_unnamed_addr constant [4 x ptr], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca [4 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  %4 = tail call i32 @curl_global_init(i64 noundef 3) #5
  %5 = load ptr, ptr @urls, align 16, !tbaa !5
  %6 = call i32 @pthread_create(ptr noundef nonnull %3, ptr noundef null, ptr noundef nonnull @pull_one_url, ptr noundef %5) #5
  %.not = icmp eq i32 %6, 0
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  br i1 %.not, label %10, label %8

8:                                                ; preds = %2
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.4, i32 noundef 0, i32 noundef %6) #6
  br label %12

10:                                               ; preds = %2
  %11 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.5, i32 noundef 0, ptr noundef %5) #6
  br label %12

12:                                               ; preds = %10, %8
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @urls, i64 8), align 8, !tbaa !5
  %15 = call i32 @pthread_create(ptr noundef nonnull %13, ptr noundef null, ptr noundef nonnull @pull_one_url, ptr noundef %14) #5
  %.not.1 = icmp eq i32 %15, 0
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  br i1 %.not.1, label %19, label %17

17:                                               ; preds = %12
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.4, i32 noundef 1, i32 noundef %15) #6
  br label %21

19:                                               ; preds = %12
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.5, i32 noundef 1, ptr noundef %14) #6
  br label %21

21:                                               ; preds = %19, %17
  %22 = getelementptr inbounds i8, ptr %3, i64 16
  %23 = load ptr, ptr getelementptr inbounds (i8, ptr @urls, i64 16), align 16, !tbaa !5
  %24 = call i32 @pthread_create(ptr noundef nonnull %22, ptr noundef null, ptr noundef nonnull @pull_one_url, ptr noundef %23) #5
  %.not.2 = icmp eq i32 %24, 0
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  br i1 %.not.2, label %28, label %26

26:                                               ; preds = %21
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.4, i32 noundef 2, i32 noundef %24) #6
  br label %30

28:                                               ; preds = %21
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.5, i32 noundef 2, ptr noundef %23) #6
  br label %30

30:                                               ; preds = %28, %26
  %31 = getelementptr inbounds i8, ptr %3, i64 24
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @urls, i64 24), align 8, !tbaa !5
  %33 = call i32 @pthread_create(ptr noundef nonnull %31, ptr noundef null, ptr noundef nonnull @pull_one_url, ptr noundef %32) #5
  %.not.3 = icmp eq i32 %33, 0
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  br i1 %.not.3, label %37, label %35

35:                                               ; preds = %30
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.4, i32 noundef 3, i32 noundef %33) #6
  br label %.preheader.preheader

37:                                               ; preds = %30
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.5, i32 noundef 3, ptr noundef %32) #6
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %37, %35
  %39 = load i64, ptr %3, align 16, !tbaa !9
  %40 = call i32 @pthread_join(i64 noundef %39, ptr noundef null) #5
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.6, i32 noundef 0) #6
  %43 = load i64, ptr %13, align 8, !tbaa !9
  %44 = call i32 @pthread_join(i64 noundef %43, ptr noundef null) #5
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef nonnull @.str.6, i32 noundef 1) #6
  %47 = load i64, ptr %22, align 16, !tbaa !9
  %48 = call i32 @pthread_join(i64 noundef %47, ptr noundef null) #5
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef nonnull @.str.6, i32 noundef 2) #6
  %51 = load i64, ptr %31, align 8, !tbaa !9
  %52 = call i32 @pthread_join(i64 noundef %51, ptr noundef null) #5
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef nonnull @.str.6, i32 noundef 3) #6
  call void @curl_global_cleanup() #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  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

; Function Attrs: nounwind
declare i32 @pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden ptr @pull_one_url(ptr noundef) #0

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

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

declare i32 @pthread_join(i64 noundef, 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 = { 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 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass