#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 /*<<< orphan*/ die(char *);
unsigned chickens(unsigned heads, unsigned legs) {
  unsigned retVal, testGoatVal;
  if (legs % 2 != 0)
    die("It is not possible to have an odd number of legs.\n");
  if (legs < heads * 2)
    die("Anatomically impossible.\n");
  if (legs > heads * 4)
    die("Anatomically impossible.\n");
  retVal = (2 * heads) - (legs / 2);
  testGoatVal = (legs / 2) - heads;
  if ((heads == retVal + testGoatVal) &&
      (legs == (2 * retVal) + (4 * testGoatVal)))
    return retVal;
  die("Anatomically impossible.\n");
}


x86 assembly (clang, -O0):
<chickens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1139 <chickens+0x29>
lea    0xecc(%rip),%rdi
call   1030 <die@plt>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jae    1156 <chickens+0x46>
lea    0xee2(%rip),%rdi
call   1030 <die@plt>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x2,%ecx
cmp    %ecx,%eax
jbe    1173 <chickens+0x63>
lea    0xec5(%rip),%rdi
call   1030 <die@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    -0xc(%rbp),%ecx
shr    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jne    11c5 <chickens+0xb5>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x14(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
cmp    %ecx,%eax
jne    11c5 <chickens+0xb5>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <chickens+0xc1>
lea    0xe67(%rip),%rdi
call   1030 <die@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chickens>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
test   $0x1,%r15b
je     112f <chickens+0x1f>
lea    0xed6(%rip),%rdi
call   1030 <die@plt>
lea    (%r14,%r14,1),%ebp
cmp    %r15d,%ebp
jbe    1144 <chickens+0x34>
lea    0xef4(%rip),%rdi
call   1030 <die@plt>
lea    0x0(,%r14,4),%eax
cmp    %r15d,%eax
jae    115d <chickens+0x4d>
lea    0xedb(%rip),%rdi
call   1030 <die@plt>
mov    %r15d,%eax
shr    %eax
mov    %ebp,%ebx
sub    %eax,%ebx
cmp    %ebp,%ebp
jne    1178 <chickens+0x68>
sub    %r14d,%eax
shl    $0x2,%eax
lea    (%rax,%rbx,2),%eax
cmp    %r15d,%eax
je     1184 <chickens+0x74>
lea    0xeb4(%rip),%rdi
call   1030 <die@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"It is not possible to have an odd number of legs.\0A\00"
@.str.1 = [26 x i8] c"Anatomically impossible.\0A\00"
define i32 @chickens(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = urem i32 %8, 2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @die(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = mul i32 %15, 2
%17 = icmp ult i32 %14, %16
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = mul i32 %22, 4
%24 = icmp ugt i32 %21, %23
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = load i32, i32* %4
%29 = mul i32 2, %28
%30 = load i32, i32* %5
%31 = udiv i32 %30, 2
%32 = sub i32 %29, %31
store i32 %32, i32* %6
%33 = load i32, i32* %5
%34 = udiv i32 %33, 2
%35 = load i32, i32* %4
%36 = sub i32 %34, %35
store i32 %36, i32* %7
%37 = load i32, i32* %4
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = add i32 %38, %39
%41 = icmp eq i32 %37, %40
br i1 %41, label %42, label %52
42: ; preds = %27
%43 = load i32, i32* %5
%44 = load i32, i32* %6
%45 = mul i32 2, %44
%46 = load i32, i32* %7
%47 = mul i32 4, %46
%48 = add i32 %45, %47
%49 = icmp eq i32 %43, %48
br i1 %49, label %50, label %52
50: ; preds = %42
%51 = load i32, i32* %6
store i32 %51, i32* %3
br label %54
52: ; preds = %42, %27
%53 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [51 x i8] c"It is not possible to have an odd number of legs.\0A\00"
@.str.1 = [26 x i8] c"Anatomically impossible.\0A\00"
define i32 @chickens(i32 %0, i32 %1) {
%3 = and i32 %1, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @die(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = shl i32 %0, 1
%9 = icmp ugt i32 %8, %1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = shl i32 %0, 2
%14 = icmp ult i32 %13, %1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = lshr i32 %1, 1
%19 = sub i32 %8, %18
%20 = sub i32 %18, %0
%21 = add i32 %19, %20
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = shl i32 %19, 1
%25 = shl i32 %20, 2
%26 = add i32 %24, %25
%27 = icmp eq i32 %26, %1
br i1 %27, label %30, label %28
28: ; preds = %23, %17
%29 = tail call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %23, %28
ret i32 %19
}