#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_DEBUG;
int LOG_ERR;
int LOG_INFO;
int LOG_NOTICE;
int /*<<< orphan*/ syslog(int, char *);
void msg_to_syslog(unsigned short level, char *msg) {
  int sl;
  switch (level) {
  case 0:
    sl = LOG_ERR;
    break;
  case 1:
    sl = LOG_NOTICE;
    break;
  case 2:
    sl = LOG_INFO;
    break;
  default:
    sl = LOG_DEBUG;
    break;
  }
  syslog(sl, msg);
}


x86 assembly (clang, -O0):
<msg_to_syslog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movzwl -0x2(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     1159 <msg_to_syslog+0x49>
jmp    1137 <msg_to_syslog+0x27>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     116a <msg_to_syslog+0x5a>
jmp    1148 <msg_to_syslog+0x38>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     117b <msg_to_syslog+0x6b>
jmp    118c <msg_to_syslog+0x7c>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1198 <msg_to_syslog+0x88>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1198 <msg_to_syslog+0x88>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1198 <msg_to_syslog+0x88>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <syslog@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_to_syslog>:
cmp    $0x2,%di
ja     112c <msg_to_syslog+0x1c>
movswq %di,%rax
lea    0x2cdf(%rip),%rcx
mov    (%rcx,%rax,8),%rax
mov    (%rax),%edi
jmp    1030 <syslog@plt>
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
jmp    1030 <syslog@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@LOG_NOTICE = global i32 0
@LOG_INFO = global i32 0
@LOG_DEBUG = global i32 0
define void @msg_to_syslog(i16 zeroext %0, i8* %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i32
store i16 %0, i16* %3
store i8* %1, i8** %4
%6 = load i16, i16* %3
%7 = zext i16 %6 to i32
switch i32 %7, label %14 [
i32 0, label %8
i32 1, label %10
i32 2, label %12
]
8: ; preds = %2
%9 = load i32, i32* @LOG_ERR
store i32 %9, i32* %5
br label %16
10: ; preds = %2
%11 = load i32, i32* @LOG_NOTICE
store i32 %11, i32* %5
br label %16
12: ; preds = %2
%13 = load i32, i32* @LOG_INFO
store i32 %13, i32* %5
br label %16
14: ; preds = %2
%15 = load i32, i32* @LOG_DEBUG
store i32 %15, i32* %5
br label %16
16: ; preds = %14, %12, %10, %8
%17 = load i32, i32* %5
%18 = load i8*, i8** %4
%19 = call i32 @syslog(i32 %17, i8* %18)
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@LOG_NOTICE = global i32 0
@LOG_INFO = global i32 0
@LOG_DEBUG = global i32 0
@switch.table.msg_to_syslog = [3 x i32*] [i32* @LOG_ERR, i32* @LOG_NOTICE, i32* @LOG_INFO]
define void @msg_to_syslog(i16 zeroext %0, i8* %1) {
%3 = icmp ult i16 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = sext i16 %0 to i64
%6 = getelementptr inbounds [3 x i32*], [3 x i32*]* @switch.table.msg_to_syslog, i64 0, i64 %5
%7 = load i32*, i32** %6
br label %8
8: ; preds = %2, %4
%9 = phi i32* [ %7, %4 ], [ @LOG_DEBUG, %2 ]
%10 = load i32, i32* %9
%11 = tail call i32 @syslog(i32 %10, i8* %1)
ret void
}