#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 get_permissoins();
int /*<<< orphan*/ getenv(char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int check_device() {
  int ret = 1;
  int perms = get_permissoins();
  if (perms & 1 << 0)
    return 1;
  if (perms & 1 << 1)
    return 0;
  if (perms & 1 << 2 && strcmp(getenv("DRIVER"), "usbhid") == 0)
    return 0;
  if (perms & 1 << 3 && strcmp(getenv("DEVTYPE"), "usb_interface") == 0)
    return 0;
  return ret;
}


x86 assembly (clang, -O0):
<check_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x8(%rbp)
mov    $0x0,%al
call   1050 <get_permissoins@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1164 <check_device+0x34>
movl   $0x1,-0x4(%rbp)
jmp    1203 <check_device+0xd3>
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     117f <check_device+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1203 <check_device+0xd3>
mov    -0xc(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11be <check_device+0x8e>
lea    0xe6b(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xe64(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11be <check_device+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    1203 <check_device+0xd3>
mov    -0xc(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11fd <check_device+0xcd>
lea    0xe3a(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xe34(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11fd <check_device+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    1203 <check_device+0xd3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_device>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <get_permissoins@plt>
mov    %eax,%ebp
test   $0x1,%bpl
jne    1194 <check_device+0x64>
test   $0x2,%bpl
jne    1199 <check_device+0x69>
test   $0x4,%bpl
je     116f <check_device+0x3f>
lea    0xea9(%rip),%rdi
call   1030 <getenv@plt>
lea    0xea4(%rip),%rsi
mov    %eax,%edi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1199 <check_device+0x69>
test   $0x8,%bpl
je     1194 <check_device+0x64>
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe8e(%rip),%rsi
mov    %eax,%edi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1199 <check_device+0x69>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"DRIVER\00"
@.str.1 = [7 x i8] c"usbhid\00"
@.str.2 = [8 x i8] c"DEVTYPE\00"
@.str.3 = [14 x i8] c"usb_interface\00"
define i32 @check_device() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 1, i32* %2
%4 = call i32 (...) @get_permissoins()
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = and i32 %5, 1
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %34
9: ; preds = %0
%10 = load i32, i32* %3
%11 = and i32 %10, 2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %1
br label %34
14: ; preds = %9
%15 = load i32, i32* %3
%16 = and i32 %15, 4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = call i32 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = call i64 @strcmp(i32 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %1
br label %34
23: ; preds = %18, %14
%24 = load i32, i32* %3
%25 = and i32 %24, 8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = call i32 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%29 = call i64 @strcmp(i32 %28, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 0, i32* %1
br label %34
32: ; preds = %27, %23
%33 = load i32, i32* %2
store i32 %33, i32* %1
br label %34
34: ; preds = %32, %31, %22, %13, %8
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [7 x i8] c"DRIVER\00"
@.str.1 = [7 x i8] c"usbhid\00"
@.str.2 = [8 x i8] c"DEVTYPE\00"
@.str.3 = [14 x i8] c"usb_interface\00"
define i32 @check_device() {
%1 = tail call i32 (...) @get_permissoins()
%2 = and i32 %1, 1
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %0
%5 = and i32 %1, 2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = and i32 %1, 4
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i32 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = tail call i64 @strcmp(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %10, %7
%15 = and i32 %1, 8
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = tail call i32 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i64 @strcmp(i32 %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17, %14
br label %22
22: ; preds = %17, %10, %4, %0, %21
%23 = phi i32 [ 1, %21 ], [ 1, %0 ], [ 0, %4 ], [ 0, %10 ], [ 0, %17 ]
ret i32 %23
}