#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 */
unsigned short __builtin_inw(int);
void main(void) {
  unsigned long loops0, loops1, loops2;
  unsigned long accum;
  accum = 0;
  loops0 = 10;
  do {
    unsigned short val;
    val = __builtin_inw(0x10e0);
    if (((val & 0x08) == 0) || (val == 1)) {
      break;
    }
  } while (--loops0);
  if (loops0 < 0)
    return;
  accum += loops0;
  loops1 = 20;
  do {
    unsigned short val;
    val = __builtin_inw(0x10e0);
    if (((val & 0x08) == 0) || (val == 1)) {
      break;
    }
  } while (--loops1);
  loops2 = 30;
  do {
    unsigned short val;
    val = __builtin_inw(0x10e0);
    if (((val & 0x08) == 0) || (val == 1)) {
      break;
    }
  } while (--loops2);
  accum += loops1 + loops0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x20(%rbp)
movq   $0xa,-0x8(%rbp)
mov    $0x10e0,%edi
call   1030 <__builtin_inw@plt>
mov    %ax,-0x22(%rbp)
movzwl -0x22(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1153 <main+0x43>
movzwl -0x22(%rbp),%eax
cmp    $0x1,%eax
jne    1158 <main+0x48>
jmp    1173 <main+0x63>
jmp    115d <main+0x4d>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1128 <main+0x18>
cmpq   $0x0,-0x8(%rbp)
jae    1183 <main+0x73>
jmp    1245 <main+0x135>
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x14,-0x10(%rbp)
mov    $0x10e0,%edi
call   1030 <__builtin_inw@plt>
mov    %ax,-0x24(%rbp)
movzwl -0x24(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11c2 <main+0xb2>
movzwl -0x24(%rbp),%eax
cmp    $0x1,%eax
jne    11c7 <main+0xb7>
jmp    11e2 <main+0xd2>
jmp    11cc <main+0xbc>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1197 <main+0x87>
movq   $0x1e,-0x18(%rbp)
mov    $0x10e0,%edi
call   1030 <__builtin_inw@plt>
mov    %ax,-0x26(%rbp)
movzwl -0x26(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1215 <main+0x105>
movzwl -0x26(%rbp),%eax
cmp    $0x1,%eax
jne    121a <main+0x10a>
jmp    1235 <main+0x125>
jmp    121f <main+0x10f>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ea <main+0xda>
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xfffffffffffffff7,%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x10e0,%edi
call   1030 <__builtin_inw@plt>
cmp    $0x1,%ax
je     1144 <main+0x34>
and    $0x8,%eax
test   %ax,%ax
je     1144 <main+0x34>
lea    0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jne    1120 <main+0x10>
mov    $0xffffffffffffffed,%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x10e0,%edi
call   1030 <__builtin_inw@plt>
cmp    $0x1,%ax
je     1174 <main+0x64>
and    $0x8,%eax
test   %ax,%ax
je     1174 <main+0x64>
lea    0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jne    1150 <main+0x40>
mov    $0xffffffffffffffe3,%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x10e0,%edi
call   1030 <__builtin_inw@plt>
cmp    $0x1,%ax
je     11a4 <main+0x94>
and    $0x8,%eax
test   %ax,%ax
je     11a4 <main+0x94>
lea    0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jne    1180 <main+0x70>
pop    %rbx
ret

LLVM IR (-O0):
define void @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
store i64 0, i64* %4
store i64 10, i64* %1
br label %8
8: ; preds = %20, %0
%9 = call zeroext i16 @__builtin_inw(i32 4320)
store i16 %9, i16* %5
%10 = load i16, i16* %5
%11 = zext i16 %10 to i32
%12 = and i32 %11, 8
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = load i16, i16* %5
%16 = zext i16 %15 to i32
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %14, %8
br label %24
19: ; preds = %14
br label %20
20: ; preds = %19
%21 = load i64, i64* %1
%22 = add i64 %21, -1
store i64 %22, i64* %1
%23 = icmp ne i64 %22, 0
br i1 %23, label %8, label %24
24: ; preds = %20, %18
%25 = load i64, i64* %1
%26 = icmp ult i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
br label %71
28: ; preds = %24
%29 = load i64, i64* %1
%30 = load i64, i64* %4
%31 = add i64 %30, %29
store i64 %31, i64* %4
store i64 20, i64* %2
br label %32
32: ; preds = %44, %28
%33 = call zeroext i16 @__builtin_inw(i32 4320)
store i16 %33, i16* %6
%34 = load i16, i16* %6
%35 = zext i16 %34 to i32
%36 = and i32 %35, 8
%37 = icmp eq i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %32
%39 = load i16, i16* %6
%40 = zext i16 %39 to i32
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %43
42: ; preds = %38, %32
br label %48
43: ; preds = %38
br label %44
44: ; preds = %43
%45 = load i64, i64* %2
%46 = add i64 %45, -1
store i64 %46, i64* %2
%47 = icmp ne i64 %46, 0
br i1 %47, label %32, label %48
48: ; preds = %44, %42
store i64 30, i64* %3
br label %49
49: ; preds = %61, %48
%50 = call zeroext i16 @__builtin_inw(i32 4320)
store i16 %50, i16* %7
%51 = load i16, i16* %7
%52 = zext i16 %51 to i32
%53 = and i32 %52, 8
%54 = icmp eq i32 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %49
%56 = load i16, i16* %7
%57 = zext i16 %56 to i32
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %55, %49
br label %65
60: ; preds = %55
br label %61
61: ; preds = %60
%62 = load i64, i64* %3
%63 = add i64 %62, -1
store i64 %63, i64* %3
%64 = icmp ne i64 %63, 0
br i1 %64, label %49, label %65
65: ; preds = %61, %59
%66 = load i64, i64* %2
%67 = load i64, i64* %1
%68 = add i64 %66, %67
%69 = load i64, i64* %4
%70 = add i64 %69, %68
store i64 %70, i64* %4
br label %71
71: ; preds = %65, %27
ret void
}

LLVM IR (-O2):
define void @main() {
br label %1
1: ; preds = %1, %0
%2 = phi i64 [ 10, %0 ], [ %8, %1 ]
%3 = tail call zeroext i16 @__builtin_inw(i32 4320)
%4 = and i16 %3, 8
%5 = icmp eq i16 %4, 0
%6 = icmp eq i16 %3, 1
%7 = or i1 %6, %5
%8 = add nsw i64 %2, -1
%9 = icmp eq i64 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %1
11: ; preds = %1, %11
%12 = phi i64 [ %18, %11 ], [ 20, %1 ]
%13 = tail call zeroext i16 @__builtin_inw(i32 4320)
%14 = and i16 %13, 8
%15 = icmp eq i16 %14, 0
%16 = icmp eq i16 %13, 1
%17 = or i1 %16, %15
%18 = add nsw i64 %12, -1
%19 = icmp eq i64 %18, 0
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %11
21: ; preds = %11, %21
%22 = phi i64 [ %28, %21 ], [ 30, %11 ]
%23 = tail call zeroext i16 @__builtin_inw(i32 4320)
%24 = and i16 %23, 8
%25 = icmp eq i16 %24, 0
%26 = icmp eq i16 %23, 1
%27 = or i1 %26, %25
%28 = add nsw i64 %22, -1
%29 = icmp eq i64 %28, 0
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %31, label %21
31: ; preds = %21
ret void
}