; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (imap-multi)

; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [37 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  %7 = call i32 @curl_global_init(i64 noundef 3)
  %8 = call ptr @curl_easy_init()
  store ptr %8, ptr %2, align 8, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %53

12:                                               ; preds = %0
  %13 = call ptr @curl_multi_init()
  store ptr %13, ptr %3, align 8, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %53

17:                                               ; preds = %12
  %18 = load ptr, ptr %2, align 8, !tbaa !9
  %19 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %18, i32 noundef 10173, ptr noundef @.str)
  %20 = load ptr, ptr %2, align 8, !tbaa !9
  %21 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %20, i32 noundef 10174, ptr noundef @.str.1)
  %22 = load ptr, ptr %2, align 8, !tbaa !9
  %23 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %22, i32 noundef 10002, ptr noundef @.str.2)
  %24 = load ptr, ptr %3, align 8, !tbaa !9
  %25 = load ptr, ptr %2, align 8, !tbaa !9
  %26 = call i32 @curl_multi_add_handle(ptr noundef %24, ptr noundef %25)
  br label %27

27:                                               ; preds = %43, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %28 = load ptr, ptr %3, align 8, !tbaa !9
  %29 = call i32 @curl_multi_perform(ptr noundef %28, ptr noundef %4)
  store i32 %29, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = call i32 @curl_multi_poll(ptr noundef %33, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null)
  store i32 %34, ptr %6, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %32, %27
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i32 2, ptr %5, align 4
  br label %40

39:                                               ; preds = %35
  store i32 0, ptr %5, align 4
  br label %40

40:                                               ; preds = %39, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %41 = load i32, ptr %5, align 4
  switch i32 %41, label %55 [
    i32 0, label %42
    i32 2, label %46
  ]

42:                                               ; preds = %40
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %27, label %46, !llvm.loop !11

46:                                               ; preds = %43, %40
  %47 = load ptr, ptr %3, align 8, !tbaa !9
  %48 = load ptr, ptr %2, align 8, !tbaa !9
  %49 = call i32 @curl_multi_remove_handle(ptr noundef %47, ptr noundef %48)
  %50 = load ptr, ptr %3, align 8, !tbaa !9
  %51 = call i32 @curl_multi_cleanup(ptr noundef %50)
  %52 = load ptr, ptr %2, align 8, !tbaa !9
  call void @curl_easy_cleanup(ptr noundef %52)
  call void @curl_global_cleanup()
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %53

53:                                               ; preds = %46, %16, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %54 = load i32, ptr %1, align 4
  ret i32 %54

55:                                               ; preds = %40
  unreachable
}

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

declare ptr @curl_multi_init() #2

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

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

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

declare i32 @curl_multi_poll(ptr noundef, ptr noundef, i32 noundef, i32 noundef, 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_remove_handle(ptr noundef, ptr noundef) #2

declare i32 @curl_multi_cleanup(ptr noundef) #2

declare void @curl_easy_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 }

!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"}


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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  store i32 1, ptr %1, align 4, !tbaa !5
  %2 = tail call i32 @curl_global_init(i64 noundef 3) #3
  %3 = tail call ptr @curl_easy_init() #3
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %18, label %4

4:                                                ; preds = %0
  %5 = tail call ptr @curl_multi_init() #3
  %.not19 = icmp eq ptr %5, null
  br i1 %.not19, label %18, label %6

6:                                                ; preds = %4
  %7 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 10173, ptr noundef nonnull @.str) #3
  %8 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 10174, ptr noundef nonnull @.str.1) #3
  %9 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 10002, ptr noundef nonnull @.str.2) #3
  %10 = tail call i32 @curl_multi_add_handle(ptr noundef nonnull %5, ptr noundef nonnull %3) #3
  br label %11

11:                                               ; preds = %14, %6
  %12 = call i32 @curl_multi_perform(ptr noundef nonnull %5, ptr noundef nonnull %1) #3
  %13 = load i32, ptr %1, align 4
  %.not20 = icmp eq i32 %13, 0
  br i1 %.not20, label %.thread, label %14

14:                                               ; preds = %11
  %15 = call i32 @curl_multi_poll(ptr noundef nonnull %5, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null) #3
  %.pre = load i32, ptr %1, align 4
  %.not21 = icmp ne i32 %15, 0
  %.not22 = icmp eq i32 %.pre, 0
  %or.cond = select i1 %.not21, i1 true, i1 %.not22
  br i1 %or.cond, label %.thread, label %11, !llvm.loop !9

.thread:                                          ; preds = %11, %14
  %16 = call i32 @curl_multi_remove_handle(ptr noundef nonnull %5, ptr noundef nonnull %3) #3
  %17 = call i32 @curl_multi_cleanup(ptr noundef nonnull %5) #3
  call void @curl_easy_cleanup(ptr noundef nonnull %3) #3
  call void @curl_global_cleanup() #3
  br label %18

18:                                               ; preds = %4, %0, %.thread
  %.016 = phi i32 [ 0, %.thread ], [ 1, %0 ], [ 2, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 %.016
}

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

declare ptr @curl_multi_init() local_unnamed_addr #2

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

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

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

declare i32 @curl_multi_poll(ptr noundef, ptr noundef, i32 noundef, i32 noundef, 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_remove_handle(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @curl_multi_cleanup(ptr noundef) local_unnamed_addr #2

declare void @curl_easy_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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass