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

; 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.MemoryStruct = type { ptr, i64 }

@main.postthis = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 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 %struct.MemoryStruct, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #6
  %5 = call noalias ptr @malloc(i64 noundef 1) #7
  %6 = getelementptr inbounds %struct.MemoryStruct, ptr %4, i32 0, i32 0
  store ptr %5, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MemoryStruct, ptr %4, i32 0, i32 1
  store i64 0, ptr %7, align 8, !tbaa !11
  %8 = call i32 @curl_global_init(i64 noundef 3)
  %9 = call ptr @curl_easy_init()
  store ptr %9, ptr %2, align 8, !tbaa !12
  %10 = load ptr, ptr %2, align 8, !tbaa !12
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %43

12:                                               ; preds = %0
  %13 = load ptr, ptr %2, align 8, !tbaa !12
  %14 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %13, i32 noundef 10002, ptr noundef @.str.1)
  %15 = load ptr, ptr %2, align 8, !tbaa !12
  %16 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %15, i32 noundef 20011, ptr noundef @WriteMemoryCallback)
  %17 = load ptr, ptr %2, align 8, !tbaa !12
  %18 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %17, i32 noundef 10001, ptr noundef %4)
  %19 = load ptr, ptr %2, align 8, !tbaa !12
  %20 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %19, i32 noundef 10018, ptr noundef @.str.2)
  %21 = load ptr, ptr %2, align 8, !tbaa !12
  %22 = load ptr, ptr @main.postthis, align 8, !tbaa !12
  %23 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %21, i32 noundef 10015, ptr noundef %22)
  %24 = load ptr, ptr %2, align 8, !tbaa !12
  %25 = load ptr, ptr @main.postthis, align 8, !tbaa !12
  %26 = call i64 @strlen(ptr noundef %25) #8
  %27 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %24, i32 noundef 60, i64 noundef %26)
  %28 = load ptr, ptr %2, align 8, !tbaa !12
  %29 = call i32 @curl_easy_perform(ptr noundef %28)
  store i32 %29, ptr %3, align 4, !tbaa !13
  %30 = load i32, ptr %3, align 4, !tbaa !13
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %12
  %33 = load ptr, ptr @stderr, align 8, !tbaa !12
  %34 = load i32, ptr %3, align 4, !tbaa !13
  %35 = call ptr @curl_easy_strerror(i32 noundef %34)
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.3, ptr noundef %35) #6
  br label %41

37:                                               ; preds = %12
  %38 = getelementptr inbounds %struct.MemoryStruct, ptr %4, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %39)
  br label %41

41:                                               ; preds = %37, %32
  %42 = load ptr, ptr %2, align 8, !tbaa !12
  call void @curl_easy_cleanup(ptr noundef %42)
  br label %43

43:                                               ; preds = %41, %0
  %44 = getelementptr inbounds %struct.MemoryStruct, ptr %4, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  call void @free(ptr noundef %45) #6
  call void @curl_global_cleanup()
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  ret i32 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i32 @curl_global_init(i64 noundef) #3

declare ptr @curl_easy_init() #3

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

; Function Attrs: nounwind uwtable
declare hidden i64 @WriteMemoryCallback(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

declare i32 @curl_easy_perform(ptr noundef) #3

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

declare ptr @curl_easy_strerror(i32 noundef) #3

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

declare void @curl_easy_cleanup(ptr noundef) #3

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

declare void @curl_global_cleanup() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 willreturn memory(read) "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 }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { nounwind willreturn memory(read) }

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


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

%struct.MemoryStruct = type { ptr, i64 }

@main.postthis = external hidden local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.MemoryStruct, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #7
  %2 = tail call noalias dereferenceable_or_null(1) ptr @malloc(i64 noundef 1) #8
  store ptr %2, ptr %1, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 0, ptr %3, align 8, !tbaa !11
  %4 = tail call i32 @curl_global_init(i64 noundef 3) #7
  %5 = tail call ptr @curl_easy_init() #7
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %25, 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.1) #7
  %8 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %5, i32 noundef 20011, ptr noundef nonnull @WriteMemoryCallback) #7
  %9 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %5, i32 noundef 10001, ptr noundef nonnull %1) #7
  %10 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %5, i32 noundef 10018, ptr noundef nonnull @.str.2) #7
  %11 = load ptr, ptr @main.postthis, align 8, !tbaa !12
  %12 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %5, i32 noundef 10015, ptr noundef %11) #7
  %13 = load ptr, ptr @main.postthis, align 8, !tbaa !12
  %14 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %13) #9
  %15 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %5, i32 noundef 60, i64 noundef %14) #7
  %16 = call i32 @curl_easy_perform(ptr noundef nonnull %5) #7
  %.not11 = icmp eq i32 %16, 0
  br i1 %.not11, label %21, label %17

17:                                               ; preds = %6
  %18 = load ptr, ptr @stderr, align 8, !tbaa !12
  %19 = call ptr @curl_easy_strerror(i32 noundef %16) #7
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.3, ptr noundef %19) #10
  br label %24

21:                                               ; preds = %6
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %22)
  br label %24

24:                                               ; preds = %21, %17
  call void @curl_easy_cleanup(ptr noundef nonnull %5) #7
  %.pre = load ptr, ptr %1, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %24, %0
  %26 = phi ptr [ %.pre, %24 ], [ %2, %0 ]
  call void @free(ptr noundef %26) #7
  call void @curl_global_cleanup() #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #7
  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

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

declare i32 @curl_global_init(i64 noundef) local_unnamed_addr #3

declare ptr @curl_easy_init() local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare hidden i64 @WriteMemoryCallback(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

declare i32 @curl_easy_perform(ptr noundef) local_unnamed_addr #3

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

declare ptr @curl_easy_strerror(i32 noundef) local_unnamed_addr #3

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

declare void @curl_easy_cleanup(ptr 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 #6

declare void @curl_global_cleanup() local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 nofree nounwind willreturn memory(argmem: read) "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 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind willreturn memory(read) }
attributes #10 = { 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, !7, i64 0}
!6 = !{!"MemoryStruct", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass