int main() {
  printf("Logging example\n");
  printf("\nCall: log_init()\n");
  log_init();
  printf("\nCall: log_error(__func__, \"error ...\")\n");
  log_error(__func__, "error ...");
  printf("\nCall: log_warn(__func__, \"warn ...\")\n");
  log_warn(__func__, "warn ...");
  printf("\nCall: log_info(__func__, \"info <var1>, <var2> ...\", \"arg1\", "
         "\"arg2\")\n");
  log_info(__func__, "info %s, %s ...", "arg1", "arg2");
  printf("\nCall: log_debug(__func__, \"debug ...\")\n");
  log_debug(__func__, "debug ...");
  printf("\nCall: log_close()\n");
  log_close();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <log_init@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1050 <log_error@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe73(%rip),%rdi
lea    0xea2(%rip),%rsi
mov    $0x0,%al
call   1090 <log_warn@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe50(%rip),%rdi
lea    0xece(%rip),%rsi
lea    0xed7(%rip),%rdx
lea    0xed5(%rip),%rcx
mov    $0x0,%al
call   1040 <log_info@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe1f(%rip),%rdi
lea    0xee0(%rip),%rsi
mov    $0x0,%al
call   1070 <log_debug@plt>
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <log_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec4(%rip),%rdi
call   1040 <puts@plt>
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <log_init@plt>
lea    0xec7(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5d(%rip),%rbx
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <log_error@plt>
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <log_warn@plt>
lea    0xed4(%rip),%rdi
call   1040 <puts@plt>
lea    0xe34(%rip),%rsi
lea    0xe3d(%rip),%rdx
lea    0xe3b(%rip),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <log_info@plt>
lea    0xeee(%rip),%rdi
call   1040 <puts@plt>
lea    0xe23(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <log_debug@plt>
lea    0xef9(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <log_close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Logging example\0A\00"
@.str.1 = [19 x i8] c"\0ACall: log_init()\0A\00"
@.str.2 = [41 x i8] c"\0ACall: log_error(__func__, \22error ...\22)\0A\00"
@__func__.main = [5 x i8] c"main\00"
@.str.3 = [10 x i8] c"error ...\00"
@.str.4 = [39 x i8] c"\0ACall: log_warn(__func__, \22warn ...\22)\0A\00"
@.str.5 = [9 x i8] c"warn ...\00"
@.str.6 = [70 x i8] c"\0ACall: log_info(__func__, \22info <var1>, <var2> ...\22, \22arg1\22, \22arg2\22)\0A\00"
@.str.7 = [16 x i8] c"info %s, %s ...\00"
@.str.8 = [5 x i8] c"arg1\00"
@.str.9 = [5 x i8] c"arg2\00"
@.str.10 = [41 x i8] c"\0ACall: log_debug(__func__, \22debug ...\22)\0A\00"
@.str.11 = [10 x i8] c"debug ...\00"
@.str.12 = [20 x i8] c"\0ACall: log_close()\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 (...) @log_init()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @log_error to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @log_warn to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.6, i64 0, i64 0))
%10 = call i32 (i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @log_info to i32 (i8*, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0))
%12 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @log_debug to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
%14 = call i32 (...) @log_close()
ret i32 0
}

LLVM IR (-O2):
@__func__.main = [5 x i8] c"main\00"
@.str.3 = [10 x i8] c"error ...\00"
@.str.5 = [9 x i8] c"warn ...\00"
@.str.7 = [16 x i8] c"info %s, %s ...\00"
@.str.8 = [5 x i8] c"arg1\00"
@.str.9 = [5 x i8] c"arg2\00"
@.str.11 = [10 x i8] c"debug ...\00"
@str = [16 x i8] c"Logging example\00"
@str.13 = [18 x i8] c"\0ACall: log_init()\00"
@str.14 = [40 x i8] c"\0ACall: log_error(__func__, \22error ...\22)\00"
@str.15 = [38 x i8] c"\0ACall: log_warn(__func__, \22warn ...\22)\00"
@str.16 = [69 x i8] c"\0ACall: log_info(__func__, \22info <var1>, <var2> ...\22, \22arg1\22, \22arg2\22)\00"
@str.17 = [40 x i8] c"\0ACall: log_debug(__func__, \22debug ...\22)\00"
@str.18 = [19 x i8] c"\0ACall: log_close()\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.13, i64 0, i64 0))
%3 = tail call i32 (...) @log_init()
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.14, i64 0, i64 0))
%5 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @log_error to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.15, i64 0, i64 0))
%7 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @log_warn to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str.16, i64 0, i64 0))
%9 = tail call i32 (i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @log_info to i32 (i8*, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.17, i64 0, i64 0))
%11 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @log_debug to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.18, i64 0, i64 0))
%13 = tail call i32 (...) @log_close()
ret i32 0
}