#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 find_freecell();
int lastcard(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int exposed_dragons() {
  int dragoncount[3];
  bool dragoncell[3];
  memset(dragoncount, 0, sizeof(int) * 3);
  memset(dragoncell, 0, sizeof(bool) * 3);
  for (int i = 0; i < 11; i++) {
    int lc = lastcard(i);
    if ((lc >= 27) && (lc < 39)) {
      dragoncount[lc % 3]++;
      if (i >= 8)
        dragoncell[lc % 3] = true;
    }
  }
  int result = 0;
  for (int i = 0; i < 3; i++)
    if (((find_freecell() != -1) || dragoncell[i]) && (dragoncount[i] == 4))
      result |= (1 << i);
  return result;
}


x86 assembly (clang, -O0):
<exposed_dragons>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xb,-0x1c(%rbp)
jge    11d9 <exposed_dragons+0xa9>
mov    -0x1c(%rbp),%edi
call   1040 <lastcard@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1b,-0x20(%rbp)
jl     11c6 <exposed_dragons+0x96>
cmpl   $0x27,-0x20(%rbp)
jge    11c6 <exposed_dragons+0x96>
mov    -0x20(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0xc(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp,%rax,4)
cmpl   $0x8,-0x1c(%rbp)
jl     11c1 <exposed_dragons+0x91>
mov    -0x20(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movl   $0x1,-0x18(%rbp,%rax,4)
jmp    11c6 <exposed_dragons+0x96>
jmp    11cb <exposed_dragons+0x9b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <exposed_dragons+0x2f>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    1242 <exposed_dragons+0x112>
mov    $0x0,%al
call   1050 <find_freecell@plt>
cmp    $0xffffffff,%eax
jne    1210 <exposed_dragons+0xe0>
movslq -0x28(%rbp),%rax
cmpl   $0x0,-0x18(%rbp,%rax,4)
je     122f <exposed_dragons+0xff>
movslq -0x28(%rbp),%rax
cmpl   $0x4,-0xc(%rbp,%rax,4)
jne    122f <exposed_dragons+0xff>
mov    -0x28(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1234 <exposed_dragons+0x104>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e7 <exposed_dragons+0xb7>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exposed_dragons>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xc(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
jmp    1168 <exposed_dragons+0x38>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    $0xb,%ebx
je     119e <exposed_dragons+0x6e>
mov    %ebx,%edi
call   1040 <lastcard@plt>
lea    -0x1b(%rax),%ecx
cmp    $0xb,%ecx
ja     1160 <exposed_dragons+0x30>
movzbl %al,%eax
imul   $0xab,%eax,%ecx
shr    $0x9,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %cl,%al
movzbl %al,%eax
addl   $0x1,0xc(%rsp,%rax,4)
cmp    $0x8,%ebx
jb     1160 <exposed_dragons+0x30>
movl   $0x1,(%rsp,%rax,4)
jmp    1160 <exposed_dragons+0x30>
xor    %eax,%eax
call   1050 <find_freecell@plt>
not    %eax
or     (%rsp),%eax
setne  %al
cmpl   $0x4,0xc(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%r14d
xor    %eax,%eax
call   1050 <find_freecell@plt>
not    %eax
lea    0x2(%r14),%ebx
cmpl   $0x4,0x10(%rsp)
cmovne %r14d,%ebx
or     0x4(%rsp),%eax
cmove  %r14d,%ebx
xor    %eax,%eax
call   1050 <find_freecell@plt>
not    %eax
lea    0x4(%rbx),%ecx
cmpl   $0x4,0x14(%rsp)
cmovne %ebx,%ecx
or     0x8(%rsp),%eax
cmove  %ebx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @exposed_dragons() {
%1 = alloca [3 x i32]
%2 = alloca [3 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%8 = call i32 @memset(i32* %7, i32 0, i32 12)
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%10 = call i32 @memset(i32* %9, i32 0, i32 12)
store i32 0, i32* %3
br label %11
11: ; preds = %38, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 11
br i1 %13, label %14, label %41
14: ; preds = %11
%15 = load i32, i32* %3
%16 = call i32 @lastcard(i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp sge i32 %17, 27
br i1 %18, label %19, label %37
19: ; preds = %14
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 39
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i32, i32* %4
%24 = srem i32 %23, 3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
%29 = load i32, i32* %3
%30 = icmp sge i32 %29, 8
br i1 %30, label %31, label %36
31: ; preds = %22
%32 = load i32, i32* %4
%33 = srem i32 %32, 3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %34
store i32 1, i32* %35
br label %36
36: ; preds = %31, %22
br label %37
37: ; preds = %36, %19, %14
br label %38
38: ; preds = %37
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %11
41: ; preds = %11
store i32 0, i32* %5
store i32 0, i32* %6
br label %42
42: ; preds = %66, %41
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 3
br i1 %44, label %45, label %69
45: ; preds = %42
%46 = call i32 (...) @find_freecell()
%47 = icmp ne i32 %46, -1
br i1 %47, label %54, label %48
48: ; preds = %45
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %48, %45
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = icmp eq i32 %58, 4
br i1 %59, label %60, label %65
60: ; preds = %54
%61 = load i32, i32* %6
%62 = shl i32 1, %61
%63 = load i32, i32* %5
%64 = or i32 %63, %62
store i32 %64, i32* %5
br label %65
65: ; preds = %60, %54, %48
br label %66
66: ; preds = %65
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %42
69: ; preds = %42
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
define i32 @exposed_dragons() {
%1 = alloca [3 x i32]
%2 = alloca [3 x i32]
%3 = bitcast [3 x i32]* %1 to i8*
%4 = bitcast [3 x i32]* %2 to i8*
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%6 = call i32 @memset(i32* %5, i32 0, i32 12)
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%8 = call i32 @memset(i32* %7, i32 0, i32 12)
br label %9
9: ; preds = %0, %24
%10 = phi i32 [ 0, %0 ], [ %25, %24 ]
%11 = call i32 @lastcard(i32 %10)
%12 = add i32 %11, -27
%13 = icmp ult i32 %12, 12
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = trunc i32 %11 to i8
%16 = urem i8 %15, 3
%17 = zext i8 %16 to i64
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
%21 = icmp ugt i32 %10, 7
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %17
store i32 1, i32* %23
br label %24
24: ; preds = %14, %22, %9
%25 = add nuw nsw i32 %10, 1
%26 = icmp eq i32 %25, 11
br i1 %26, label %27, label %9
27: ; preds = %24
%28 = call i32 (...) @find_freecell()
%29 = icmp ne i32 %28, -1
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
%32 = select i1 %29, i1 true, i1 %31
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 4
%35 = select i1 %32, i1 %34, i1 false
%36 = zext i1 %35 to i32
%37 = call i32 (...) @find_freecell()
%38 = icmp ne i32 %37, -1
%39 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%40 = load i32, i32* %39
%41 = icmp ne i32 %40, 0
%42 = select i1 %38, i1 true, i1 %41
%43 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 4
%46 = select i1 %42, i1 %45, i1 false
%47 = or i32 %36, 2
%48 = select i1 %46, i32 %47, i32 %36
%49 = call i32 (...) @find_freecell()
%50 = icmp ne i32 %49, -1
%51 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
%52 = load i32, i32* %51
%53 = icmp ne i32 %52, 0
%54 = select i1 %50, i1 true, i1 %53
%55 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%56 = load i32, i32* %55
%57 = icmp eq i32 %56, 4
%58 = select i1 %54, i1 %57, i1 false
%59 = or i32 %48, 4
%60 = select i1 %58, i32 %59, i32 %48
ret i32 %60
}