; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (shared-connection-cache)

; 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 = external hidden unnamed_addr constant [17 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [32 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 i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  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 4, ptr %3) #4
  %6 = call ptr @curl_share_init()
  store ptr %6, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call i32 (ptr, i32, ...) @curl_share_setopt(ptr noundef %7, i32 noundef 1, i32 noundef 5)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call i32 (ptr, i32, ...) @curl_share_setopt(ptr noundef %9, i32 noundef 3, ptr noundef @my_lock)
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call i32 (ptr, i32, ...) @curl_share_setopt(ptr noundef %11, i32 noundef 4, ptr noundef @my_unlock)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %38, %0
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 3
  br i1 %15, label %16, label %41

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %17 = call ptr @curl_easy_init()
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %37

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %21, i32 noundef 10002, ptr noundef @.str)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %23, i32 noundef 10100, ptr noundef %24)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call i32 @curl_easy_perform(ptr noundef %26)
  store i32 %27, ptr %5, align 4, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %20
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = call ptr @curl_easy_strerror(i32 noundef %32)
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.1, ptr noundef %33) #4
  br label %35

35:                                               ; preds = %30, %20
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  call void @curl_easy_cleanup(ptr noundef %36)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %37

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

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

41:                                               ; preds = %13
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = call i32 @curl_share_cleanup(ptr noundef %42)
  call void @llvm.lifetime.end.p0(i64 4, 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 ptr @curl_share_init() #2

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

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

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

declare ptr @curl_easy_init() #2

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

declare i32 @curl_easy_perform(ptr noundef) #2

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

declare ptr @curl_easy_strerror(i32 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_share_cleanup(ptr noundef) #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 = external hidden unnamed_addr constant [17 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call ptr @curl_share_init() #3
  %2 = tail call i32 (ptr, i32, ...) @curl_share_setopt(ptr noundef %1, i32 noundef 1, i32 noundef 5) #3
  %3 = tail call i32 (ptr, i32, ...) @curl_share_setopt(ptr noundef %1, i32 noundef 3, ptr noundef nonnull @my_lock) #3
  %4 = tail call i32 (ptr, i32, ...) @curl_share_setopt(ptr noundef %1, i32 noundef 4, ptr noundef nonnull @my_unlock) #3
  %5 = tail call ptr @curl_easy_init() #3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %15, label %6

6:                                                ; preds = %0
  %7 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %5, i32 noundef 10002, ptr noundef nonnull @.str) #3
  %8 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %5, i32 noundef 10100, ptr noundef %1) #3
  %9 = tail call i32 @curl_easy_perform(ptr noundef nonnull %5) #3
  %.not15 = icmp eq i32 %9, 0
  br i1 %.not15, label %14, label %10

10:                                               ; preds = %6
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call ptr @curl_easy_strerror(i32 noundef %9) #3
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.1, ptr noundef %12) #4
  br label %14

14:                                               ; preds = %10, %6
  tail call void @curl_easy_cleanup(ptr noundef nonnull %5) #3
  br label %15

15:                                               ; preds = %14, %0
  %16 = tail call ptr @curl_easy_init() #3
  %.not.1 = icmp eq ptr %16, null
  br i1 %.not.1, label %26, label %17

17:                                               ; preds = %15
  %18 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %16, i32 noundef 10002, ptr noundef nonnull @.str) #3
  %19 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %16, i32 noundef 10100, ptr noundef %1) #3
  %20 = tail call i32 @curl_easy_perform(ptr noundef nonnull %16) #3
  %.not15.1 = icmp eq i32 %20, 0
  br i1 %.not15.1, label %25, label %21

21:                                               ; preds = %17
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = tail call ptr @curl_easy_strerror(i32 noundef %20) #3
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.1, ptr noundef %23) #4
  br label %25

25:                                               ; preds = %21, %17
  tail call void @curl_easy_cleanup(ptr noundef nonnull %16) #3
  br label %26

26:                                               ; preds = %25, %15
  %27 = tail call ptr @curl_easy_init() #3
  %.not.2 = icmp eq ptr %27, null
  br i1 %.not.2, label %37, label %28

28:                                               ; preds = %26
  %29 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %27, i32 noundef 10002, ptr noundef nonnull @.str) #3
  %30 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %27, i32 noundef 10100, ptr noundef %1) #3
  %31 = tail call i32 @curl_easy_perform(ptr noundef nonnull %27) #3
  %.not15.2 = icmp eq i32 %31, 0
  br i1 %.not15.2, label %36, label %32

32:                                               ; preds = %28
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = tail call ptr @curl_easy_strerror(i32 noundef %31) #3
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str.1, ptr noundef %34) #4
  br label %36

36:                                               ; preds = %32, %28
  tail call void @curl_easy_cleanup(ptr noundef nonnull %27) #3
  br label %37

37:                                               ; preds = %36, %26
  %38 = tail call i32 @curl_share_cleanup(ptr noundef %1) #3
  ret i32 0
}

declare ptr @curl_share_init() local_unnamed_addr #1

declare i32 @curl_share_setopt(ptr noundef, i32 noundef, ...) local_unnamed_addr #1

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

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

declare ptr @curl_easy_init() local_unnamed_addr #1

declare i32 @curl_easy_setopt(ptr noundef, i32 noundef, ...) local_unnamed_addr #1

declare i32 @curl_easy_perform(ptr noundef) local_unnamed_addr #1

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

declare ptr @curl_easy_strerror(i32 noundef) local_unnamed_addr #1

declare void @curl_easy_cleanup(ptr noundef) local_unnamed_addr #1

declare i32 @curl_share_cleanup(ptr noundef) 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 = { "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 = { nounwind }
attributes #4 = { 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"}


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