#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 */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LOG_DAEMON;
int LOG_DEBUG;
int LOG_ERR;
int LOG_INFO;
int /*<<< orphan*/ LOG_PID;
int /*<<< orphan*/ LOG_UPTO(int);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setlogmask(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int, char *, char *);
void runLogger(int listenFd, int level) {
  FILE *stream;
  int priosysl;
  char buf[4096];
  openlog("sfcb", LOG_PID, LOG_DAEMON);
  setlogmask(LOG_UPTO(level));
  ;
  stream = fdopen(listenFd, "r");
  while (!feof(stream)) {
    fgets(buf, sizeof(buf), stream);
    int priority = buf[0];
    switch (priority) {
    case 1:
      priosysl = LOG_DEBUG;
      break;
    case 2:
      priosysl = LOG_INFO;
      break;
    case 3:
    default:
      priosysl = LOG_ERR;
      break;
    }
    syslog(priosysl, "%s", buf + 1);
  }
  return;
}


x86 assembly (clang, -O0):
<runLogger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
lea    0xe66(%rip),%rdi
call   1090 <openlog@plt>
mov    -0x8(%rbp),%edi
call   1030 <LOG_UPTO@plt>
mov    %eax,%edi
call   1060 <setlogmask@plt>
mov    -0x4(%rbp),%edi
lea    0xe4d(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11df <runLogger+0x6f>
jmp    1295 <runLogger+0x125>
mov    -0x10(%rbp),%rdx
lea    -0x1020(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <fgets@plt>
movsbl -0x1020(%rbp),%eax
mov    %eax,-0x1024(%rbp)
mov    -0x1024(%rbp),%eax
mov    %eax,-0x1028(%rbp)
sub    $0x1,%eax
je     1243 <runLogger+0xd3>
jmp    121b <runLogger+0xab>
mov    -0x1028(%rbp),%eax
sub    $0x2,%eax
je     1254 <runLogger+0xe4>
jmp    122f <runLogger+0xbf>
mov    -0x1028(%rbp),%eax
sub    $0x3,%eax
je     1265 <runLogger+0xf5>
jmp    126a <runLogger+0xfa>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1276 <runLogger+0x106>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1276 <runLogger+0x106>
jmp    126a <runLogger+0xfa>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rdx
add    $0x1,%rdx
lea    0xd7c(%rip),%rsi
call   1070 <syslog@plt>
jmp    11c1 <runLogger+0x51>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runLogger>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rdi
call   1090 <openlog@plt>
mov    %ebx,%edi
call   1030 <LOG_UPTO@plt>
mov    %eax,%edi
call   1060 <setlogmask@plt>
lea    0xe4d(%rip),%rsi
mov    %ebp,%edi
call   1080 <fdopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11e0 <runLogger+0x70>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x1(%rsp),%r14
mov    %rsp,%r15
mov    0x2dc9(%rip),%rbp
mov    0x2dda(%rip),%r13
lea    0xe0a(%rip),%r12
jmp    1219 <runLogger+0xa9>
nop
mov    (%rax),%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <syslog@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11ce <runLogger+0x5e>
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
movzbl (%rsp),%ecx
mov    %rbp,%rax
cmp    $0x2,%cl
jne    123c <runLogger+0xcc>
mov    0x2d8c(%rip),%rax
cmp    $0x1,%cl
jne    1200 <runLogger+0x90>
mov    %r13,%rax
jmp    1200 <runLogger+0x90>

LLVM IR (-O0):
@.str = [5 x i8] c"sfcb\00"
@LOG_PID = global i32 0
@LOG_DAEMON = global i32 0
@.str.1 = [2 x i8] c"r\00"
@LOG_DEBUG = global i32 0
@LOG_INFO = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @runLogger(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* @LOG_PID
%10 = load i32, i32* @LOG_DAEMON
%11 = call i32 @openlog(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32, i32* %4
%13 = call i32 @LOG_UPTO(i32 %12)
%14 = call i32 @setlogmask(i32 %13)
%15 = load i32, i32* %3
%16 = call i32* @fdopen(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %5
br label %17
17: ; preds = %37, %2
%18 = load i32*, i32** %5
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %42
22: ; preds = %17
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%24 = load i32*, i32** %5
%25 = call i32 @fgets(i8* %23, i32 4096, i32* %24)
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
store i32 %28, i32* %8
%29 = load i32, i32* %8
switch i32 %29, label %35 [
i32 1, label %30
i32 2, label %32
i32 3, label %34
]
30: ; preds = %22
%31 = load i32, i32* @LOG_DEBUG
store i32 %31, i32* %6
br label %37
32: ; preds = %22
%33 = load i32, i32* @LOG_INFO
store i32 %33, i32* %6
br label %37
34: ; preds = %22
br label %35
35: ; preds = %22, %34
%36 = load i32, i32* @LOG_ERR
store i32 %36, i32* %6
br label %37
37: ; preds = %35, %32, %30
%38 = load i32, i32* %6
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = call i32 @syslog(i32 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %17
42: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"sfcb\00"
@LOG_PID = global i32 0
@LOG_DAEMON = global i32 0
@.str.1 = [2 x i8] c"r\00"
@LOG_DEBUG = global i32 0
@LOG_INFO = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @runLogger(i32 %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @LOG_PID
%6 = load i32, i32* @LOG_DAEMON
%7 = tail call i32 @openlog(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call i32 @LOG_UPTO(i32 %1)
%9 = tail call i32 @setlogmask(i32 %8)
%10 = tail call i32* @fdopen(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @feof(i32* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %2
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 1
br label %15
15: ; preds = %13, %15
%16 = call i32 @fgets(i8* %4, i32 4096, i32* %10)
%17 = load i8, i8* %4
%18 = icmp eq i8 %17, 2
%19 = icmp eq i8 %17, 1
%20 = load i32, i32* @LOG_DEBUG
%21 = load i32, i32* @LOG_INFO
%22 = load i32, i32* @LOG_ERR
%23 = select i1 %18, i32 %21, i32 %22
%24 = select i1 %19, i32 %20, i32 %23
%25 = call i32 @syslog(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%26 = call i32 @feof(i32* %10)
%27 = icmp eq i32 %26, 0
br i1 %27, label %15, label %28
28: ; preds = %15, %2
ret void
}