#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*/ EXIT_FAILURE;
int /*<<< orphan*/ LOG_ALERT;
int LOG_CONS;
int /*<<< orphan*/ LOG_CRIT;
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_EMERG;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_LOCAL1;
int LOG_NDELAY;
int /*<<< orphan*/ LOG_NOTICE;
int LOG_PID;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ openlog(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
int main(void) {
  printf("Depending on how your machine is configured, this program might "
         "cause an 'emergency' message to be broadcast to users on all "
         "terminals. You might not want to run this on a machine where other "
         "logged in users might be alarmed by the message. Press Ctrl+C to "
         "exit, any other key to continue.\n");
  char buf[100];
  if (fgets(buf, 100, stdin) == NULL) {
    printf("fgets error\n");
    exit(EXIT_FAILURE);
  }
  char disclaimer[1024];
  snprintf(disclaimer, 1024,
           "Everything is fine, this is a test generated by user '%s'.\n",
           getenv("USER"));
  openlog("syslog-demonstration", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
  syslog(LOG_EMERG,
         "This is a test of the syslog emergency system. This type of message "
         "is typically used to indicate that the system is unstable. %s",
         disclaimer);
  syslog(LOG_ALERT, "This is an alert, action must be taken immediately. %s",
         disclaimer);
  syslog(LOG_CRIT, "This is a critical condition. %s", disclaimer);
  syslog(LOG_ERR, "This is a error condition. %s", disclaimer);
  syslog(LOG_WARNING,
         "This is a warning condition. Everything is fine, this is a test. %s",
         disclaimer);
  syslog(LOG_NOTICE,
         "This is a normal, but significant, condition. Everything is fine, "
         "this is a test. %s",
         disclaimer);
  syslog(LOG_INFO,
         "This is an informational message. Everything is fine, this is a "
         "test. %s",
         disclaimer);
  syslog(LOG_DEBUG,
         "This is a debugging message. Everything is fine, this is a test. %s",
         disclaimer);
  closelog();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    11d2 <main+0x52>
lea    0xf64(%rip),%rdi
call   1050 <printf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x470(%rbp),%rax
mov    %rax,-0x478(%rbp)
lea    0xf85(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x478(%rbp),%rdi
mov    %rax,%rcx
mov    $0x400,%esi
lea    0xf2e(%rip),%rdx
call   1060 <snprintf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
mov    0x2d58(%rip),%rax
or     (%rax),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
lea    0xf3f(%rip),%rdi
call   1090 <openlog@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0xf38(%rip),%rsi
call   1080 <syslog@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0xf9e(%rip),%rsi
call   1080 <syslog@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0xfb9(%rip),%rsi
call   1080 <syslog@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0xfbe(%rip),%rsi
call   1080 <syslog@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0xfc0(%rip),%rsi
call   1080 <syslog@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0xfe8(%rip),%rsi
call   1080 <syslog@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0x1021(%rip),%rsi
call   1080 <syslog@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    -0x470(%rbp),%rdx
lea    0x104e(%rip),%rsi
call   1080 <syslog@plt>
mov    $0x0,%al
call   1040 <closelog@plt>
xor    %eax,%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x470,%rsp
lea    0x10e5(%rip),%rdi
call   1050 <puts@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     12dd <main+0x15d>
lea    0xe82(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe3a(%rip),%rdx
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
mov    0x2dce(%rip),%rax
mov    0x2dcf(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d84(%rip),%rax
or     (%rax),%esi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
lea    0xe3b(%rip),%rdi
call   1090 <openlog@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xecd(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xed3(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xeff(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xf3c(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    0xf6d(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
xor    %eax,%eax
call   1040 <closelog@plt>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbx
ret
lea    0x10b2(%rip),%rdi
call   1050 <puts@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [291 x i8] c"Depending on how your machine is configured, this program might cause an 'emergency' message to be broadcast to users on all terminals. You might not want to run this on a machine where other logged in users might be alarmed by the message. Press Ctrl+C to exit, any other key to continue.\0A\00"
@stdin = global i32 0
@.str.1 = [13 x i8] c"fgets error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [60 x i8] c"Everything is fine, this is a test generated by user '%s'.\0A\00"
@.str.3 = [5 x i8] c"USER\00"
@.str.4 = [21 x i8] c"syslog-demonstration\00"
@LOG_CONS = global i32 0
@LOG_PID = global i32 0
@LOG_NDELAY = global i32 0
@LOG_LOCAL1 = global i32 0
@LOG_EMERG = global i32 0
@.str.5 = [130 x i8] c"This is a test of the syslog emergency system. This type of message is typically used to indicate that the system is unstable. %s\00"
@LOG_ALERT = global i32 0
@.str.6 = [55 x i8] c"This is an alert, action must be taken immediately. %s\00"
@LOG_CRIT = global i32 0
@.str.7 = [33 x i8] c"This is a critical condition. %s\00"
@LOG_ERR = global i32 0
@.str.8 = [30 x i8] c"This is a error condition. %s\00"
@LOG_WARNING = global i32 0
@.str.9 = [68 x i8] c"This is a warning condition. Everything is fine, this is a test. %s\00"
@LOG_NOTICE = global i32 0
@.str.10 = [85 x i8] c"This is a normal, but significant, condition. Everything is fine, this is a test. %s\00"
@LOG_INFO = global i32 0
@.str.11 = [73 x i8] c"This is an informational message. Everything is fine, this is a test. %s\00"
@LOG_DEBUG = global i32 0
@.str.12 = [68 x i8] c"This is a debugging message. Everything is fine, this is a test. %s\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [1024 x i8]
%3 = call i32 @printf(i8* getelementptr inbounds ([291 x i8], [291 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 100, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @LOG_CONS
%17 = load i32, i32* @LOG_PID
%18 = or i32 %16, %17
%19 = load i32, i32* @LOG_NDELAY
%20 = or i32 %18, %19
%21 = load i32, i32* @LOG_LOCAL1
%22 = call i32 @openlog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* @LOG_EMERG
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%25 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.5, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @LOG_ALERT
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%28 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @LOG_CRIT
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%31 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @LOG_ERR
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%34 = call i32 @syslog(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @LOG_WARNING
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%37 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.9, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @LOG_NOTICE
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%40 = call i32 @syslog(i32 %38, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.10, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @LOG_INFO
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%43 = call i32 @syslog(i32 %41, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.11, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @LOG_DEBUG
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%46 = call i32 @syslog(i32 %44, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.12, i64 0, i64 0), i8* %45)
%47 = call i32 (...) @closelog()
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [60 x i8] c"Everything is fine, this is a test generated by user '%s'.\0A\00"
@.str.3 = [5 x i8] c"USER\00"
@.str.4 = [21 x i8] c"syslog-demonstration\00"
@LOG_CONS = global i32 0
@LOG_PID = global i32 0
@LOG_NDELAY = global i32 0
@LOG_LOCAL1 = global i32 0
@LOG_EMERG = global i32 0
@.str.5 = [130 x i8] c"This is a test of the syslog emergency system. This type of message is typically used to indicate that the system is unstable. %s\00"
@LOG_ALERT = global i32 0
@.str.6 = [55 x i8] c"This is an alert, action must be taken immediately. %s\00"
@LOG_CRIT = global i32 0
@.str.7 = [33 x i8] c"This is a critical condition. %s\00"
@LOG_ERR = global i32 0
@.str.8 = [30 x i8] c"This is a error condition. %s\00"
@LOG_WARNING = global i32 0
@.str.9 = [68 x i8] c"This is a warning condition. Everything is fine, this is a test. %s\00"
@LOG_NOTICE = global i32 0
@.str.10 = [85 x i8] c"This is a normal, but significant, condition. Everything is fine, this is a test. %s\00"
@LOG_INFO = global i32 0
@.str.11 = [73 x i8] c"This is an informational message. Everything is fine, this is a test. %s\00"
@LOG_DEBUG = global i32 0
@.str.12 = [68 x i8] c"This is a debugging message. Everything is fine, this is a test. %s\00"
@str = [290 x i8] c"Depending on how your machine is configured, this program might cause an 'emergency' message to be broadcast to users on all terminals. You might not want to run this on a machine where other logged in users might be alarmed by the message. Press Ctrl+C to exit, any other key to continue.\00"
@str.13 = [12 x i8] c"fgets error\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [1024 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([290 x i8], [290 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 100, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @LOG_CONS
%17 = load i32, i32* @LOG_PID
%18 = or i32 %17, %16
%19 = load i32, i32* @LOG_NDELAY
%20 = or i32 %18, %19
%21 = load i32, i32* @LOG_LOCAL1
%22 = call i32 @openlog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* @LOG_EMERG
%24 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%25 = load i32, i32* @LOG_ALERT
%26 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%27 = load i32, i32* @LOG_CRIT
%28 = call i32 @syslog(i32 %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %13)
%29 = load i32, i32* @LOG_ERR
%30 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %13)
%31 = load i32, i32* @LOG_WARNING
%32 = call i32 @syslog(i32 %31, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.9, i64 0, i64 0), i8* %13)
%33 = load i32, i32* @LOG_NOTICE
%34 = call i32 @syslog(i32 %33, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.10, i64 0, i64 0), i8* %13)
%35 = load i32, i32* @LOG_INFO
%36 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.11, i64 0, i64 0), i8* %13)
%37 = load i32, i32* @LOG_DEBUG
%38 = call i32 @syslog(i32 %37, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.12, i64 0, i64 0), i8* %13)
%39 = call i32 (...) @closelog()
ret i32 0
}