#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 flashcom_checkcard(int port) {
  int id;
  struct resource *tmp;
  unsigned char tmp___0;
  {
    port += 4;
    tmp = request_region((unsigned long)port, 1UL, "MixCOM watchdog");
    if (!tmp) {
      return (0);
    }
    tmp___0 = inb_p((unsigned int)port);
    id = (int)tmp___0;
    if (id != 24) {
      release_region((unsigned long)port, 1UL);
      return (0);
    }
    return (port);
  }
}


x86 assembly (clang, -O0):
<flashcom_checkcard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rdi
mov    $0x1,%esi
lea    0xeac(%rip),%rdx
call   1030 <request_region@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1174 <flashcom_checkcard+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <flashcom_checkcard+0x80>
mov    -0x8(%rbp),%edi
call   1050 <inb_p@plt>
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x18,-0xc(%rbp)
je     11aa <flashcom_checkcard+0x7a>
movslq -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <release_region@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <flashcom_checkcard+0x80>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flashcom_checkcard>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
add    $0x4,%ebx
movslq %ebx,%r14
lea    0xebd(%rip),%rdx
mov    $0x1,%esi
mov    %r14,%rdi
call   1030 <request_region@plt>
test   %rax,%rax
je     116d <flashcom_checkcard+0x3d>
mov    %ebx,%edi
call   1050 <inb_p@plt>
cmp    $0x18,%al
je     116f <flashcom_checkcard+0x3f>
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 @flashcom_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, 4
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 %28
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
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 24
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = call i32 @release_region(i64 %24, i64 1)
store i32 0, i32* %2
br label %28
26: ; preds = %15
%27 = load i32, i32* %3
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %22, %14
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
%struct.resource = type { i32 }
@.str = [16 x i8] c"MixCOM watchdog\00"
define i32 @flashcom_checkcard(i32 %0) {
%2 = add nsw i32 %0, 4
%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 %11, label %6
6: ; preds = %1
%7 = tail call zeroext i8 @inb_p(i32 %2)
%8 = icmp eq i8 %7, 24
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @release_region(i64 %3, i64 1)
br label %11
11: ; preds = %6, %1, %9
%12 = phi i32 [ 0, %9 ], [ 0, %1 ], [ %2, %6 ]
ret i32 %12
}