#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 short inw(unsigned int);
int /*<<< orphan*/ release_region(unsigned long, unsigned long);
struct resource *request_region(unsigned long, unsigned long, char *);
int probe_base_port(int base) {
  int b;
  int e;
  int volatile fool;
  int volatile i;
  struct resource *tmp;
  unsigned short tmp___0;
  unsigned short tmp___1;
  unsigned short tmp___2;
  {
    b = 768;
    e = 880;
    if (base) {
      e = base;
      b = e;
    }
    base = b;
    while (base <= e) {
      tmp = request_region((unsigned long)base, 16UL, "cm206");
      if (!tmp) {
        goto __Cont;
      }
      i = (int volatile)0;
      while (i < (int volatile)3) {
        tmp___0 = inw((unsigned int)(base + 2));
        fool = (int volatile)tmp___0;
        i += (int volatile)1;
      }
      tmp___1 = inw((unsigned int)(base + 6));
      if (((int)tmp___1 & 65519) != 1) {
        release_region((unsigned long)base, 16UL);
        goto __Cont;
      } else {
        tmp___2 = inw((unsigned int)base);
        if (((int)tmp___2 & 44288) != 0) {
          release_region((unsigned long)base, 16UL);
          goto __Cont;
        }
      }
      return (base);
    __Cont:
      base += 16;
    }
    return (0);
  }
}


