#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 LOG_CONS;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int LOG_PID;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ openlog(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *);
void write_to_log(const char *argument, bool to_error) {
  openlog("sbatterymonitor", LOG_PID | LOG_CONS, LOG_USER);
  syslog(to_error ? LOG_ERR : LOG_INFO, "%s", argument);
  closelog();
}


x86 assembly (clang, -O0):
<write_to_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
or     (%rax),%esi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
lea    0xe9f(%rip),%rdi
call   1050 <openlog@plt>
cmpl   $0x0,-0xc(%rbp)
je     1181 <write_to_log+0x51>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    118d <write_to_log+0x5d>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_log>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e99(%rip),%rax
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
lea    0xea6(%rip),%rdi
call   1050 <openlog@plt>
test   %ebp,%ebp
jne    116c <write_to_log+0x3c>
mov    0x2e5e(%rip),%rax
jmp    1173 <write_to_log+0x43>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    %rbx,%rdx
call   1040 <syslog@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <closelog@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"sbatterymonitor\00"
@LOG_PID = global i32 0
@LOG_CONS = global i32 0
@LOG_USER = global i32 0
@LOG_ERR = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @write_to_log(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* @LOG_PID
%6 = load i32, i32* @LOG_CONS
%7 = or i32 %5, %6
%8 = load i32, i32* @LOG_USER
%9 = call i32 @openlog(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* @LOG_ERR
br label %16
14: ; preds = %2
%15 = load i32, i32* @LOG_INFO
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ %13, %12 ], [ %15, %14 ]
%18 = load i8*, i8** %3
%19 = call i32 @syslog(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 (...) @closelog()
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"sbatterymonitor\00"
@LOG_PID = global i32 0
@LOG_CONS = global i32 0
@LOG_USER = global i32 0
@LOG_ERR = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @write_to_log(i8* %0, i32 %1) {
%3 = load i32, i32* @LOG_PID
%4 = load i32, i32* @LOG_CONS
%5 = or i32 %4, %3
%6 = load i32, i32* @LOG_USER
%7 = tail call i32 @openlog(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = icmp eq i32 %1, 0
%9 = load i32, i32* @LOG_ERR
%10 = load i32, i32* @LOG_INFO
%11 = select i1 %8, i32 %10, i32 %9
%12 = tail call i32 @syslog(i32 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 (...) @closelog()
ret void
}