#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_UPTO(int /*<<< orphan*/);
int /*<<< orphan*/ debugclose();
int /*<<< orphan*/ debugopen(char *);
int /*<<< orphan*/ setlogmask(int /*<<< orphan*/);
int /*<<< orphan*/ sysloglevel(int);
void setdebuglevel(char *host, int level) {
  static int open = 0;
  if (level == 0) {
    debugclose();
    open = 0;
    return;
  }
  if (open == 0) {
    debugopen(host);
    open = 1;
  }
  setlogmask(LOG_UPTO(sysloglevel(level)));
  return;
}


x86 assembly (clang, -O0):
<setdebuglevel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    117f <setdebuglevel+0x2f>
mov    $0x0,%al
call   1050 <debugclose@plt>
movl   $0x0,0x2ed2(%rip)
jmp    11b5 <setdebuglevel+0x65>
cmpl   $0x0,0x2ec6(%rip)
jne    119f <setdebuglevel+0x4f>
mov    -0x8(%rbp),%rdi
call   1070 <debugopen@plt>
movl   $0x1,0x2ead(%rip)
mov    -0xc(%rbp),%edi
call   1040 <sysloglevel@plt>
mov    %eax,%edi
call   1030 <LOG_UPTO@plt>
mov    %eax,%edi
call   1060 <setlogmask@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setdebuglevel>:
push   %rbx
test   %esi,%esi
je     1182 <setdebuglevel+0x32>
mov    %esi,%ebx
cmpb   $0x0,0x2eee(%rip)
jne    116c <setdebuglevel+0x1c>
call   1070 <debugopen@plt>
movb   $0x1,0x2ee0(%rip)
mov    %ebx,%edi
call   1040 <sysloglevel@plt>
mov    %eax,%edi
call   1030 <LOG_UPTO@plt>
mov    %eax,%edi
pop    %rbx
jmp    1060 <setlogmask@plt>
xor    %eax,%eax
call   1050 <debugclose@plt>
movb   $0x0,0x2ebc(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@setdebuglevel.open = internal global i32 0
define void @setdebuglevel(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 (...) @debugclose()
store i32 0, i32* @setdebuglevel.open
br label %20
9: ; preds = %2
%10 = load i32, i32* @setdebuglevel.open
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = call i32 @debugopen(i8* %13)
store i32 1, i32* @setdebuglevel.open
br label %15
15: ; preds = %12, %9
%16 = load i32, i32* %4
%17 = call i32 @sysloglevel(i32 %16)
%18 = call i32 @LOG_UPTO(i32 %17)
%19 = call i32 @setlogmask(i32 %18)
br label %20
20: ; preds = %15, %7
ret void
}

LLVM IR (-O2):
@setdebuglevel.open = internal unnamed_addr global i1 false
define void @setdebuglevel(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @debugclose()
store i1 false, i1* @setdebuglevel.open
br label %14
6: ; preds = %2
%7 = load i1, i1* @setdebuglevel.open
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 @debugopen(i8* %0)
store i1 true, i1* @setdebuglevel.open
br label %10
10: ; preds = %8, %6
%11 = tail call i32 @sysloglevel(i32 %1)
%12 = tail call i32 @LOG_UPTO(i32 %11)
%13 = tail call i32 @setlogmask(i32 %12)
br label %14
14: ; preds = %10, %4
ret void
}