#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 */
struct resource {
  int dummy;
};

/* Variables and functions */
unsigned char inb_p(unsigned int);
int /*<<< orphan*/ release_region(unsigned long, unsigned long);
struct resource *request_region(unsigned long, unsigned long, char *);
int mixcomwd_checkcard(int port) {
  int id;
  struct resource *tmp;
  unsigned char tmp___0;
  {
    port += 3088;
    tmp = request_region((unsigned long)port, 1UL, "MixCOM watchdog");
    if (!tmp) {
      return (0);
    }
    tmp___0 = inb_p((unsigned int)port);
    id = (int)tmp___0 & 63;
    if (id != 17) {
      release_region((unsigned long)port, 1UL);
      return (0);
    }
    return (port);
  }
}


x86 assembly (clang, -O0):
<mixcomwd_checkcard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xc10,%eax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rdi
mov    $0x1,%esi
lea    0xeaa(%rip),%rdx
call   1030 <request_region@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1176 <mixcomwd_checkcard+0x46>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <mixcomwd_checkcard+0x85>
mov    -0x8(%rbp),%edi
call   1050 <inb_p@plt>
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
and    $0x3f,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x11,-0xc(%rbp)
je     11af <mixcomwd_checkcard+0x7f>
movslq -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <release_region@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <mixcomwd_checkcard+0x85>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mixcomwd_checkcard>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
add    $0xc10,%ebx
movslq %ebx,%r14
lea    0xeba(%rip),%rdx
mov    $0x1,%esi
mov    %r14,%rdi
call   1030 <request_region@plt>
test   %rax,%rax
je     1172 <mixcomwd_checkcard+0x42>
mov    %ebx,%edi
call   1050 <inb_p@plt>
and    $0x3f,%al
cmp    $0x11,%al
je     1174 <mixcomwd_checkcard+0x44>
mov    $0x1,%esi
mov    %r14,%rdi
call   1040 <release_region@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.resource = type { i32 }
@.str = [16 x i8] c"MixCOM watchdog\00"
define i32 @mixcomwd_checkcard(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.resource*
%6 = alloca i8
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 3088
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = call %struct.resource* @request_region(i64 %10, i64 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store %struct.resource* %11, %struct.resource** %5
%12 = load %struct.resource*, %struct.resource** %5
%13 = icmp ne %struct.resource* %12, null
br i1 %13, label %15, label %14
14: ; preds = %1
store i32 0, i32* %2
br label %29
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call zeroext i8 @inb_p(i32 %16)
store i8 %17, i8* %6
%18 = load i8, i8* %6
%19 = zext i8 %18 to i32
%20 = and i32 %19, 63
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 17
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = call i32 @release_region(i64 %25, i64 1)
store i32 0, i32* %2
br label %29
27: ; preds = %15
%28 = load i32, i32* %3
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %23, %14
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
%struct.resource = type { i32 }
@.str = [16 x i8] c"MixCOM watchdog\00"
define i32 @mixcomwd_checkcard(i32 %0) {
%2 = add nsw i32 %0, 3088
%3 = sext i32 %2 to i64
%4 = tail call %struct.resource* @request_region(i64 %3, i64 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq %struct.resource* %4, null
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = tail call zeroext i8 @inb_p(i32 %2)
%8 = and i8 %7, 63
%9 = icmp eq i8 %8, 17
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @release_region(i64 %3, i64 1)
br label %12
12: ; preds = %6, %1, %10
%13 = phi i32 [ 0, %10 ], [ 0, %1 ], [ %2, %6 ]
ret i32 %13
}