#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 act_of_god();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int people = 100;
  int food = 200;
  int sow = 0;
  int tables = 0;
  int z;
  puts("RULER\n-----\n\n");
input:
  printf("%d lbs of food and %d people\nInput food for sowing ", food, people);
  scanf("%d", &sow);
  printf("and the amount for our peoples table sire? ");
  scanf("%d", &tables);
  if (sow + tables > food) {
    printf("you can't put %d lbs on the tables and sow %d lbs this "
           "year,  sire\n",
           tables, sow);
    goto input;
  }
  z = food - (sow + tables);
  people = (tables / people) * (people / 2) + tables;
  if (people < 10) {
    printf("\nThe few people that survived the hard winter have left "
           "for pastures new.\nYour empire has crumbled like many before it and"
           "many that will rise in\nits ashes");
    return 0;
  }
  if (rand() % 5 == 0)
    sow = act_of_god();
  food = z + (sow * 3.5);
  if (people > 1000 && food > 1000) {
    printf(
        "\nSire, your majesty is known throughout the world.\n"
        "Statues are errected in your honour today because our nation is "
        "strong "
        "and\nsafe from harm, our nation is currently %d strong and we have "
        "supplies\nof %d to feed us.  We now longer need your guidance in "
        "these matters you\ncan sit in state without vexation on our earthly "
        "matters.\n\nALL HAIL THE KING!",
        people, food);
    return 0;
  }
  printf("\nA New Year Dawns\n");
  goto input;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x64,-0x8(%rbp)
