#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 */
scalar_t__ debug_init_isviewer();
scalar_t__ debug_init_sdfs(char *, int);
int debug_init_sdlog(char *, char *);
scalar_t__ debug_init_usblog();
bool debug_init(int features) {
  bool ok = false;
  if (features & (1 << 0))
    ok = debug_init_usblog() || ok;
  if (features & (1 << 1))
    ok = debug_init_isviewer() || ok;
  if (features & (1 << 3))
    ok = debug_init_sdfs("sd:/", -1) || ok;
  if (features & (1 << 2))
    ok = debug_init_sdlog("sd:/libdragon.log", "a");
  return ok;
}


x86 assembly (clang, -O0):
<debug_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     118f <debug_init+0x4f>
mov    $0x0,%al
call   1040 <debug_init_usblog@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
jne    1184 <debug_init+0x44>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11cc <debug_init+0x8c>
mov    $0x0,%al
call   1060 <debug_init_isviewer@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0xa(%rbp)
jne    11c1 <debug_init+0x81>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1213 <debug_init+0xd3>
lea    0xe1e(%rip),%rdi
mov    $0xffffffff,%esi
call   1030 <debug_init_sdfs@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0xb(%rbp)
jne    1208 <debug_init+0xc8>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0xb(%rbp)
mov    -0xb(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1238 <debug_init+0xf8>
lea    0xddc(%rip),%rdi
lea    0xde7(%rip),%rsi
call   1050 <debug_init_sdlog@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_init>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
test   $0x1,%bl
jne    1164 <debug_init+0x24>
test   $0x2,%bl
jne    1179 <debug_init+0x39>
test   $0x8,%bl
jne    1195 <debug_init+0x55>
test   $0x4,%bl
jne    11bb <debug_init+0x7b>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1040 <debug_init_usblog@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
test   $0x2,%bl
je     1151 <debug_init+0x11>
xor    %eax,%eax
call   1060 <debug_init_isviewer@plt>
test   %rax,%rax
setne  %al
test   %ebp,%ebp
setne  %cl
or     %al,%cl
movzbl %cl,%ebp
test   $0x8,%bl
je     1156 <debug_init+0x16>
lea    0xe64(%rip),%rdi
mov    $0xffffffff,%esi
call   1030 <debug_init_sdfs@plt>
test   %rax,%rax
setne  %al
test   %ebp,%ebp
setne  %cl
or     %al,%cl
movzbl %cl,%ebp
test   $0x4,%bl
je     115b <debug_init+0x1b>
lea    0xe43(%rip),%rdi
lea    0xe4e(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <debug_init_sdlog@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"sd:/\00"
@.str.1 = [18 x i8] c"sd:/libdragon.log\00"
@.str.2 = [2 x i8] c"a\00"
define i32 @debug_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = and i32 %4, 1
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = call i64 (...) @debug_init_usblog()
%9 = icmp ne i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ true, %7 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %1
%17 = load i32, i32* %2
%18 = and i32 %17, 2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = call i64 (...) @debug_init_isviewer()
%22 = icmp ne i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br label %26
26: ; preds = %23, %20
%27 = phi i1 [ true, %20 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
store i32 %28, i32* %3
br label %29
29: ; preds = %26, %16
%30 = load i32, i32* %2
%31 = and i32 %30, 8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = call i64 @debug_init_sdfs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 -1)
%35 = icmp ne i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* %3
%38 = icmp ne i32 %37, 0
br label %39
39: ; preds = %36, %33
%40 = phi i1 [ true, %33 ], [ %38, %36 ]
%41 = zext i1 %40 to i32
store i32 %41, i32* %3
br label %42
42: ; preds = %39, %29
%43 = load i32, i32* %2
%44 = and i32 %43, 4
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @debug_init_sdlog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 %47, i32* %3
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [5 x i8] c"sd:/\00"
@.str.1 = [18 x i8] c"sd:/libdragon.log\00"
@.str.2 = [2 x i8] c"a\00"
define i32 @debug_init(i32 %0) {
%2 = and i32 %0, 1
%3 = icmp eq i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i64 (...) @debug_init_usblog()
%6 = icmp ne i64 %5, 0
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %4, %1
%9 = phi i32 [ %7, %4 ], [ 0, %1 ]
%10 = and i32 %0, 2
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = tail call i64 (...) @debug_init_isviewer()
%14 = icmp ne i64 %13, 0
%15 = icmp ne i32 %9, 0
%16 = select i1 %14, i1 true, i1 %15
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %12, %8
%19 = phi i32 [ %17, %12 ], [ %9, %8 ]
%20 = and i32 %0, 8
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %18
%23 = tail call i64 @debug_init_sdfs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 -1)
%24 = icmp ne i64 %23, 0
%25 = icmp ne i32 %19, 0
%26 = select i1 %24, i1 true, i1 %25
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %22, %18
%29 = phi i32 [ %27, %22 ], [ %19, %18 ]
%30 = and i32 %0, 4
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @debug_init_sdlog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = phi i32 [ %33, %32 ], [ %29, %28 ]
ret i32 %35
}