#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*/ balance_request();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove_random();
scalar_t__ servers_left();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time();
int main(void) {
  unsigned requests = 0;
  srand(time());
  while (0 != servers_left()) {
    if (0 == ++requests % 10)
      remove_random();
    balance_request();
  }
  printf("Happy April Fools!\n");
  printf("%i requests handled\n", requests);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   1060 <servers_left@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11c8 <main+0x68>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    11bc <main+0x5c>
mov    $0x0,%al
call   1080 <remove_random@plt>
mov    $0x0,%al
call   1030 <balance_request@plt>
jmp    1184 <main+0x24>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   1070 <servers_left@plt>
test   %rax,%rax
je     11d8 <main+0x68>
mov    $0x1,%ebp
mov    $0xcccccccd,%r14d
xor    %ebx,%ebx
jmp    11b9 <main+0x49>
nop
xor    %eax,%eax
call   1040 <balance_request@plt>
xor    %eax,%eax
call   1070 <servers_left@plt>
add    $0x1,%ebp
add    $0x1,%ebx
test   %rax,%rax
je     11d8 <main+0x68>
mov    %ebp,%eax
imul   %r14,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
add    %eax,%eax
add    $0xffffffff,%eax
cmp    %ebx,%eax
jne    11a0 <main+0x30>
xor    %eax,%eax
call   1090 <remove_random@plt>
jmp    11a0 <main+0x30>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
lea    0xe15(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Happy April Fools!\0A\00"
@.str.1 = [21 x i8] c"%i requests handled\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = call i32 (...) @time()
%4 = call i32 @srand(i32 %3)
br label %5
5: ; preds = %15, %0
%6 = call i64 (...) @servers_left()
%7 = icmp ne i64 0, %6
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i32, i32* %2
%10 = add i32 %9, 1
store i32 %10, i32* %2
%11 = urem i32 %10, 10
%12 = icmp eq i32 0, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 (...) @remove_random()
br label %15
15: ; preds = %13, %8
%16 = call i32 (...) @balance_request()
br label %5
17: ; preds = %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"%i requests handled\0A\00"
@str = [19 x i8] c"Happy April Fools!\00"
define i32 @main() {
%1 = tail call i32 (...) @time()
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i64 (...) @servers_left()
%4 = icmp eq i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %0, %12
%6 = phi i32 [ %7, %12 ], [ 0, %0 ]
%7 = add i32 %6, 1
%8 = urem i32 %7, 10
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 (...) @remove_random()
br label %12
12: ; preds = %10, %5
%13 = tail call i32 (...) @balance_request()
%14 = tail call i64 (...) @servers_left()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %12, %0
%17 = phi i32 [ 0, %0 ], [ %7, %12 ]
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %17)
ret i32 0
}