#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 goats(unsigned heads, unsigned legs) {
  unsigned retVal, testChickenVal;
  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 = (legs / 2) - heads;
  testChickenVal = (2 * heads) - (legs / 2);
  if ((heads == testChickenVal + retVal) &&
      (legs == (2 * testChickenVal) + (4 * retVal)))
    return retVal;
  die("Anatomically impossible.\n");
}


x86 assembly (clang, -O0):
<goats>:
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 <goats+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 <goats+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 <goats+0x63>
lea    0xec5(%rip),%rdi
call   1030 <die@plt>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    -0xc(%rbp),%ecx
shr    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jne    11c5 <goats+0xb5>
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x10(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
cmp    %ecx,%eax
jne    11c5 <goats+0xb5>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <goats+0xc1>
lea    0xe67(%rip),%rdi
call   1030 <die@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<goats>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
test   $0x1,%r15b
je     112f <goats+0x1f>
lea    0xed6(%rip),%rdi
call   1030 <die@plt>
lea    (%r14,%r14,1),%ebp
cmp    %r15d,%ebp
jbe    1144 <goats+0x34>
lea    0xef4(%rip),%rdi
call   1030 <die@plt>
lea    0x0(,%r14,4),%eax
cmp    %r15d,%eax
jae    115d <goats+0x4d>
lea    0xedb(%rip),%rdi
call   1030 <die@plt>
mov    %r15d,%eax
shr    %eax
mov    %eax,%ebx
sub    %r14d,%ebx
cmp    %ebp,%ebp
jne    117c <goats+0x6c>
sub    %eax,%ebp
lea    0x0(,%rbx,4),%eax
lea    (%rax,%rbp,2),%eax
cmp    %r15d,%eax
je     1188 <goats+0x78>
lea    0xeb0(%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 @goats(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* %5
%29 = udiv i32 %28, 2
%30 = load i32, i32* %4
%31 = sub i32 %29, %30
store i32 %31, i32* %6
%32 = load i32, i32* %4
%33 = mul i32 2, %32
%34 = load i32, i32* %5
%35 = udiv i32 %34, 2
%36 = sub i32 %33, %35
store i32 %36, i32* %7
%37 = load i32, i32* %4
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%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* %7
%45 = mul i32 2, %44
%46 = load i32, i32* %6
%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 @goats(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 %18, %0
%20 = sub i32 %8, %18
%21 = add i32 %20, %19
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = shl i32 %20, 1
%25 = shl i32 %19, 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
}