movl   $0xc8,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <scanf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1221 <main+0xb1>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b7 <main+0x47>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1276 <main+0x106>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1306 <main+0x196>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1298 <main+0x128>
mov    $0x0,%al
call   1030 <act_of_god@plt>
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xd56(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jle    12f3 <main+0x183>
cmpl   $0x3e8,-0xc(%rbp)
jle    12f3 <main+0x183>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1306 <main+0x196>
lea    0xfba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b7 <main+0x47>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe65(%rip),%rdi
call   1040 <puts@plt>
mov    $0xc8,%ebx
mov    $0x64,%r13d
lea    0xe5c(%rip),%rdi
lea    0xe89(%rip),%rbp
lea    0x8(%rsp),%r12
lea    0xe80(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11f3 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x10cd(%rip),%rdi
call   1040 <puts@plt>
lea    0xe23(%rip),%rdi
mov    %ebx,%esi
mov    %r13d,0x10(%rsp)
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%esi
lea    (%rsi,%rdx,1),%ecx
mov    %ebx,0x14(%rsp)
cmp    %ecx,%ebx
jge    12c0 <main+0x150>
lea    0x8(%rsp),%r13
lea    0xe06(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xdf7(%rip),%rbp
mov    0x10(%rsp),%ebx
mov    0x14(%rsp),%r12d
nopl   0x0(%rax)
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xda1(%rip),%rdi
mov    %r12d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%esi
lea    (%rsi,%rdx,1),%ecx
cmp    %ecx,%r12d
jl     1260 <main+0xf0>
jmp    12c4 <main+0x154>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%ebx
mov    %esi,%eax
cltd
idiv   %ebx
mov    %ebx,%r13d
shr    $0x1f,%r13d
add    %ebx,%r13d
sar    %r13d
imul   %eax,%r13d
add    %esi,%r13d
cmp    $0x9,%r13d
jle    137f <main+0x20f>
mov    0x14(%rsp),%ebx
sub    %ecx,%ebx
xor    %eax,%eax
call   1090 <rand@plt>
imul   $0xcccccccd,%eax,%eax
add    $0x19999999,%eax
cmp    $0x33333333,%eax
jb     1310 <main+0x1a0>
mov    0x8(%rsp),%eax
jmp    131b <main+0x1ab>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <act_of_god@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%r12
lea    0xd26(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xd17(%rip),%rbp
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0xcb7(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%ebx
cmp    $0x3e9,%r13d
jb     11e0 <main+0x70>
cmp    $0x3e9,%ebx
jl     11e0 <main+0x70>
lea    0xde7(%rip),%rdi
mov    %r13d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    138d <main+0x21d>
lea    0xd37(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"RULER\0A-----\0A\0A\00"
@.str.1 = [52 x i8] c"%d lbs of food and %d people\0AInput food for sowing \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [44 x i8] c"and the amount for our peoples table sire? \00"
@.str.4 = [68 x i8] c"you can't put %d lbs on the tables and sow %d lbs this year, sire\0A\00"
@.str.5 = [155 x i8] c"\0AThe few people that survived the hard winter have left for pastures new.\0AYour empire has crumbled like many before it andmany that will rise in\0Aits ashes\00"
@.str.6 = [348 x i8] c"\0ASire, your majesty is known throughout the world.\0AStatues are errected in your honour today because our nation is strong and\0Asafe from harm, our nation is currently %d strong and we have supplies\0Aof %d to feed us. We now longer need your guidance in these matters you\0Acan sit in state without vexation on our earthly matters.\0A\0AALL HAIL THE KING!\00"
@.str.7 = [19 x i8] c"\0AA New Year Dawns\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
store i32 100, i32* %2
store i32 200, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%9 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %66, %22, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = add nsw i32 %17, %18
%20 = load i32, i32* %3
%21 = icmp sgt i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %10
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i32 %23, i32 %24)
br label %10
26: ; preds = %10
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = add nsw i32 %28, %29
%31 = sub nsw i32 %27, %30
store i32 %31, i32* %6
%32 = load i32, i32* %5
%33 = load i32, i32* %2
%34 = sdiv i32 %32, %33
%35 = load i32, i32* %2
%36 = sdiv i32 %35, 2
%37 = mul nsw i32 %34, %36
%38 = load i32, i32* %5
%39 = add nsw i32 %37, %38
store i32 %39, i32* %2
%40 = load i32, i32* %2
%41 = icmp slt i32 %40, 10
br i1 %41, label %42, label %44
42: ; preds = %26
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %68
44: ; preds = %26
%45 = call i32 (...) @rand()
%46 = srem i32 %45, 5
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (...) @act_of_god()
store i32 %49, i32* %4
br label %50
50: ; preds = %48, %44
%51 = load i32, i32* %6
%52 = sitofp i32 %51 to double
%53 = load i32, i32* %4
%54 = sitofp i32 %53 to double
%55 = call double @llvm.fmuladd.f64(double %54, double 3.500000e+00, double %52)
%56 = fptosi double %55 to i32
store i32 %56, i32* %3
%57 = load i32, i32* %2
%58 = icmp sgt i32 %57, 1000
br i1 %58, label %59, label %66
59: ; preds = %50
%60 = load i32, i32* %3
%61 = icmp sgt i32 %60, 1000
br i1 %61, label %62, label %66
62: ; preds = %59
%63 = load i32, i32* %2
%64 = load i32, i32* %3
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([348 x i8], [348 x i8]* @.str.6, i64 0, i64 0), i32 %63, i32 %64)
store i32 0, i32* %1
br label %68
66: ; preds = %59, %50
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %10
68: ; preds = %62, %42
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@.str = [14 x i8] c"RULER\0A-----\0A\0A\00"
@.str.1 = [52 x i8] c"%d lbs of food and %d people\0AInput food for sowing \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [44 x i8] c"and the amount for our peoples table sire? \00"
@.str.4 = [68 x i8] c"you can't put %d lbs on the tables and sow %d lbs this year, sire\0A\00"
@.str.5 = [155 x i8] c"\0AThe few people that survived the hard winter have left for pastures new.\0AYour empire has crumbled like many before it andmany that will rise in\0Aits ashes\00"
@.str.6 = [348 x i8] c"\0ASire, your majesty is known throughout the world.\0AStatues are errected in your honour today because our nation is strong and\0Asafe from harm, our nation is currently %d strong and we have supplies\0Aof %d to feed us. We now longer need your guidance in these matters you\0Acan sit in state without vexation on our earthly matters.\0A\0AALL HAIL THE KING!\00"
@str = [18 x i8] c"\0AA New Year Dawns\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %61, %0
%9 = phi i32 [ %38, %61 ], [ 100, %0 ]
%10 = phi i32 [ %55, %61 ], [ 200, %0 ]
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %9)
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = add nsw i32 %16, %15
%18 = icmp slt i32 %10, %17
br i1 %18, label %19, label %31
19: ; preds = %8, %19
%20 = phi i32 [ %28, %19 ], [ %16, %8 ]
%21 = phi i32 [ %27, %19 ], [ %15, %8 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i32 %20, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %9)
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%27 = load i32, i32* %1
%28 = load i32, i32* %2
%29 = add nsw i32 %28, %27
%30 = icmp slt i32 %10, %29
br i1 %30, label %19, label %31
31: ; preds = %19, %8
%32 = phi i32 [ %16, %8 ], [ %28, %19 ]
%33 = phi i32 [ %17, %8 ], [ %29, %19 ]
%34 = sub nsw i32 %10, %33
%35 = sdiv i32 %32, %9
%36 = sdiv i32 %9, 2
%37 = mul nsw i32 %35, %36
%38 = add nsw i32 %37, %32
%39 = icmp slt i32 %38, 10
br i1 %39, label %40, label %42
40: ; preds = %31
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([155 x i8], [155 x i8]* @.str.5, i64 0, i64 0))
br label %63
42: ; preds = %31
%43 = call i32 (...) @rand()
%44 = srem i32 %43, 5
%45 = icmp eq i32 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %42
%47 = load i32, i32* %1
br label %50
48: ; preds = %42
%49 = call i32 (...) @act_of_god()
store i32 %49, i32* %1
br label %50
50: ; preds = %46, %48
%51 = phi i32 [ %47, %46 ], [ %49, %48 ]
%52 = sitofp i32 %34 to double
%53 = sitofp i32 %51 to double
%54 = call double @llvm.fmuladd.f64(double %53, double 3.500000e+00, double %52)
%55 = fptosi double %54 to i32
%56 = icmp ugt i32 %38, 1000
%57 = icmp sgt i32 %55, 1000
%58 = select i1 %56, i1 %57, i1 false
br i1 %58, label %59, label %61
59: ; preds = %50
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([348 x i8], [348 x i8]* @.str.6, i64 0, i64 0), i32 %38, i32 %55)
br label %63
61: ; preds = %50
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %8
63: ; preds = %59, %40
ret i32 0
}