x86 assembly (clang, -O0):
<probe_base_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x300,-0xc(%rbp)
movl   $0x370,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     115f <probe_base_port+0x2f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1254 <probe_base_port+0x124>
movslq -0x8(%rbp),%rdi
mov    $0x10,%esi
lea    0xe7f(%rip),%rdx
call   1040 <request_region@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <probe_base_port+0x6a>
jmp    1246 <probe_base_port+0x116>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    $0x3,%eax
jge    11d1 <probe_base_port+0xa1>
mov    -0x8(%rbp),%edi
add    $0x2,%edi
call   1030 <inw@plt>
mov    %ax,-0x22(%rbp)
movzwl -0x22(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <probe_base_port+0x71>
mov    -0x8(%rbp),%edi
add    $0x6,%edi
call   1030 <inw@plt>
mov    %ax,-0x24(%rbp)
movzwl -0x24(%rbp),%eax
and    $0xffef,%eax
cmp    $0x1,%eax
je     1205 <probe_base_port+0xd5>
movslq -0x8(%rbp),%rdi
mov    $0x10,%esi
call   1050 <release_region@plt>
jmp    1246 <probe_base_port+0x116>
mov    -0x8(%rbp),%edi
call   1030 <inw@plt>
mov    %ax,-0x26(%rbp)
movzwl -0x26(%rbp),%eax
and    $0xad00,%eax
cmp    $0x0,%eax
je     1236 <probe_base_port+0x106>
movslq -0x8(%rbp),%rdi
mov    $0x10,%esi
call   1050 <release_region@plt>
jmp    1246 <probe_base_port+0x116>
jmp    123b <probe_base_port+0x10b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <probe_base_port+0x12b>
mov    -0x8(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x8(%rbp)
jmp    1165 <probe_base_port+0x35>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<probe_base_port>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
mov    $0x370,%eax
cmovne %edi,%eax
mov    $0x300,%ecx
cmovne %edi,%ecx
xor    %r14d,%r14d
cmp    %eax,%ecx
jg     11f0 <probe_base_port+0xc0>
movslq %ecx,%rbx
movslq %eax,%r12
lea    0xe9a(%rip),%r15
jmp    1186 <probe_base_port+0x56>
nopl   0x0(%rax,%rax,1)
mov    $0x10,%esi
mov    %rbx,%rdi
call   1050 <release_region@plt>
add    $0x10,%rbx
cmp    %r12,%rbx
jg     11f0 <probe_base_port+0xc0>
mov    $0x10,%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1040 <request_region@plt>
test   %rax,%rax
je     117d <probe_base_port+0x4d>
movl   $0x0,0x8(%rsp)
mov    0x8(%rsp),%eax
cmp    $0x2,%eax
jg     11cc <probe_base_port+0x9c>
lea    0x2(%rbx),%ebp
nop
mov    %ebp,%edi
call   1030 <inw@plt>
movzwl %ax,%eax
mov    %eax,0xc(%rsp)
addl   $0x1,0x8(%rsp)
mov    0x8(%rsp),%eax
cmp    $0x3,%eax
jl     11b0 <probe_base_port+0x80>
lea    0x6(%rbx),%edi
call   1030 <inw@plt>
and    $0xffef,%eax
cmp    $0x1,%ax
jne    1170 <probe_base_port+0x40>
mov    %ebx,%edi
call   1030 <inw@plt>
test   $0xad00,%eax
jne    1170 <probe_base_port+0x40>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.resource = type { i32 }
@.str = [6 x i8] c"cm206\00"
define i32 @probe_base_port(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.resource*
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
store i32 %0, i32* %3
store i32 768, i32* %4
store i32 880, i32* %5
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* %3
store i32 %15, i32* %5
%16 = load i32, i32* %5
store i32 %16, i32* %4
br label %17
17: ; preds = %14, %1
%18 = load i32, i32* %4
store i32 %18, i32* %3
br label %19
19: ; preds = %68, %17
%20 = load i32, i32* %3
%21 = load i32, i32* %5
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %71
23: ; preds = %19
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = call %struct.resource* @request_region(i64 %25, i64 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store %struct.resource* %26, %struct.resource** %8
%27 = load %struct.resource*, %struct.resource** %8
%28 = icmp ne %struct.resource* %27, null
br i1 %28, label %30, label %29
29: ; preds = %23
br label %68
30: ; preds = %23
store volatile i32 0, i32* %7
br label %31
31: ; preds = %34, %30
%32 = load volatile i32, i32* %7
%33 = icmp slt i32 %32, 3
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 2
%37 = call zeroext i16 @inw(i32 %36)
store i16 %37, i16* %9
%38 = load i16, i16* %9
%39 = zext i16 %38 to i32
store volatile i32 %39, i32* %6
%40 = load volatile i32, i32* %7
%41 = add nsw i32 %40, 1
store volatile i32 %41, i32* %7
br label %31
42: ; preds = %31
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 6
%45 = call zeroext i16 @inw(i32 %44)
store i16 %45, i16* %10
%46 = load i16, i16* %10
%47 = zext i16 %46 to i32
%48 = and i32 %47, 65519
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %54
50: ; preds = %42
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = call i32 @release_region(i64 %52, i64 16)
br label %68
54: ; preds = %42
%55 = load i32, i32* %3
%56 = call zeroext i16 @inw(i32 %55)
store i16 %56, i16* %11
%57 = load i16, i16* %11
%58 = zext i16 %57 to i32
%59 = and i32 %58, 44288
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %54
%62 = load i32, i32* %3
%63 = sext i32 %62 to i64
%64 = call i32 @release_region(i64 %63, i64 16)
br label %68
65: ; preds = %54
br label %66
66: ; preds = %65
%67 = load i32, i32* %3
store i32 %67, i32* %2
br label %72
68: ; preds = %61, %50, %29
%69 = load i32, i32* %3
%70 = add nsw i32 %69, 16
store i32 %70, i32* %3
br label %19
71: ; preds = %19
store i32 0, i32* %2
br label %72
72: ; preds = %71, %66
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
%struct.resource = type { i32 }
@.str = [6 x i8] c"cm206\00"
define i32 @probe_base_port(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = icmp eq i32 %0, 0
%7 = select i1 %6, i32 880, i32 %0
%8 = select i1 %6, i32 768, i32 %0
%9 = icmp sgt i32 %8, %7
br i1 %9, label %48, label %10
10: ; preds = %1
%11 = sext i32 %8 to i64
%12 = sext i32 %7 to i64
br label %13
13: ; preds = %10, %43
%14 = phi i64 [ %11, %10 ], [ %44, %43 ]
%15 = tail call %struct.resource* @request_region(i64 %14, i64 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq %struct.resource* %15, null
br i1 %16, label %43, label %17
17: ; preds = %13
store volatile i32 0, i32* %3
%18 = load volatile i32, i32* %3
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = trunc i64 %14 to i32
%22 = add i32 %21, 2
br label %23
23: ; preds = %20, %23
%24 = tail call zeroext i16 @inw(i32 %22)
%25 = zext i16 %24 to i32
store volatile i32 %25, i32* %2
%26 = load volatile i32, i32* %3
%27 = add nsw i32 %26, 1
store volatile i32 %27, i32* %3
%28 = load volatile i32, i32* %3
%29 = icmp slt i32 %28, 3
br i1 %29, label %23, label %30
30: ; preds = %23, %17
%31 = trunc i64 %14 to i32
%32 = add i32 %31, 6
%33 = tail call zeroext i16 @inw(i32 %32)
%34 = and i16 %33, -17
%35 = icmp eq i16 %34, 1
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = trunc i64 %14 to i32
%38 = tail call zeroext i16 @inw(i32 %37)
%39 = and i16 %38, -21248
%40 = icmp eq i16 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %36, %30
%42 = tail call i32 @release_region(i64 %14, i64 16)
br label %43
43: ; preds = %41, %13
%44 = add i64 %14, 16
%45 = icmp sgt i64 %44, %12
br i1 %45, label %48, label %13
46: ; preds = %36
%47 = trunc i64 %14 to i32
br label %48
48: ; preds = %43, %46, %1
%49 = phi i32 [ 0, %1 ], [ %47, %46 ], [ 0, %43 ]
ret i32 %49
}