#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*/ printf(char *, int, int, int, int);
void exercise_two() {
  int x, y, z = 0;
  const int MAX_ANIMALS = 100;
  const int MAX_DOLLARS = 100;
  for (x = 0; x <= MAX_ANIMALS; x++) {
    for (y = 0; y <= MAX_ANIMALS; y++) {
      for (z = 0; z <= MAX_ANIMALS; z += 3) {
        int sum = (x * 5) + (y * 3) + (z / 3);
        if (sum == MAX_DOLLARS && (x + y + z) == MAX_ANIMALS) {
          printf("A possible combination is; %d ducks, %d cats, and %d "
                 "chickens. = %d \n",
                 x, y, z, x + y + z);
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<exercise_two>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x64,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jg     11f8 <exercise_two+0xe8>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jg     11e5 <exercise_two+0xd5>
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jg     11d2 <exercise_two+0xc2>
imul   $0x5,-0x4(%rbp),%eax
imul   $0x3,-0x8(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jne    11bf <exercise_two+0xaf>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    $0x64,%eax
jne    11bf <exercise_two+0xaf>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x4(%rbp),%r8d
add    -0x8(%rbp),%r8d
add    -0xc(%rbp),%r8d
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
jmp    11c4 <exercise_two+0xb4>
mov    -0xc(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    1156 <exercise_two+0x46>
jmp    11d7 <exercise_two+0xc7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1145 <exercise_two+0x35>
jmp    11ea <exercise_two+0xda>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1134 <exercise_two+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exercise_two>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
mov    $0x64,%r12d
mov    $0x12c,%r13d
lea    0xecf(%rip),%r14
jmp    115b <exercise_two+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15d
mov    0x4(%rsp),%r12d
add    $0xffffffff,%r12d
mov    (%rsp),%r13d
add    $0xfffffff1,%r13d
cmp    $0x65,%r15d
je     11bb <exercise_two+0xab>
mov    %r13d,(%rsp)
mov    %r12d,0x4(%rsp)
xor    %ebp,%ebp
jmp    1180 <exercise_two+0x70>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0xffffffff,%r12d
add    $0xfffffff7,%r13d
cmp    $0x65,%ebp
je     1140 <exercise_two+0x30>
xor    %ebx,%ebx
jmp    119a <exercise_two+0x8a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x3(%rbx),%eax
cmp    $0x62,%ebx
mov    %eax,%ebx
jae    1170 <exercise_two+0x60>
cmp    %ebx,%r13d
jne    1190 <exercise_two+0x80>
cmp    %ebx,%r12d
jne    1190 <exercise_two+0x80>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    $0x64,%r8d
call   1030 <printf@plt>
jmp    1190 <exercise_two+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [70 x i8] c"A possible combination is; %d ducks, %d cats, and %d chickens. = %d \0A\00"
define void @exercise_two() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %3
store i32 100, i32* %4
store i32 100, i32* %5
store i32 0, i32* %1
br label %7
7: ; preds = %55, %0
%8 = load i32, i32* %1
%9 = icmp sle i32 %8, 100
br i1 %9, label %10, label %58
10: ; preds = %7
store i32 0, i32* %2
br label %11
11: ; preds = %51, %10
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 100
br i1 %13, label %14, label %54
14: ; preds = %11
store i32 0, i32* %3
br label %15
15: ; preds = %47, %14
%16 = load i32, i32* %3
%17 = icmp sle i32 %16, 100
br i1 %17, label %18, label %50
18: ; preds = %15
%19 = load i32, i32* %1
%20 = mul nsw i32 %19, 5
%21 = load i32, i32* %2
%22 = mul nsw i32 %21, 3
%23 = add nsw i32 %20, %22
%24 = load i32, i32* %3
%25 = sdiv i32 %24, 3
%26 = add nsw i32 %23, %25
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 100
br i1 %28, label %29, label %46
29: ; preds = %18
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %3
%34 = add nsw i32 %32, %33
%35 = icmp eq i32 %34, 100
br i1 %35, label %36, label %46
36: ; preds = %29
%37 = load i32, i32* %1
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = load i32, i32* %1
%41 = load i32, i32* %2
%42 = add nsw i32 %40, %41
%43 = load i32, i32* %3
%44 = add nsw i32 %42, %43
%45 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %37, i32 %38, i32 %39, i32 %44)
br label %46
46: ; preds = %36, %29, %18
br label %47
47: ; preds = %46
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 3
store i32 %49, i32* %3
br label %15
50: ; preds = %15
br label %51
51: ; preds = %50
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 1
store i32 %53, i32* %2
br label %11
54: ; preds = %11
br label %55
55: ; preds = %54
%56 = load i32, i32* %1
%57 = add nsw i32 %56, 1
store i32 %57, i32* %1
br label %7
58: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [70 x i8] c"A possible combination is; %d ducks, %d cats, and %d chickens. = %d \0A\00"
define void @exercise_two() {
br label %1
1: ; preds = %0, %27
%2 = phi i32 [ 0, %0 ], [ %28, %27 ]
%3 = mul nuw nsw i32 %2, 5
br label %4
4: ; preds = %1, %24
%5 = phi i32 [ 0, %1 ], [ %25, %24 ]
%6 = mul nuw nsw i32 %5, 3
%7 = add nuw nsw i32 %6, %3
%8 = add nuw nsw i32 %5, %2
br label %9
9: ; preds = %4, %21
%10 = phi i32 [ 0, %4 ], [ %22, %21 ]
%11 = trunc i32 %10 to i8
%12 = udiv i8 %11, 3
%13 = zext i8 %12 to i32
%14 = add nuw nsw i32 %7, %13
%15 = icmp eq i32 %14, 100
%16 = add nuw nsw i32 %8, %10
%17 = icmp eq i32 %16, 100
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = tail call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %5, i32 %10, i32 100)
br label %21
21: ; preds = %19, %9
%22 = add nuw nsw i32 %10, 3
%23 = icmp ult i32 %10, 98
br i1 %23, label %9, label %24
24: ; preds = %21
%25 = add nuw nsw i32 %5, 1
%26 = icmp eq i32 %25, 101
br i1 %26, label %27, label %4
27: ; preds = %24
%28 = add nuw nsw i32 %2, 1
%29 = icmp eq i32 %28, 101
br i1 %29, label %30, label %1
30: ; preds = %27
ret void
}