Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.

The normal messages print to what is called "standard output" or "standard out".

The error messages print to "standard error".

This separation can be used to redirect error messages to a different place than normal messages.



Task

Show how to print a message to standard error by printing     Goodbye, World!     on that stream.




; This is not strictly LLVM, as it uses the C library function "printf".
; LLVM does not provide a way to print values, so the alternative would be
; to just load the string into memory, and that would be boring.
 
; Additional comments have been inserted, as well as changes made from the output produced by clang such as putting more meaningful labels for the jumps
 
%struct._iobuf = type { i8* }
 
$"message" = comdat any
@"message" = linkonce_odr unnamed_addr constant [17 x i8] c"Goodbye, world!\0A\00", comdat, align 1
 
;-- For discovering stderr (io pipe 2)
declare %struct._iobuf* @__acrt_iob_func(i32)
 
;--- The declaration for the external C fprintf function.
declare i32 @fprintf(%struct._iobuf*, i8*, ...)
 
define i32 @main() {
;-- load stderr
  %1 = call %struct._iobuf* @__acrt_iob_func(i32 2)
;-- print the message to stderr with fprintf
  %2 = call i32 (%struct._iobuf*, i8*, ...) @fprintf(%struct._iobuf* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @"message", i32 0, i32 0))
;-- exit
  ret i32 0
}