#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*/ LOG_ALERT;
int LOG_CONS;
int /*<<< orphan*/ LOG_CRIT;
int /*<<< orphan*/ LOG_EMERG;
int /*<<< orphan*/ LOG_ERR;
int LOG_MASK(int /*<<< orphan*/);
int LOG_NDELAY;
int LOG_PID;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ openlog(char *, int, int /*<<< orphan*/);
int setlogmask(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ write_to_syslog();
int main(int argc, char *argv[]) {
  int option = LOG_CONS | LOG_NDELAY | LOG_PID;
  int mask = LOG_MASK(LOG_EMERG) | LOG_MASK(LOG_ALERT) | LOG_MASK(LOG_CRIT) |
             LOG_MASK(LOG_ERR);
  int old_mask = 0;
  openlog(argv[0], option, LOG_USER);
  write_to_syslog();
  old_mask = setlogmask(mask);
  syslog(LOG_EMERG, "Old log mask: 0x%x new: 0x%x", old_mask, mask);
  write_to_syslog();
  closelog();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    0x2e22(%rip),%rcx
or     (%rcx),%eax
mov    0x2e31(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1050 <LOG_MASK@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1050 <LOG_MASK@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1050 <LOG_MASK@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1050 <LOG_MASK@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
call   1080 <openlog@plt>
mov    $0x0,%al
call   1040 <write_to_syslog@plt>
mov    -0x18(%rbp),%edi
call   1060 <setlogmask@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xdcc(%rip),%rsi
call   1070 <syslog@plt>
mov    $0x0,%al
call   1040 <write_to_syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    0x2e46(%rip),%rax
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2e3c(%rip),%rax
or     (%rax),%ebx
mov    0x2e43(%rip),%r12
mov    (%r12),%edi
call   1050 <LOG_MASK@plt>
mov    %eax,%r15d
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <LOG_MASK@plt>
or     %eax,%r15d
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1050 <LOG_MASK@plt>
mov    %eax,%ebp
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1050 <LOG_MASK@plt>
or     %eax,%ebp
or     %r15d,%ebp
mov    (%r14),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%esi
call   1080 <openlog@plt>
xor    %eax,%eax
call   1040 <write_to_syslog@plt>
mov    %ebp,%edi
call   1060 <setlogmask@plt>
mov    (%r12),%edi
lea    0xe07(%rip),%rsi
mov    %eax,%edx
mov    %ebp,%ecx
call   1070 <syslog@plt>
xor    %eax,%eax
call   1040 <write_to_syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_CONS = global i32 0
@LOG_NDELAY = global i32 0
@LOG_PID = global i32 0
@LOG_EMERG = global i32 0
@LOG_ALERT = global i32 0
@LOG_CRIT = global i32 0
@LOG_ERR = global i32 0
@LOG_USER = global i32 0
@.str = [29 x i8] c"Old log mask: 0x%x new: 0x%x\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @LOG_CONS
%10 = load i32, i32* @LOG_NDELAY
%11 = or i32 %9, %10
%12 = load i32, i32* @LOG_PID
%13 = or i32 %11, %12
store i32 %13, i32* %6
%14 = load i32, i32* @LOG_EMERG
%15 = call i32 @LOG_MASK(i32 %14)
%16 = load i32, i32* @LOG_ALERT
%17 = call i32 @LOG_MASK(i32 %16)
%18 = or i32 %15, %17
%19 = load i32, i32* @LOG_CRIT
%20 = call i32 @LOG_MASK(i32 %19)
%21 = or i32 %18, %20
%22 = load i32, i32* @LOG_ERR
%23 = call i32 @LOG_MASK(i32 %22)
%24 = or i32 %21, %23
store i32 %24, i32* %7
store i32 0, i32* %8
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = load i32, i32* %6
%29 = load i32, i32* @LOG_USER
%30 = call i32 @openlog(i8* %27, i32 %28, i32 %29)
%31 = call i32 (...) @write_to_syslog()
%32 = load i32, i32* %7
%33 = call i32 @setlogmask(i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* @LOG_EMERG
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = call i32 @syslog(i32 %34, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36)
%38 = call i32 (...) @write_to_syslog()
%39 = call i32 (...) @closelog()
ret i32 0
}

LLVM IR (-O2):
@LOG_CONS = global i32 0
@LOG_NDELAY = global i32 0
@LOG_PID = global i32 0
@LOG_EMERG = global i32 0
@LOG_ALERT = global i32 0
@LOG_CRIT = global i32 0
@LOG_ERR = global i32 0
@LOG_USER = global i32 0
@.str = [29 x i8] c"Old log mask: 0x%x new: 0x%x\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @LOG_CONS
%4 = load i32, i32* @LOG_NDELAY
%5 = or i32 %4, %3
%6 = load i32, i32* @LOG_PID
%7 = or i32 %5, %6
%8 = load i32, i32* @LOG_EMERG
%9 = tail call i32 @LOG_MASK(i32 %8)
%10 = load i32, i32* @LOG_ALERT
%11 = tail call i32 @LOG_MASK(i32 %10)
%12 = or i32 %11, %9
%13 = load i32, i32* @LOG_CRIT
%14 = tail call i32 @LOG_MASK(i32 %13)
%15 = or i32 %12, %14
%16 = load i32, i32* @LOG_ERR
%17 = tail call i32 @LOG_MASK(i32 %16)
%18 = or i32 %15, %17
%19 = load i8*, i8** %1
%20 = load i32, i32* @LOG_USER
%21 = tail call i32 @openlog(i8* %19, i32 %7, i32 %20)
%22 = tail call i32 (...) @write_to_syslog()
%23 = tail call i32 @setlogmask(i32 %18)
%24 = load i32, i32* @LOG_EMERG
%25 = tail call i32 @syslog(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %18)
%26 = tail call i32 (...) @write_to_syslog()
%27 = tail call i32 (...) @closelog()
ret i32 0
}