#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 inb(unsigned short);
int /*<<< orphan*/ mdelay(int);
int /*<<< orphan*/ outb(unsigned char, scalar_t__);
int act2000_isa_reset(unsigned short portbase) {
  unsigned char reg;
  int i;
  int found;
  int serial = 0;
  found = 0;
  if ((reg = inb(portbase + 0)) != 0xff) {
    outb(reg | 0x80, portbase + 0);
    mdelay(10);
    outb(reg, portbase + 0);
    mdelay(10);
    for (i = 0; i < 16; i++) {
      if (inb(portbase + 1) & 0x08)
        serial |= 0x10000;
      serial >>= 1;
    }
    if (serial == 0x0201)
      found++;
  }
  return found;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x0,%eax
movzwl %ax,%edi
call   1050 <inb@plt>
mov    %al,-0x3(%rbp)
movzbl %al,%eax
cmp    $0xff,%eax
je     121a <act2000_isa_reset+0xea>
movzbl -0x3(%rbp),%eax
or     $0x80,%eax
movzwl -0x2(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rsi
movzbl %al,%edi
call   1040 <outb@plt>
mov    $0xa,%edi
call   1030 <mdelay@plt>
mov    -0x3(%rbp),%al
movzwl -0x2(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rsi
movzbl %al,%edi
call   1040 <outb@plt>
mov    $0xa,%edi
call   1030 <mdelay@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    11ff <act2000_isa_reset+0xcf>
movzwl -0x2(%rbp),%eax
add    $0x1,%eax
movzwl %ax,%edi
call   1050 <inb@plt>
and    $0x8,%eax
cmp    $0x0,%eax
je     11e8 <act2000_isa_reset+0xb8>
mov    -0x10(%rbp),%eax
or     $0x10000,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b8 <act2000_isa_reset+0x88>
cmpl   $0x201,-0x10(%rbp)
jne    1215 <act2000_isa_reset+0xe5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    121a <act2000_isa_reset+0xea>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1050 <inb@plt>
mov    %eax,%ebp
xor    %eax,%eax
cmp    $0xff,%bpl
je     12d6 <act2000_isa_reset+0x1a6>
mov    %ebp,%eax
or     $0x80,%al
movzwl %bx,%r14d
movzbl %al,%edi
mov    %r14,%rsi
call   1040 <outb@plt>
mov    $0xa,%edi
call   1030 <mdelay@plt>
movzbl %bpl,%edi
mov    %r14,%rsi
call   1040 <outb@plt>
mov    $0xa,%edi
call   1030 <mdelay@plt>
lea    0x1(%rbx),%eax
movzwl %ax,%r14d
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebx
and    $0x8,%ebx
shl    $0xc,%ebx
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebp
and    $0x8,%ebp
shl    $0xd,%ebp
or     %ebx,%ebp
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebx
shr    $0x2,%ebp
and    $0x8,%ebx
shl    $0xc,%ebx
or     %ebp,%ebx
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebp
and    $0x8,%ebp
shl    $0xd,%ebp
or     %ebx,%ebp
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebx
shr    $0x2,%ebp
and    $0x8,%ebx
shl    $0xc,%ebx
or     %ebp,%ebx
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%r15d
and    $0x8,%r15d
shl    $0xd,%r15d
or     %ebx,%r15d
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebx
shr    $0x2,%r15d
and    $0x8,%ebx
shl    $0xc,%ebx
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebp
and    $0x8,%ebp
shl    $0xd,%ebp
or     %ebx,%ebp
or     %r15d,%ebp
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%r15d
shr    $0x2,%ebp
and    $0x8,%r15d
shl    $0xc,%r15d
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebx
and    $0x8,%ebx
shl    $0xd,%ebx
or     %r15d,%ebx
or     %ebp,%ebx
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebp
shr    $0x2,%ebx
and    $0x8,%ebp
shl    $0xc,%ebp
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%r15d
and    $0x8,%r15d
shl    $0xd,%r15d
or     %ebp,%r15d
or     %ebx,%r15d
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebx
shr    $0x2,%r15d
and    $0x8,%ebx
shl    $0xc,%ebx
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebp
and    $0x8,%ebp
shl    $0xd,%ebp
or     %ebx,%ebp
or     %r15d,%ebp
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %eax,%ebx
shr    $0x2,%ebp
and    $0x8,%ebx
shl    $0xc,%ebx
mov    %r14d,%edi
call   1050 <inb@plt>
and    $0x8,%eax
shl    $0xd,%eax
or     %ebx,%eax
and    $0xfffffffe,%ebp
or     %eax,%ebp
xor    %eax,%eax
cmp    $0x402,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @act2000_isa_reset(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i16 %0, i16* %2
store i32 0, i32* %6
store i32 0, i32* %5
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
%9 = add nsw i32 %8, 0
%10 = trunc i32 %9 to i16
%11 = call i32 @inb(i16 zeroext %10)
%12 = trunc i32 %11 to i8
store i8 %12, i8* %3
%13 = zext i8 %12 to i32
%14 = icmp ne i32 %13, 255
br i1 %14, label %15, label %60
15: ; preds = %1
%16 = load i8, i8* %3
%17 = zext i8 %16 to i32
%18 = or i32 %17, 128
%19 = trunc i32 %18 to i8
%20 = load i16, i16* %2
%21 = zext i16 %20 to i32
%22 = add nsw i32 %21, 0
%23 = sext i32 %22 to i64
%24 = call i32 @outb(i8 zeroext %19, i64 %23)
%25 = call i32 @mdelay(i32 10)
%26 = load i8, i8* %3
%27 = load i16, i16* %2
%28 = zext i16 %27 to i32
%29 = add nsw i32 %28, 0
%30 = sext i32 %29 to i64
%31 = call i32 @outb(i8 zeroext %26, i64 %30)
%32 = call i32 @mdelay(i32 10)
store i32 0, i32* %4
br label %33
33: ; preds = %50, %15
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 16
br i1 %35, label %36, label %53
36: ; preds = %33
%37 = load i16, i16* %2
%38 = zext i16 %37 to i32
%39 = add nsw i32 %38, 1
%40 = trunc i32 %39 to i16
%41 = call i32 @inb(i16 zeroext %40)
%42 = and i32 %41, 8
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = load i32, i32* %6
%46 = or i32 %45, 65536
store i32 %46, i32* %6
br label %47
47: ; preds = %44, %36
%48 = load i32, i32* %6
%49 = ashr i32 %48, 1
store i32 %49, i32* %6
br label %50
50: ; preds = %47
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %33
53: ; preds = %33
%54 = load i32, i32* %6
%55 = icmp eq i32 %54, 513
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59, %1
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
define i32 @act2000_isa_reset(i16 zeroext %0) {
%2 = tail call i32 @inb(i16 zeroext %0)
%3 = and i32 %2, 255
%4 = icmp eq i32 %3, 255
br i1 %4, label %87, label %5
5: ; preds = %1
%6 = trunc i32 %2 to i8
%7 = or i8 %6, -128
%8 = zext i16 %0 to i64
%9 = tail call i32 @outb(i8 zeroext %7, i64 %8)
%10 = tail call i32 @mdelay(i32 10)
%11 = tail call i32 @outb(i8 zeroext %6, i64 %8)
%12 = tail call i32 @mdelay(i32 10)
%13 = add i16 %0, 1
%14 = tail call i32 @inb(i16 zeroext %13)
%15 = shl i32 %14, 12
%16 = and i32 %15, 32768
%17 = tail call i32 @inb(i16 zeroext %13)
%18 = shl i32 %17, 13
%19 = and i32 %18, 65536
%20 = or i32 %19, %16
%21 = tail call i32 @inb(i16 zeroext %13)
%22 = lshr exact i32 %20, 2
%23 = shl i32 %21, 12
%24 = and i32 %23, 32768
%25 = or i32 %22, %24
%26 = tail call i32 @inb(i16 zeroext %13)
%27 = shl i32 %26, 13
%28 = and i32 %27, 65536
%29 = or i32 %28, %25
%30 = tail call i32 @inb(i16 zeroext %13)
%31 = lshr exact i32 %29, 2
%32 = shl i32 %30, 12
%33 = and i32 %32, 32768
%34 = or i32 %31, %33
%35 = tail call i32 @inb(i16 zeroext %13)
%36 = shl i32 %35, 13
%37 = and i32 %36, 65536
%38 = or i32 %37, %34
%39 = tail call i32 @inb(i16 zeroext %13)
%40 = lshr i32 %38, 2
%41 = shl i32 %39, 12
%42 = and i32 %41, 32768
%43 = or i32 %40, %42
%44 = tail call i32 @inb(i16 zeroext %13)
%45 = shl i32 %44, 13
%46 = and i32 %45, 65536
%47 = or i32 %46, %43
%48 = tail call i32 @inb(i16 zeroext %13)
%49 = lshr i32 %47, 2
%50 = shl i32 %48, 12
%51 = and i32 %50, 32768
%52 = or i32 %49, %51
%53 = tail call i32 @inb(i16 zeroext %13)
%54 = shl i32 %53, 13
%55 = and i32 %54, 65536
%56 = or i32 %55, %52
%57 = tail call i32 @inb(i16 zeroext %13)
%58 = lshr i32 %56, 2
%59 = shl i32 %57, 12
%60 = and i32 %59, 32768
%61 = or i32 %58, %60
%62 = tail call i32 @inb(i16 zeroext %13)
%63 = shl i32 %62, 13
%64 = and i32 %63, 65536
%65 = or i32 %64, %61
%66 = tail call i32 @inb(i16 zeroext %13)
%67 = lshr i32 %65, 2
%68 = shl i32 %66, 12
%69 = and i32 %68, 32768
%70 = or i32 %67, %69
%71 = tail call i32 @inb(i16 zeroext %13)
%72 = shl i32 %71, 13
%73 = and i32 %72, 65536
%74 = or i32 %73, %70
%75 = tail call i32 @inb(i16 zeroext %13)
%76 = lshr i32 %74, 2
%77 = shl i32 %75, 12
%78 = and i32 %77, 32768
%79 = tail call i32 @inb(i16 zeroext %13)
%80 = shl i32 %79, 13
%81 = and i32 %80, 65536
%82 = and i32 %76, 268435454
%83 = or i32 %82, %78
%84 = or i32 %81, %83
%85 = icmp eq i32 %84, 1026
%86 = zext i1 %85 to i32
br label %87
87: ; preds = %5, %1
%88 = phi i32 [ 0, %1 ], [ %86, %5 ]
ret i32 %88
}