#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ init_log(int, char *);
int /*<<< orphan*/ logerrno(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ logmsg(int, char *, ...);
int main() {
  init_log((1 << 0) | (1 << 1), NULL);
  logmsg((1 << 0), "this is stderr");
  logmsg((1 << 2), "Should not show");
  logerrno((1 << 2), NULL, ENOENT);
  init_log((1 << 0) | (1 << 1) | (1 << 2), "./logs/");
  logmsg((1 << 0), "some info");
  logmsg((1 << 1), "invalid type '%i'", 3);
  logerrno((1 << 2), "malloc", ENOMEM);
  logerrno((1 << 2), NULL, ENOENT);
  logmsg((1 << 3), "Should not show");
  logmsg((1 << 0) | (1 << 2), "Should not work, can only log to one priority");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <init_log@plt>
mov    $0x1,%edi
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1040 <logmsg@plt>
mov    $0x4,%edi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1040 <logmsg@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <logerrno@plt>
mov    $0x7,%edi
lea    0xe89(%rip),%rsi
call   1050 <init_log@plt>
mov    $0x1,%edi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1040 <logmsg@plt>
mov    $0x2,%edi
lea    0xe77(%rip),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <logmsg@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%edi
lea    0xe68(%rip),%rsi
call   1030 <logerrno@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <logerrno@plt>
mov    $0x8,%edi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1040 <logmsg@plt>
mov    $0x5,%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1040 <logmsg@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3,%edi
xor    %esi,%esi
call   1050 <init_log@plt>
lea    0xeb9(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <logmsg@plt>
lea    0xeb5(%rip),%r14
mov    $0x4,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <logmsg@plt>
mov    0x2e60(%rip),%rbx
mov    (%rbx),%edx
mov    $0x4,%edi
xor    %esi,%esi
call   1030 <logerrno@plt>
lea    0xe9a(%rip),%rsi
mov    $0x7,%edi
call   1050 <init_log@plt>
lea    0xe91(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <logmsg@plt>
lea    0xe88(%rip),%rsi
mov    $0x2,%edi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <logmsg@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
lea    0xe79(%rip),%rsi
mov    $0x4,%edi
call   1030 <logerrno@plt>
mov    (%rbx),%edx
mov    $0x4,%edi
xor    %esi,%esi
call   1030 <logerrno@plt>
mov    $0x8,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <logmsg@plt>
lea    0xe52(%rip),%rsi
mov    $0x5,%edi
xor    %eax,%eax
call   1040 <logmsg@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"this is stderr\00"
@.str.1 = [16 x i8] c"Should not show\00"
@ENOENT = global i32 0
@.str.2 = [8 x i8] c"./logs/\00"
@.str.3 = [10 x i8] c"some info\00"
@.str.4 = [18 x i8] c"invalid type '%i'\00"
@.str.5 = [7 x i8] c"malloc\00"
@ENOMEM = global i32 0
@.str.6 = [46 x i8] c"Should not work, can only log to one priority\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @init_log(i32 3, i8* null)
%3 = call i32 (i32, i8*, ...) @logmsg(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i32, i8*, ...) @logmsg(i32 4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @ENOENT
%6 = call i32 @logerrno(i32 4, i8* null, i32 %5)
%7 = call i32 @init_log(i32 7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i32, i8*, ...) @logmsg(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 (i32, i8*, ...) @logmsg(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 3)
%10 = load i32, i32* @ENOMEM
%11 = call i32 @logerrno(i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @ENOENT
%13 = call i32 @logerrno(i32 4, i8* null, i32 %12)
%14 = call i32 (i32, i8*, ...) @logmsg(i32 8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i32, i8*, ...) @logmsg(i32 5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"this is stderr\00"
@.str.1 = [16 x i8] c"Should not show\00"
@ENOENT = global i32 0
@.str.2 = [8 x i8] c"./logs/\00"
@.str.3 = [10 x i8] c"some info\00"
@.str.4 = [18 x i8] c"invalid type '%i'\00"
@.str.5 = [7 x i8] c"malloc\00"
@ENOMEM = global i32 0
@.str.6 = [46 x i8] c"Should not work, can only log to one priority\00"
define i32 @main() {
%1 = tail call i32 @init_log(i32 3, i8* null)
%2 = tail call i32 (i32, i8*, ...) @logmsg(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (i32, i8*, ...) @logmsg(i32 4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @ENOENT
%5 = tail call i32 @logerrno(i32 4, i8* null, i32 %4)
%6 = tail call i32 @init_log(i32 7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i32, i8*, ...) @logmsg(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 (i32, i8*, ...) @logmsg(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 3)
%9 = load i32, i32* @ENOMEM
%10 = tail call i32 @logerrno(i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @ENOENT
%12 = tail call i32 @logerrno(i32 4, i8* null, i32 %11)
%13 = tail call i32 (i32, i8*, ...) @logmsg(i32 8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 (i32, i8*, ...) @logmsg(i32 5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}